Indentation
This commit is contained in:
parent
6805ea719b
commit
81cb42f37e
@ -119,18 +119,22 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
}
|
||||
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
// FIXME: NPE - Cache to avoid
|
||||
return channel.getLocalAddress();
|
||||
}
|
||||
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
// FIXME: NPE - Cache to avoid
|
||||
return channel.getRemoteAddress();
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
// FIXME: Should not return false during reconnection.
|
||||
return channel.isBound();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
// FIXME: Should not return false during reconnection.
|
||||
return channel.isConnected();
|
||||
}
|
||||
|
||||
@ -188,91 +192,91 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
||||
|
||||
SocketAddress connectAddress = new InetSocketAddress(url.getHost(), url.getPort());
|
||||
channel.connect(connectAddress).addListener(
|
||||
new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture f) {
|
||||
if (f.isSuccess()) {
|
||||
// Configure SSL
|
||||
HttpTunnelingSocketChannelConfig config = getConfig();
|
||||
SSLContext sslContext = config.getSslContext();
|
||||
ChannelFuture sslHandshakeFuture = null;
|
||||
if (sslContext != null) {
|
||||
URI uri = remoteAddress.getUri();
|
||||
SSLEngine engine = sslContext.createSSLEngine(
|
||||
uri.getHost(), uri.getPort());
|
||||
// FIXME: bindAddress not respected.
|
||||
channel.connect(connectAddress).addListener(new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture f) {
|
||||
if (f.isSuccess()) {
|
||||
// Configure SSL
|
||||
HttpTunnelingSocketChannelConfig config = getConfig();
|
||||
SSLContext sslContext = config.getSslContext();
|
||||
ChannelFuture sslHandshakeFuture = null;
|
||||
if (sslContext != null) {
|
||||
URI uri = remoteAddress.getUri();
|
||||
SSLEngine engine = sslContext.createSSLEngine(
|
||||
uri.getHost(), uri.getPort());
|
||||
|
||||
// Configure the SSLEngine.
|
||||
engine.setUseClientMode(true);
|
||||
engine.setEnableSessionCreation(config.isEnableSslSessionCreation());
|
||||
String[] enabledCipherSuites = config.getEnabledSslCipherSuites();
|
||||
if (enabledCipherSuites != null) {
|
||||
engine.setEnabledCipherSuites(enabledCipherSuites);
|
||||
}
|
||||
String[] enabledProtocols = config.getEnabledSslProtocols();
|
||||
if (enabledProtocols != null) {
|
||||
engine.setEnabledProtocols(enabledProtocols);
|
||||
}
|
||||
// Configure the SSLEngine.
|
||||
engine.setUseClientMode(true);
|
||||
engine.setEnableSessionCreation(config.isEnableSslSessionCreation());
|
||||
String[] enabledCipherSuites = config.getEnabledSslCipherSuites();
|
||||
if (enabledCipherSuites != null) {
|
||||
engine.setEnabledCipherSuites(enabledCipherSuites);
|
||||
}
|
||||
String[] enabledProtocols = config.getEnabledSslProtocols();
|
||||
if (enabledProtocols != null) {
|
||||
engine.setEnabledProtocols(enabledProtocols);
|
||||
}
|
||||
|
||||
SslHandler sslHandler = new SslHandler(engine);
|
||||
channel.getPipeline().addFirst("ssl", sslHandler);
|
||||
try {
|
||||
sslHandshakeFuture = sslHandler.handshake(channel);
|
||||
} catch (SSLException e) {
|
||||
future.setFailure(e);
|
||||
fireExceptionCaught(channel, e);
|
||||
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());
|
||||
SslHandler sslHandler = new SslHandler(engine);
|
||||
channel.getPipeline().addFirst("ssl", sslHandler);
|
||||
try {
|
||||
sslHandshakeFuture = sslHandler.handshake(channel);
|
||||
} catch (SSLException e) {
|
||||
future.setFailure(e);
|
||||
fireExceptionCaught(channel, e);
|
||||
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 - 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() {
|
||||
@ -285,6 +289,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
}
|
||||
|
||||
void sendChunk(ChannelBuffer a, final ChannelFuture future) {
|
||||
// XXX: Investigate race condition during reconnection
|
||||
final int size = a.readableBytes();
|
||||
channel.write(new DefaultHttpChunk(a)).addListener(new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture f)
|
||||
@ -303,6 +308,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
void closeSocket() {
|
||||
if (setClosed()) {
|
||||
// Send the end of chunk.
|
||||
// XXX: Investigate race condition during reconnection
|
||||
synchronized (writeLock) {
|
||||
channel.write(HttpChunk.LAST_CHUNK).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user