JAVA-3541: Move spring-5-mvc into spring-web-modules

This commit is contained in:
Krzysztof Woyke
2021-01-06 11:16:55 +01:00
parent 40dbb56721
commit b348dd79c8
28 changed files with 67 additions and 69 deletions

View File

@@ -0,0 +1,35 @@
package com.baeldung.web;
import com.baeldung.Constants;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
@Controller
public class ResponseBodyEmitterController {
private ExecutorService nonBlockingService = Executors.newCachedThreadPool();
@GetMapping(Constants.API_RBE)
public ResponseEntity<ResponseBodyEmitter> handleRbe() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
nonBlockingService.execute(() -> {
try {
emitter.send(Constants.API_RBE_MSG + " @ " + new Date(), MediaType.TEXT_PLAIN);
emitter.complete();
} catch (Exception ex) {
System.out.println(Constants.GENERIC_EXCEPTION);
emitter.completeWithError(ex);
}
});
return new ResponseEntity(emitter, HttpStatus.OK);
}
}