0

Working on a JAX-RS application. I have an endpoint (@GET). Once the request arrives at endpoint, the call stack flows through multiple service classes. As shown in below image. I want something in place of that RED Bucket.

enter image description here

Is there any I can create a shared session map which lives only per request?

I considered using STATIC or @Singleton but these values are shared between multiple requests. I don't want that.

Please point me to right question

Kishor Prakash
  • 8,011
  • 12
  • 61
  • 92
  • what's your jax-rs implementations? – Ori Marko Mar 05 '19 at 13:49
  • What about using a `ThreadLocal` variable? – Madhu Bhat Mar 05 '19 at 13:55
  • 1
    It may depend on how this shared resource is created. Can it be built with information from the request? Maybe a custom CDI producer that creates the resource based on the request-context and injects it into your services would fit your requirements. If the resource can only be created by your `BurgerBuilderService` and all other services depend on it, it may be better to "forward" it as method-parameter to singal that the following services depend on this resource. – Sebastian Mar 05 '19 at 13:59
  • What's wrong with a `@RequestScoped` component? – kaqqao Mar 05 '19 at 14:16
  • What JAX-RS implementation are you using? – Paul Samsotha Mar 05 '19 at 18:26

1 Answers1

0

This seems to be a scoping question. This may provide an answer to your question:

How to choose the right bean scope?

Thomas Bitonti
  • 1,179
  • 7
  • 14
  • Ha Ha Ha.... This is so weird Have you seen the answers on that question? It was I who answered that question. But I answered it for JSF not for JAX-RS and I guess it works here as well. – Kishor Prakash Mar 06 '19 at 08:33