Commit e4ed261b authored by Dave Cridland's avatar Dave Cridland

Merge pull request #209 from tevans/OF-909

OF-909: Include ack in BOSH response body element
parents 606d34c2 8e19f5ba
...@@ -299,9 +299,9 @@ public class HttpBindServlet extends HttpServlet { ...@@ -299,9 +299,9 @@ public class HttpBindServlet extends HttpServlet {
if (async) { if (async) {
response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent)); response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent));
} else { } else {
// BOSH communication should not have Chunked encoding. Ensure that the // BOSH communication should not use Chunked encoding.
// buffer can hold the entire response to prevent chunking. // This is prevented by explicitly setting the Content-Length header.
context.getResponse().setBufferSize(byteContent.length); context.getResponse().setContentLength(byteContent.length);
context.getResponse().getOutputStream().write(byteContent); context.getResponse().getOutputStream().write(byteContent);
context.getResponse().getOutputStream().flush(); context.getResponse().getOutputStream().flush();
context.complete(); context.complete();
...@@ -348,14 +348,6 @@ public class HttpBindServlet extends HttpServlet { ...@@ -348,14 +348,6 @@ public class HttpBindServlet extends HttpServlet {
sendLegacyError(context, error, null); sendLegacyError(context, error, null);
} }
protected static String createEmptyBody(boolean terminate)
{
final Element body = DocumentHelper.createElement("body");
if (terminate) { body.addAttribute("type", "terminate"); }
body.addNamespace("", "http://jabber.org/protocol/httpbind");
return body.asXML();
}
protected static String createErrorBody(String type, String condition) { protected static String createErrorBody(String type, String condition) {
final Element body = DocumentHelper.createElement("body"); final Element body = DocumentHelper.createElement("body");
body.addNamespace("", "http://jabber.org/protocol/httpbind"); body.addNamespace("", "http://jabber.org/protocol/httpbind");
......
...@@ -122,9 +122,9 @@ public class HttpConnection { ...@@ -122,9 +122,9 @@ public class HttpConnection {
} }
if (body == null) { if (body == null) {
body = HttpBindServlet.createEmptyBody(false); body = getSession().createEmptyBody(false);
} }
HttpBindServlet.respond(this.getSession(), this.context, body, async); HttpBindServlet.respond(getSession(), this.context, body, async);
} }
/** /**
......
...@@ -710,7 +710,7 @@ public class HttpSession extends LocalClientSession { ...@@ -710,7 +710,7 @@ public class HttpSession extends LocalClientSession {
try { try {
// If onTimeout does not result in a complete(), the container falls back to default behavior. // If onTimeout does not result in a complete(), the container falls back to default behavior.
// This is why this body is to be delivered in a non-async fashion. // This is why this body is to be delivered in a non-async fashion.
connection.deliverBody(createEmptyBody(), false); connection.deliverBody(createEmptyBody(false), false);
setLastResponseEmpty(true); setLastResponseEmpty(true);
// This connection timed out we need to increment the request count // This connection timed out we need to increment the request count
...@@ -1014,13 +1014,8 @@ public class HttpSession extends LocalClientSession { ...@@ -1014,13 +1014,8 @@ public class HttpSession extends LocalClientSession {
private String createDeliverable(Collection<Deliverable> elements) { private String createDeliverable(Collection<Deliverable> elements) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<body xmlns='" + "http://jabber.org/protocol/httpbind" + "'"); builder.append("<body xmlns='http://jabber.org/protocol/httpbind' ack='")
.append(getLastAcknowledged()).append("'>");
long ack = getLastAcknowledged();
if(ack > lastRequestID)
builder.append(" ack='").append(ack).append("'");
builder.append(">");
setLastResponseEmpty(elements.size() == 0); setLastResponseEmpty(elements.size() == 0);
synchronized (elements) { synchronized (elements) {
...@@ -1095,20 +1090,12 @@ public class HttpSession extends LocalClientSession { ...@@ -1095,20 +1090,12 @@ public class HttpSession extends LocalClientSession {
}); });
} }
private String createEmptyBody() { protected String createEmptyBody(boolean terminate)
Element body = DocumentHelper.createElement("body");
body.addNamespace("", "http://jabber.org/protocol/httpbind");
long ack = getLastAcknowledged();
if(ack > lastRequestID)
body.addAttribute("ack", String.valueOf(ack));
return body.asXML();
}
protected static String createEmptyBody(boolean terminate)
{ {
final Element body = DocumentHelper.createElement("body"); final Element body = DocumentHelper.createElement("body");
if (terminate) { body.addAttribute("type", "terminate"); } if (terminate) { body.addAttribute("type", "terminate"); }
body.addNamespace("", "http://jabber.org/protocol/httpbind"); body.addNamespace("", "http://jabber.org/protocol/httpbind");
body.addAttribute("ack", String.valueOf(getLastAcknowledged()));
return body.asXML(); return body.asXML();
} }
......
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