Best way to consume http resource from EJB or Java EE webapp

I have a java ee 7 app with jsf2, ejb3.1 , jpa etc. running in a Glassfish4 container.

At the submission of a facelet, I want to call an external http resource (most probably using apache http client). The response is going to be text response, which I will need to parse and then do some db stuff afterwards as well.

My First idea is to call it from an ejb, but as the clint may spawn threads, it is not a good idea. I have also heard about ways to restrict the httpClient in such a way that it doesn't spawn threads e.g. use HttpConnectionManager, don't use timeouts etc. But then I think I would loose some performance.

What about an asynchronous ejb method which can eventually use / trigger the httpClient ?

What will be the best way to achieve this?

What should I do to manage the connections ?


Why not using a JAX-RS client as in this simple example:

 Client client = ClientBuilder.newClient();
 String content ="")

More informations in the Java EE 7 tutorial.

Need Your Help

Code signing error in Xcode 8

ios swift xcode settings signing

I want to run my app on my device instead of on the simulator, but every time I try to run it, I get a code signing error:

Inner XML tag Parsing Using C#

c# xmlnodelist

<career code="17-1011.00">