Commit 8831c7b2 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-885: Use NIO for writing the HTTP response.

parent b1aaa57a
...@@ -294,11 +294,9 @@ public class HttpBindServlet extends HttpServlet { ...@@ -294,11 +294,9 @@ public class HttpBindServlet extends HttpServlet {
if (JiveGlobals.getBooleanProperty("log.httpbind.enabled", false)) { if (JiveGlobals.getBooleanProperty("log.httpbind.enabled", false)) {
System.out.println(new Date()+": HTTP SENT(" + session.getStreamID().getID() + "): " + content); System.out.println(new Date()+": HTTP SENT(" + session.getStreamID().getID() + "): " + content);
} }
byte[] byteContent = content.getBytes("UTF-8");
response.setContentLength(byteContent.length); final byte[] byteContent = content.getBytes("UTF-8");
response.getOutputStream().write(byteContent); response.getOutputStream().setWriteListener( new WriteListenerImpl(context, byteContent) );
response.getOutputStream().close();
context.complete();
} }
private void sendError(HttpSession session, AsyncContext context, BoshBindingError bindingError) private void sendError(HttpSession session, AsyncContext context, BoshBindingError bindingError)
...@@ -435,4 +433,30 @@ public class HttpBindServlet extends HttpServlet { ...@@ -435,4 +433,30 @@ public class HttpBindServlet extends HttpServlet {
} }
} }
} }
static class WriteListenerImpl implements WriteListener {
private final AsyncContext context;
private final byte[] data;
private final String remoteAddress;
public WriteListenerImpl(AsyncContext context, byte[] data) {
this.context = context;
this.data = data;
this.remoteAddress = getRemoteAddress(context);
}
@Override
public void onWritePossible() throws IOException {
Log.trace("Data can be written to [" + remoteAddress + "]");
context.getResponse().getOutputStream().write(data);
context.complete();
}
@Override
public void onError(Throwable throwable) {
Log.warn("Error writing response data to [" + remoteAddress + "]", throwable);
context.complete();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment