Below solution is working as expected on Tomcat Server -> shortly speaking I am getting 503 status code with custom timeout message after 3 seconds of task processing (Thread sleep). Unfortunately if the same application is deployed on Weblogic Server (12.2.1.4) and the same test case executed I am not getting timeout exception, instead I am getting mixed responses (requestBody equals "sleepMore"): sometimes 200 status with my custom message "Deferred successfully returned" and sometimes I am getting 200 status code with no payload..
Weblogic Server 12.2.1.4
Java 8
@PostMapping("/deferred")
DeferredResult<ResponseEntity<Object>> doDeferred(@RequestBody String requestBody) throws InterruptedException {
final ResponseEntity<Object> timeoutResponse = ResponseEntity.status(503).body("Deferred timeout");
final DeferredResult<ResponseEntity<Object>> responseEntityDeferredResult = new DeferredResult<ResponseEntity<Object>>(3000L, timeoutResponse);
if(requestBody == null){
requestBody = "anything";
}
final String finalRequestBody = requestBody;
if(finalRequestBody.contains("sleep")){
ForkJoinPool.commonPool().submit(() -> {
log.info("Processing in separate thread");
if(finalRequestBody.equals("sleepMore")){
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
log.info("After the sleep execution");
responseEntityDeferredResult.setResult(ResponseEntity.status(200).body("Deferred successfully returned"));
log.info("Finished processing in separate thread");
});
} else {
responseEntityDeferredResult.setResult(ResponseEntity.status(200).body("Deferred successfully returned"));
}
return responseEntityDeferredResult;
}
Comment From: snicoll
@ma1994jkel I am afraid that if this is working with Tomcat, Weblogic support is the place to report such an issue. If it turns out something is Spring needs to be changed, we can reopen this issue.