Discussion:
Advice when using HttpServer for testing purpose
COURTAULT Francois
2018-02-16 13:01:52 UTC
Permalink
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.
Oleg Kalnichevski
2018-02-16 16:21:45 UTC
Permalink
Post by COURTAULT Francois
Hello everyone,
I want to use HttpServer for testing purpose.
*       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 ?
One should be able to do so by throwing an unchecked (runtime)
exception but why would you want to shut down the server from a request
handler in the first place? Would not it be massively cleaner and
easier to just a return a proper response and let the caller decide
whether or not the server should be shut down?

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
COURTAULT Francois
2018-02-19 18:52:43 UTC
Permalink
Hello Oleg,

Our test case is asynchronous and our test requires that the testing entity has to be an HTTP client and an HTTP server but not at the same time.

1) Our testing entity, as an HTTP client, sends a request to our product.
2)Then asynchronously, after a certain amount of time, the product sends an HTTP request to our testing entity (HTTP server)
3) The testing entity has to check the request received . Test is OK if the payload received matches the expected payload and KO if not.
In this configuration, this is up to the HTTP server to determine if the test is OK or KO.

Is it clear ?

We have to perform this several times and have to set a test result each time => this is why we have to shut down the HTTP server after receiving a bad or good HTTP request.

When you said "throwing an unchecked (runtime) exception", where do we have to do this ? In the HttpRequestHandler.handle method ?
But in such case, will the product received the entire HTTP response ?

BTW, I have another question about HTTPServer shutdown method which takes a grace period as an argument.
I haven't found so much explanation looking at the java doc. So, could you explain me please, what is the meaning of this grace period ?
If we want to perform a hard shut down, do we have to set this value to 0 ?
Do we have to perform a stop + shutdown HTTPServer calls or a shutdown call is sufficient ?

Thanks in advance for your help .

Best Regards.

-----Original Message-----
From: Oleg Kalnichevski [mailto:***@apache.org]
Sent: vendredi 16 février 2018 17:22
To: HttpClient User Discussion <httpclient-***@hc.apache.org>
Subject: Re: Advice when using HttpServer for testing purpose
Post by COURTAULT Francois
Hello everyone,
I want to use HttpServer for testing purpose.
* 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 ?
One should be able to do so by throwing an unchecked (runtime) exception but why would you want to shut down the server from a request handler in the first place? Would not it be massively cleaner and easier to just a return a proper response and let the caller decide whether or not the server should be shut down?

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org

________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional comman
Oleg Kalnichevski
2018-02-20 11:30:09 UTC
Permalink
Post by COURTAULT Francois
Hello Oleg,
Our test case is asynchronous and our test requires that  the testing
entity has to be an HTTP client and an HTTP server but not at the
same time.
1) Our testing entity, as an HTTP client, sends a request to our product.
2)Then asynchronously, after a certain amount of time,  the product
sends an HTTP request to our testing entity (HTTP server)
3) The testing entity has to check the request received . Test is OK
if the payload received matches the expected payload and KO if not.
     In this configuration, this is up to the HTTP server to
determine if the test is OK or KO.
Is it clear ?
Sort of. It is still unclear why the server could not return KO status
to the client instead of shutting down.

We do a lot of integration tests using HttpCore embedded server but
there was never a need to to let the server go down without sending
back a response to the client

https://github.com/apache/httpcomponents-client/tree/4.5.x/httpclient/s
rc/test/java/org/apache/http/impl/client/integration
Post by COURTAULT Francois
We have to perform this several times and have to set a test result
each time => this is why we have to shut down the HTTP server
after  receiving a bad or good HTTP request.
When you said "throwing an unchecked (runtime) exception", where do
we have to do this ? In the HttpRequestHandler.handle method ?
But in such case, will the product received the entire HTTP response ?
Yes, from the handler method.
Post by COURTAULT Francois
BTW, I have another question about HTTPServer shutdown method which
takes a grace period as an argument.
I haven't found so much explanation looking at the java doc. So,
could you explain me please, what is the meaning of this grace period
?
It is a period of time when the server stops accepting new connections
but allows active connections to complete ongoing exchanges.
Post by COURTAULT Francois
If we want to perform a hard shut down, do we have to set this value to 0 ?
Yes.
Post by COURTAULT Francois
Do we have to perform a stop + shutdown HTTPServer calls or a
shutdown call is sufficient ?
#shutdown should be enough.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
COURTAULT Francois
2018-02-20 15:42:41 UTC
Permalink
Hello Oleg,

Thanks a lot for your answers.

But there is still something unclear for me.
When you said that I am able to throw an unchecked exception in the handle method. In this case:
- does it means that the server will be shutdown automatically ?
- will the HTTP response be received by our product ? (don't think so but prefer to check with you)

Best Regards.

-----Original Message-----
From: Oleg Kalnichevski [mailto:***@apache.org]
Sent: mardi 20 février 2018 12:30
To: HttpClient User Discussion <httpclient-***@hc.apache.org>
Subject: Re: Advice when using HttpServer for testing purpose
Post by COURTAULT Francois
Hello Oleg,
Our test case is asynchronous and our test requires that the testing
entity has to be an HTTP client and an HTTP server but not at the same
time.
1) Our testing entity, as an HTTP client, sends a request to our product.
2)Then asynchronously, after a certain amount of time, the product
sends an HTTP request to our testing entity (HTTP server)
3) The testing entity has to check the request received . Test is OK
if the payload received matches the expected payload and KO if not.
In this configuration, this is up to the HTTP server to determine
if the test is OK or KO.
Is it clear ?
Sort of. It is still unclear why the server could not return KO status to the client instead of shutting down.

