0

I'm developing JSF web application using Primefaces and Tomcat. I need to consume some REST services deployed on the Wildfly AS. What would be the best place/scope to store Jersey Client instance in webapp? Application Scope or Session Scope? Maybe something different.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
user6492999
  • 135
  • 1
  • 1
  • 7
  • It is totally dependent on how you can share between users or not... Maybe you do not even need to 'store' it, but runtime create it each time in a request scoped service... And this is in no way jsf related... Generic Q... – Kukeltje Aug 29 '17 at 19:34
  • 1
    Possible duplicate of [How to choose the right bean scope?](https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope) – Kukeltje Aug 29 '17 at 19:34
  • So you need to access external data from your view? I think your best is to implement some `RemoteAccessService`, which would be an stateless bean containing the jsersey client and abstracts your view from how the data is being accessed. Then inject that service wherever you need in JSF beans. – Aritz Aug 30 '17 at 06:07
  • Thanks for your comments. I have something like RemoteAccessService. Now it's stateless ejb bean so i instantiate Jersey Client every time when I need to GET or POST. It's bad idea because Client is heavy object. I need to move my webapp to pure Tomcat so my RemoteAccessService will became ManagedBean. Which scope should I use for RemoteAccessService and how to use the same Jersey Client instance while consuming REST service by many web app threads? – user6492999 Aug 30 '17 at 06:21

0 Answers0