Indentation

This commit is contained in:
Trustin Lee 2009-06-30 11:36:01 +00:00
parent 6805ea719b
commit 81cb42f37e

View File

@ -119,18 +119,22 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
} }
public InetSocketAddress getLocalAddress() { public InetSocketAddress getLocalAddress() {
// FIXME: NPE - Cache to avoid
return channel.getLocalAddress(); return channel.getLocalAddress();
} }
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
// FIXME: NPE - Cache to avoid
return channel.getRemoteAddress(); return channel.getRemoteAddress();
} }
public boolean isBound() { public boolean isBound() {
// FIXME: Should not return false during reconnection.
return channel.isBound(); return channel.isBound();
} }
public boolean isConnected() { public boolean isConnected() {
// FIXME: Should not return false during reconnection.
return channel.isConnected(); return channel.isConnected();
} }
@ -188,91 +192,91 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
SocketAddress connectAddress = new InetSocketAddress(url.getHost(), url.getPort()); SocketAddress connectAddress = new InetSocketAddress(url.getHost(), url.getPort());
channel.connect(connectAddress).addListener( // FIXME: bindAddress not respected.
new ChannelFutureListener() { channel.connect(connectAddress).addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture f) { public void operationComplete(ChannelFuture f) {
if (f.isSuccess()) { if (f.isSuccess()) {
// Configure SSL // Configure SSL
HttpTunnelingSocketChannelConfig config = getConfig(); HttpTunnelingSocketChannelConfig config = getConfig();
SSLContext sslContext = config.getSslContext(); SSLContext sslContext = config.getSslContext();
ChannelFuture sslHandshakeFuture = null; ChannelFuture sslHandshakeFuture = null;
if (sslContext != null) { if (sslContext != null) {
URI uri = remoteAddress.getUri(); URI uri = remoteAddress.getUri();
SSLEngine engine = sslContext.createSSLEngine( SSLEngine engine = sslContext.createSSLEngine(
uri.getHost(), uri.getPort()); uri.getHost(), uri.getPort());
// Configure the SSLEngine. // Configure the SSLEngine.
engine.setUseClientMode(true); engine.setUseClientMode(true);
engine.setEnableSessionCreation(config.isEnableSslSessionCreation()); engine.setEnableSessionCreation(config.isEnableSslSessionCreation());
String[] enabledCipherSuites = config.getEnabledSslCipherSuites(); String[] enabledCipherSuites = config.getEnabledSslCipherSuites();
if (enabledCipherSuites != null) { if (enabledCipherSuites != null) {
engine.setEnabledCipherSuites(enabledCipherSuites); engine.setEnabledCipherSuites(enabledCipherSuites);
} }
String[] enabledProtocols = config.getEnabledSslProtocols(); String[] enabledProtocols = config.getEnabledSslProtocols();
if (enabledProtocols != null) { if (enabledProtocols != null) {
engine.setEnabledProtocols(enabledProtocols); engine.setEnabledProtocols(enabledProtocols);
} }
SslHandler sslHandler = new SslHandler(engine); SslHandler sslHandler = new SslHandler(engine);
channel.getPipeline().addFirst("ssl", sslHandler); channel.getPipeline().addFirst("ssl", sslHandler);
try { try {
sslHandshakeFuture = sslHandler.handshake(channel); sslHandshakeFuture = sslHandler.handshake(channel);
} catch (SSLException e) { } catch (SSLException e) {
future.setFailure(e); future.setFailure(e);
fireExceptionCaught(channel, e); fireExceptionCaught(channel, e);
return; return;
}
}
// Send the HTTP request.
final HttpRequest req = new DefaultHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.POST, url.getRawPath());
req.setHeader(HttpHeaders.Names.HOST, url.getHost());
req.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream");
req.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.setHeader(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING, HttpHeaders.Values.BINARY);
if (sessionId != null) {
CookieEncoder ce = new CookieEncoder(false);
ce.addCookie(JSESSIONID, sessionId);
String cookie = ce.encode();
//System.out.println("COOKIE: " + cookie);
req.setHeader(HttpHeaders.Names.COOKIE, cookie);
}
if (sslHandshakeFuture == null) {
channel.write(req);
future.setSuccess();
if (!channel.isBound()) {
fireChannelBound(HttpTunnelingClientSocketChannel.this, channel.getLocalAddress());
}
fireChannelConnected(HttpTunnelingClientSocketChannel.this, channel.getRemoteAddress());
} else {
sslHandshakeFuture.addListener(new ChannelFutureListener() {
public void operationComplete(
ChannelFuture f)
throws Exception {
if (f.isSuccess()) {
channel.write(req);
future.setSuccess();
if (!isBound()) {
// FIXME: channelBound is not fired.
fireChannelBound(HttpTunnelingClientSocketChannel.this, channel.getLocalAddress());
}
fireChannelConnected(HttpTunnelingClientSocketChannel.this, channel.getRemoteAddress());
} else {
future.setFailure(f.getCause());
fireExceptionCaught(HttpTunnelingClientSocketChannel.this, f.getCause());
}
}
});
}
} else {
future.setFailure(f.getCause());
fireExceptionCaught(channel, f.getCause());
} }
} }
});
// Send the HTTP request.
final HttpRequest req = new DefaultHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.POST, url.getRawPath());
req.setHeader(HttpHeaders.Names.HOST, url.getHost());
req.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream");
req.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.setHeader(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING, HttpHeaders.Values.BINARY);
if (sessionId != null) {
CookieEncoder ce = new CookieEncoder(false);
ce.addCookie(JSESSIONID, sessionId);
String cookie = ce.encode();
//System.out.println("COOKIE: " + cookie);
req.setHeader(HttpHeaders.Names.COOKIE, cookie);
}
if (sslHandshakeFuture == null) {
channel.write(req);
future.setSuccess();
if (!channel.isBound()) {
fireChannelBound(HttpTunnelingClientSocketChannel.this, channel.getLocalAddress());
}
fireChannelConnected(HttpTunnelingClientSocketChannel.this, channel.getRemoteAddress());
} else {
sslHandshakeFuture.addListener(new ChannelFutureListener() {
public void operationComplete(
ChannelFuture f)
throws Exception {
if (f.isSuccess()) {
channel.write(req);
future.setSuccess();
if (!isBound()) {
// FIXME: channelBound is not fired - needs own state flag
fireChannelBound(HttpTunnelingClientSocketChannel.this, channel.getLocalAddress());
}
fireChannelConnected(HttpTunnelingClientSocketChannel.this, channel.getRemoteAddress());
} else {
future.setFailure(f.getCause());
fireExceptionCaught(HttpTunnelingClientSocketChannel.this, f.getCause());
}
}
});
}
} else {
future.setFailure(f.getCause());
fireExceptionCaught(channel, f.getCause());
}
}
});
} }
private void createSocketChannel() { private void createSocketChannel() {
@ -285,6 +289,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
} }
void sendChunk(ChannelBuffer a, final ChannelFuture future) { void sendChunk(ChannelBuffer a, final ChannelFuture future) {
// XXX: Investigate race condition during reconnection
final int size = a.readableBytes(); final int size = a.readableBytes();
channel.write(new DefaultHttpChunk(a)).addListener(new ChannelFutureListener() { channel.write(new DefaultHttpChunk(a)).addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture f) public void operationComplete(ChannelFuture f)
@ -303,6 +308,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
void closeSocket() { void closeSocket() {
if (setClosed()) { if (setClosed()) {
// Send the end of chunk. // Send the end of chunk.
// XXX: Investigate race condition during reconnection
synchronized (writeLock) { synchronized (writeLock) {
channel.write(HttpChunk.LAST_CHUNK).addListener(ChannelFutureListener.CLOSE); channel.write(HttpChunk.LAST_CHUNK).addListener(ChannelFutureListener.CLOSE);
} }