Simplified stream I/O in HttpTunnelingServlet using dynamic channel buffer
This commit is contained in:
parent
35b08df70a
commit
937ee06d9d
@ -22,6 +22,7 @@
|
|||||||
package org.jboss.netty.channel.socket.http;
|
package org.jboss.netty.channel.socket.http;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.PushbackInputStream;
|
import java.io.PushbackInputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -136,16 +137,24 @@ public class HttpTunnelingServlet extends HttpServlet {
|
|||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response, HttpSession session,
|
HttpServletResponse response, HttpSession session,
|
||||||
HttpTunnelingChannelHandler handler) throws IOException {
|
HttpTunnelingChannelHandler handler) throws IOException {
|
||||||
int length = request.getContentLength();
|
|
||||||
if (length > 0) {
|
InputStream in = request.getInputStream();
|
||||||
byte[] bytes = new byte[length];
|
if (in != null) {
|
||||||
request.getInputStream().read(bytes);
|
ChannelBuffer requestContent = ChannelBuffers.dynamicBuffer();
|
||||||
ChannelBuffer cb = ChannelBuffers.copiedBuffer(bytes);
|
for (;;) {
|
||||||
channel.write(cb);
|
int writtenBytes = requestContent.writeBytes(in, 4096);
|
||||||
|
if (writtenBytes < 0) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (requestContent.readable()) {
|
||||||
|
channel.write(requestContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handler.setOutputStream(response.getOutputStream());
|
handler.setOutputStream(response.getOutputStream());
|
||||||
List<MessageEvent> buffers = handler.getAwaitingEvents();
|
List<MessageEvent> buffers = handler.getAwaitingEvents();
|
||||||
length = 0;
|
int length = 0;
|
||||||
if (buffers.size() > 0) {
|
if (buffers.size() > 0) {
|
||||||
for (MessageEvent buffer: buffers) {
|
for (MessageEvent buffer: buffers) {
|
||||||
length += ((ChannelBuffer) buffer.getMessage()).readableBytes();
|
length += ((ChannelBuffer) buffer.getMessage()).readableBytes();
|
||||||
|
Loading…
Reference in New Issue
Block a user