We do a lot of integration tests using HttpCore embedded server but there was never a need to to let the server go down without sending back a response to the client

https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fhttpcomponents-client%2Ftree%2F4.5.x%2Fhttpclient%2Fs&data=02%7C01%7CFrancois.Courtault%40gemalto.com%7Cf4d418478ca6446e133208d578564244%7C37d0a9db7c464096bfe31add5b495d6d%7C1%7C0%7C636547234230139869&sdata=QI0AAG1youwZW9AmtkVPmXEfcgKd%2FO4uYDEf6xJ4maU%3D&reserved=0
rc/test/java/org/apache/http/impl/client/integration
Post by COURTAULT Francois
We have to perform this several times and have to set a test result
each time => this is why we have to shut down the HTTP server after
receiving a bad or good HTTP request.
When you said "throwing an unchecked (runtime) exception", where do we
have to do this ? In the HttpRequestHandler.handle method ?
But in such case, will the product received the entire HTTP response ?
Yes, from the handler method.
Post by COURTAULT Francois
BTW, I have another question about HTTPServer shutdown method which
takes a grace period as an argument.
I haven't found so much explanation looking at the java doc. So,
could you explain me please, what is the meaning of this grace period
?
It is a period of time when the server stops accepting new connections
but allows active connections to complete ongoing exchanges.
Post by COURTAULT Francois
If we want to perform a hard shut down, do we have to set this value to 0 ?
Yes.
Post by COURTAULT Francois
Do we have to perform a stop + shutdown HTTPServer calls or a
shutdown call is sufficient ?
#shutdown should be enough.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org

________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
B�KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB��[��X��ܚX�KK[XZ[��Y[� ]\�\��][��X��ܚX�P˘\X�K�ܙ�B��܈Y][ۘ[��[X[
COURTAULT Francois
2018-02-20 16:02:07 UTC
Permalink
Hello Oleg again,

I have performed a test by raising a RuntimeException in the handle method: this doesn't shutdown the HTTPServer automatically and the HTTP response is not sent back to the caller.

So the "unchecked exception" in handle method won't work for the goal I want to achieve unfortunately.

Best Regards.

-----Original Message-----
From: COURTAULT Francois [mailto:***@gemalto.com]
Sent: mardi 20 février 2018 16:43
To: HttpClient User Discussion <httpclient-***@hc.apache.org>
Subject: [++SPAM++]: RE: Advice when using HttpServer for testing purpose

Hello Oleg,

Thanks a lot for your answers.

But there is still something unclear for me.
When you said that I am able to throw an unchecked exception in the handle method. In this case:
- does it means that the server will be shutdown automatically ?
- will the HTTP response be received by our product ? (don't think so but prefer to check with you)

Best Regards.

-----Original Message-----
From: Oleg Kalnichevski [mailto:***@apache.org]
Sent: mardi 20 février 2018 12:30
To: HttpClient User Discussion <httpclient-***@hc.apache.org>
Subject: Re: Advice when using HttpServer for testing purpose
Post by COURTAULT Francois
Hello Oleg,
Our test case is asynchronous and our test requires that the testing
entity has to be an HTTP client and an HTTP server but not at the same
time.
1) Our testing entity, as an HTTP client, sends a request to our product.
2)Then asynchronously, after a certain amount of time, the product
sends an HTTP request to our testing entity (HTTP server)
3) The testing entity has to check the request received . Test is OK
if the payload received matches the expected payload and KO if not.
In this configuration, this is up to the HTTP server to determine
if the test is OK or KO.
Is it clear ?
Sort of. It is still unclear why the server could not return KO status to the client instead of shutting down.

We do a lot of integration tests using HttpCore embedded server but there was never a need to to let the server go down without sending back a response to the client

https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fhttpcomponents-client%2Ftree%2F4.5.x%2Fhttpclient%2Fs&data=02%7C01%7CFrancois.Courtault%40gemalto.com%7Cf4d418478ca6446e133208d578564244%7C37d0a9db7c464096bfe31add5b495d6d%7C1%7C0%7C636547234230139869&sdata=QI0AAG1youwZW9AmtkVPmXEfcgKd%2FO4uYDEf6xJ4maU%3D&reserved=0
rc/test/java/org/apache/http/impl/client/integration
Post by COURTAULT Francois
We have to perform this several times and have to set a test result
each time => this is why we have to shut down the HTTP server after
receiving a bad or good HTTP request.
When you said "throwing an unchecked (runtime) exception", where do we
have to do this ? In the HttpRequestHandler.handle method ?
But in such case, will the product received the entire HTTP response ?
Yes, from the handler method.
Post by COURTAULT Francois
BTW, I have another question about HTTPServer shutdown method which
takes a grace period as an argument.
I haven't found so much explanation looking at the java doc. So, could
you explain me please, what is the meaning of this grace period ?
It is a period of time when the server stops accepting new connections but allows active connections to complete ongoing exchanges.
Post by COURTAULT Francois
If we want to perform a hard shut down, do we have to set this value to 0 ?
Yes.
Post by COURTAULT Francois
Do we have to perform a stop + shutdown HTTPServer calls or a shutdown call is sufficient ?
#shutdown should be enough.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org

________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
B KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB  [ X ܚX KK[XZ[
 Y[
]\ \ ][ X ܚX P˘\X K ܙ B ܈Y][ۘ[ [X[  K[XZ[
 Y[
]\ \ Z[˘\X K ܙ B B
________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional comman

Loading...