1
1
package com.eucalyptus.ws.handlers.http;
3
import javax.net.ssl.SSLEngine;
4
import javax.net.ssl.SSLException;
3
import java.util.concurrent.atomic.AtomicBoolean;
6
5
import org.jboss.netty.buffer.ChannelBuffer;
7
import org.jboss.netty.channel.Channel;
8
6
import org.jboss.netty.channel.ChannelEvent;
9
import org.jboss.netty.channel.ChannelFuture;
10
7
import org.jboss.netty.channel.ChannelHandlerContext;
11
import org.jboss.netty.channel.ChannelStateEvent;
12
import org.jboss.netty.channel.ExceptionEvent;
8
import org.jboss.netty.channel.ChannelPipelineCoverage;
13
9
import org.jboss.netty.channel.MessageEvent;
14
10
import org.jboss.netty.handler.ssl.SslHandler;
12
import com.eucalyptus.auth.util.SslSetup;
13
import com.eucalyptus.ws.util.HttpUtils;
15
@ChannelPipelineCoverage("one")
16
16
public class NioSslHandler extends SslHandler {
18
public NioSslHandler( SSLEngine engine ) {
23
public void channelBound( ChannelHandlerContext ctx, ChannelStateEvent e ) throws Exception {
24
super.channelBound( ctx, e );
28
public void channelOpen( ChannelHandlerContext ctx, ChannelStateEvent e ) throws Exception {
29
super.channelOpen( ctx, e );
17
private AtomicBoolean first = new AtomicBoolean( true );
19
public NioSslHandler( ) {
20
super( SslSetup.getServerEngine( ) );
33
24
public void handleUpstream( ChannelHandlerContext ctx, ChannelEvent e ) throws Exception {
34
if( e instanceof MessageEvent ) {
35
Object o = ((MessageEvent) e).getMessage( );
36
if( ! (o instanceof ChannelBuffer ) ) {
37
ctx.getPipeline( ).removeFirst( );//this should be me.
40
} else { //we punt on HTTP and only delegate SSL.
26
if ( e instanceof MessageEvent
27
&& first.compareAndSet( true, false )
28
&& ( o = ( ( MessageEvent ) e ).getMessage( ) ) instanceof ChannelBuffer
29
&& !HttpUtils.maybeSsl( ( ChannelBuffer ) o ) ) {
30
ctx.getPipeline( ).removeFirst( );
31
ctx.sendUpstream( e );
33
super.handleUpstream( ctx, e );
43
super.handleUpstream( ctx, e );