Browse code

IN-31 Fix: delayed empty response

David Phan authored on 05/12/2018 13:31:13
Showing 4 changed files
... ...
@@ -339,10 +339,12 @@ public class SyncProtocol implements IEasProtocol<SyncRequest, SyncResponse> {
339 339
 			final Handler<Void> completion) {
340 340
 
341 341
 		if (response == null) {
342
-			logger.debug("empty response, send http 200");
343
-			Backends.internalStorage().updateLastSync(bs);
344
-			responder.sendStatus(200);
345
-			completion.handle(null);
342
+			// IN-31, delayed empty response
343
+			responder.vertx().setTimer(500, h -> {
344
+				Backends.internalStorage().updateLastSync(bs);
345
+				responder.sendStatus(200);
346
+				completion.handle(null);
347
+			});
346 348
 			return;
347 349
 		}
348 350
 
... ...
@@ -21,6 +21,7 @@ package net.bluemind.eas.impl;
21 21
 import java.io.IOException;
22 22
 import java.io.InputStream;
23 23
 
24
+import org.vertx.java.core.Vertx;
24 25
 import org.w3c.dom.Document;
25 26
 
26 27
 import net.bluemind.eas.dto.NamespaceMapping;
... ...
@@ -49,4 +50,6 @@ public interface Responder {
49 49
 
50 50
 	void sendStatus(int statusCode);
51 51
 
52
+	Vertx vertx();
53
+
52 54
 }
... ...
@@ -23,6 +23,7 @@ import java.io.InputStream;
23 23
 
24 24
 import org.slf4j.Logger;
25 25
 import org.slf4j.LoggerFactory;
26
+import org.vertx.java.core.Vertx;
26 27
 import org.vertx.java.core.buffer.Buffer;
27 28
 import org.vertx.java.core.http.HttpHeaders;
28 29
 import org.vertx.java.core.http.HttpServerRequest;
... ...
@@ -50,10 +51,16 @@ public final class VertxResponder implements Responder {
50 50
 	private static final CharSequence HEADER_CACHE = HttpHeaders.createOptimized("private");
51 51
 	private static final CharSequence HEADER_WBXML_CONTENT = HttpHeaders
52 52
 			.createOptimized("application/vnd.ms-sync.wbxml");
53
+	private Vertx vertx;
53 54
 
54 55
 	public VertxResponder(HttpServerRequest req, HttpServerResponse resp) {
56
+		this(req, resp, null);
57
+	}
58
+
59
+	public VertxResponder(HttpServerRequest req, HttpServerResponse resp, Vertx vertx) {
55 60
 		this.resp = resp;
56 61
 		this.output = new VertxOutput(req);
62
+		this.vertx = vertx;
57 63
 	}
58 64
 
59 65
 	private void setASHeaders(ConnectionHeader connection) {
... ...
@@ -120,4 +127,9 @@ public final class VertxResponder implements Responder {
120 120
 		return asOutput(ConnectionHeader.keepAlive);
121 121
 	}
122 122
 
123
+	@Override
124
+	public Vertx vertx() {
125
+		return vertx;
126
+	}
127
+
123 128
 }
... ...
@@ -105,7 +105,7 @@ public final class ProtocolExecutor {
105 105
 					AsyncResult<R> asyncResult = protoResponseMsg.body().getValue();
106 106
 					vertxReq.resume();
107 107
 					if (asyncResult.succeeded()) {
108
-						VertxResponder responder = new VertxResponder(vertxReq, vertxReq.response());
108
+						VertxResponder responder = new VertxResponder(vertxReq, vertxReq.response(), vertx);
109 109
 						try {
110 110
 							protocol.write(bs, responder, asyncResult.result(), new Handler<Void>() {
111 111