javarestjakarta-eejax-rs

How can 2 REST-interfaces share instances


We're planning an "REST"-Server and now have the problem, that we want different REST-Interfaces to share information.

As an example to make thing clearer

This SessionMaker checks if user and password are correct and returns sessiontoken if so (this works). It's supposed to store the token in the sessionMap so that DoThings can access it. But DoThings can't access that SessionMap instead, a new instance is created.


How can we have SessionMaker and DoThings share the same SessionMap-instance.

I have 3 ideas but don't know which are even applicable.

  1. Make SessionMaker and DoTHing singletons (right now there are in getClasses) in the ApplicationClass. Make an Instance of SessionMap and give it to both.
  2. Try to fish it out of the Applicationcontext, but I don't know how.
  3. Merge SessionMaker and DoThings into one, but that results in the antipattern "Blob"

The only other question that I found, which deals with a similar situation is: Jersey REST Server: instantiating resource classes


Solution

  • You should use EJBs for this purpose.