COURTAULT Francois
2018-02-16 13:01:52 UTC
Hello everyone,
I want to use HttpServer for testing purpose.
The way I want to use, it is:
* Start the Httpserver with a HttpRequestHandler registered for a dedicated URI
* Receive POST requests on this URI with a payload
* Check the payload
o If the payload doesn't contain a dedicated id, continue to receive POST requests until a certain duration is reached.
o If the payload contains the dedicated id but with additional data that doesn't match what we are waiting for, return a 400 and then stop/shutdown the HttpServer right after.
o If the payload contains the dedicated id with additional data that matches what we are waiting for, return 200 and then stop/shutdown the HttpServer right after.
I have found a way to do this, using some flags, but I have to wait for a timeout using awaitTermination method.
Is there a way, once I have received either a POST request with a right payload or a wrong payload, in the HttpRequestHandler.handle method, to return an HTTP response and, right after perform a stop/shutdown of the HttpServer ?
FYI, if I stop/shutdown the HTTPServer in the the HttpRequestHandler.handle method, the HTTP response hasn't been sent back to the caller.
I suppose also that if I do a System.exit(0) with a addShutdownHook registered, the HTTP response won't sent back to the caller, right ?
Best Regards.
I want to use HttpServer for testing purpose.
The way I want to use, it is:
* Start the Httpserver with a HttpRequestHandler registered for a dedicated URI
* Receive POST requests on this URI with a payload
* Check the payload
o If the payload doesn't contain a dedicated id, continue to receive POST requests until a certain duration is reached.
o If the payload contains the dedicated id but with additional data that doesn't match what we are waiting for, return a 400 and then stop/shutdown the HttpServer right after.
o If the payload contains the dedicated id with additional data that matches what we are waiting for, return 200 and then stop/shutdown the HttpServer right after.
I have found a way to do this, using some flags, but I have to wait for a timeout using awaitTermination method.
Is there a way, once I have received either a POST request with a right payload or a wrong payload, in the HttpRequestHandler.handle method, to return an HTTP response and, right after perform a stop/shutdown of the HttpServer ?
FYI, if I stop/shutdown the HTTPServer in the the HttpRequestHandler.handle method, the HTTP response hasn't been sent back to the caller.
I suppose also that if I do a System.exit(0) with a addShutdownHook registered, the HTTP response won't sent back to the caller, right ?
Best Regards.