cleanup
This commit is contained in:
parent
a91f3e4acf
commit
c58568e094
@ -24,7 +24,6 @@ package org.jboss.netty.channel.socket.http;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
@ -138,7 +137,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
}
|
||||
}
|
||||
|
||||
void connectAndSendHeaders(boolean reconnect, HttpTunnelAddress remoteAddress) throws IOException {
|
||||
void connectAndSendHeaders(boolean reconnect, HttpTunnelAddress remoteAddress) {
|
||||
this.remoteAddress = remoteAddress;
|
||||
URI url = remoteAddress.getUri();
|
||||
if (reconnect) {
|
||||
@ -151,7 +150,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
channel.connect(connectAddress);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("POST ").append(url.getRawPath()).append(" HTTP/1.1").append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).
|
||||
append("HOST: ").append(url.getHost()).append(":").append(url.getPort()).append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).
|
||||
append("Host: ").append(url.getHost()).append(":").append(url.getPort()).append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).
|
||||
append("Content-Type: application/octet-stream").append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).append("Transfer-Encoding: chunked").
|
||||
append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).append("Content-Transfer-Encoding: Binary").append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR).append("Connection: Keep-Alive").
|
||||
append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR);
|
||||
@ -160,7 +159,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
}
|
||||
builder.append(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR);
|
||||
String msg = builder.toString();
|
||||
channel.write(ChannelBuffers.wrappedBuffer(msg.getBytes("ASCII7")));
|
||||
channel.write(ChannelBuffers.copiedBuffer(msg, "ASCII"));
|
||||
}
|
||||
|
||||
public void sendChunk(ChannelBuffer a) {
|
||||
@ -194,7 +193,6 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
|
||||
if (reconnectLock.tryLock()) {
|
||||
try {
|
||||
awaitingInitialResponse = true;
|
||||
|
||||
connectAndSendHeaders(true, remoteAddress);
|
||||
} finally {
|
||||
reconnectLock.unlock();
|
||||
|
@ -70,30 +70,33 @@ public class HttpTunnelingServlet extends HttpServlet {
|
||||
final HttpServletResponse response, HttpSession session,
|
||||
HttpTunnelingChannelHandler handler, Channel channel) throws IOException {
|
||||
|
||||
response.setHeader("jsessionid", session.getId());
|
||||
response.setHeader("Content-Type", "application/octet-stream");
|
||||
response.setContentLength(-1);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.getOutputStream().flush();
|
||||
handler.setOutputStream(response.getOutputStream());
|
||||
try {
|
||||
response.setHeader("JSESSIONID", session.getId());
|
||||
response.setHeader("Content-Type", "application/octet-stream");
|
||||
response.setContentLength(-1);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.getOutputStream().flush();
|
||||
handler.setOutputStream(response.getOutputStream());
|
||||
|
||||
PushbackInputStream in =
|
||||
new PushbackInputStream(request.getInputStream());
|
||||
do {
|
||||
try {
|
||||
ChannelBuffer buffer = read(in);
|
||||
if (buffer == null) {
|
||||
PushbackInputStream in =
|
||||
new PushbackInputStream(request.getInputStream());
|
||||
for (;;) {
|
||||
try {
|
||||
ChannelBuffer buffer = read(in);
|
||||
if (buffer == null) {
|
||||
break;
|
||||
}
|
||||
channel.write(buffer);
|
||||
} catch (IOException e) {
|
||||
// this is ok, the client can reconnect.
|
||||
break;
|
||||
}
|
||||
channel.write(buffer);
|
||||
} catch (IOException e) {
|
||||
// this is ok, the client can reconnect.
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
if (!handler.awaitReconnect()) {
|
||||
channel.close();
|
||||
} finally {
|
||||
// Mark the channel as closed if the client didn't reconnect in time.
|
||||
if (!handler.awaitReconnect()) {
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +104,7 @@ public class HttpTunnelingServlet extends HttpServlet {
|
||||
byte[] buf;
|
||||
int readBytes;
|
||||
|
||||
do {
|
||||
for (;;) {
|
||||
int bytesToRead = in.available();
|
||||
if (bytesToRead > 0) {
|
||||
buf = new byte[bytesToRead];
|
||||
@ -121,7 +124,8 @@ public class HttpTunnelingServlet extends HttpServlet {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
ChannelBuffer buffer;
|
||||
if (readBytes == buf.length) {
|
||||
buffer = ChannelBuffers.wrappedBuffer(buf);
|
||||
@ -160,7 +164,7 @@ public class HttpTunnelingServlet extends HttpServlet {
|
||||
length += ((ChannelBuffer) buffer.getMessage()).readableBytes();
|
||||
}
|
||||
}
|
||||
response.setHeader("jsessionid", session.getId());
|
||||
response.setHeader("JSESSIONID", session.getId());
|
||||
response.setContentLength(length);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
for (MessageEvent event: buffers) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user