Comments (0)

Files changed (1)

File xmpp-server/src/main/java/rocks/xmpp/extensions/httpbind/server/BoshConnection.java Modified

View file
  • Ignore whitespace
  • Hide word diff
         // it SHOULD return an HTTP 200 (OK) response that includes the buffered copy of the original XML response to the client.
         final Body bufferedBody = responseBuffer.get(body.getRid());
         if (bufferedBody != null) {
-            request.resume(bufferedBody);
+            request.asyncResponse.resume(bufferedBody);
             return;
         }
 
             // with a recoverable binding condition (see Recoverable Binding Conditions)
             // and send any future response to the latest request.
             final Optional<BodyRequest> pendingRequest = Stream.concat(requests.stream(), inboundQueue.stream()).filter(r -> r.body.getRid().equals(body.getRid())).findAny();
-            pendingRequest.ifPresent(bodyRequest -> bodyRequest.resume(Body.builder().type(Body.Type.ERROR).build()));
+            pendingRequest.ifPresent(bodyRequest -> bodyRequest.resume(Body.builder().type(Body.Type.ERROR)));
 
             // This queue will sort the requests by their RID.
             inboundQueue.offer(request);
         if (isPause) {
             maxPause = Math.min(body.getPause(), MAX_PAUSE);
             // Note: The response to the pause request MUST NOT contain any payloads.
-            request.resume(Body.builder().build());
+            request.resume(Body.builder());
             // Respond to all requests.
             hold = 0;
         } else {
                 deliverables.clear();
             }
         }
-        bodyRequest.resume(builder.build());
+        bodyRequest.resume(builder);
     }
 
     @Override
                 .sessionId(session.getId())
                 .authId(session.getId())
                 .wait(wait)
+                .ack(sessionRequest.getRid())
                 .requests(simultaneousRequests)
                 .version("1.11.1")
                 .hold(hold)
                 .to(sessionRequest.getTo())
                 .from(Jid.of("domain"))
                 .restartLogic(true)
-                .xmppVersion("1.0")
-                .build());
+                .xmppVersion("1.0"));
     }
 
     @Override
 
     @Override
     public final void flush() {
-        Body body = null;
+        Body.Builder body = null;
         BodyRequest bodyRequest = null;
         synchronized (deliverables) {
             if (!deliverables.isEmpty()) {
                             bodyBuilder.type(Body.Type.TERMINATE);
                             terminated.set(true);
                         }
-                        body = bodyBuilder.wrappedObjects(deliverables).build();
+                        body = bodyBuilder.wrappedObjects(deliverables);
                         deliverables.clear();
                     }
                 } while (bodyRequest != null && bodyRequest.asyncResponse.isDone());
                 if (terminated.compareAndSet(false, true)) {
                     bodyBuilder.type(Body.Type.TERMINATE);
                 }
-                bodyRequest.resume(bodyBuilder.build());
+                bodyRequest.resume(bodyBuilder);
             }
         }
     }
             this.asyncResponse = asyncResponse;
         }
 
-        private boolean resume(Body response) {
+        private boolean resume(Body.Builder response) {
+            final Body bodyToSend;
+
+            synchronized (inboundQueue) {
+                if (lastRid != body.getRid()) {
+                    response.ack(lastRid);
+                }
+            }
+            bodyToSend = response.build();
+
             // The connection manager SHOULD remember the 'rid' and the associated HTTP response body
             // of the client's most recent requests which were not session pause requests (see Inactivity)
             // and which did not result in an HTTP or binding error.
-            if (body.getPause() == null && response.getType() != Body.Type.TERMINATE) {
-                BoshConnection.this.responseBuffer.put(this.body.getRid(), response);
+            if (body.getPause() == null && bodyToSend.getType() != Body.Type.TERMINATE) {
+                BoshConnection.this.responseBuffer.put(this.body.getRid(), bodyToSend);
             }
 
             // 10. Inactivity
                 }
             }
 
-            return asyncResponse.resume(response);
+            return asyncResponse.resume(bodyToSend);
         }
 
         @Override