Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [osgi-users] JAX-RS Whiteboard question

Hi Ray,

thanks for the reply. So IIUC the suggestion is to use the PROTOTYPE scope always, unless you are sure you don't need it. Right?

Because IMHO the example in the specification would not really need to be of PROTOTYPE scope, or am I wrong?
https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#d0e133428

The enRoute Microservices example is not PROTOTYPE scope:
https://enroute.osgi.org/tutorial/030-tutorial_microservice.html

And are you talking about context based injections on fields (which is clear from the specification that in that case PROTOTYPE scope should be used) or also context based injections as method parameters?

For example I have implemented a JAX-RS resource for file uploads. The HttpServletRequest is injected as method parameter. So I would assume PROTOTYPE scope is not needed. But maybe I am wrong and we run into issues if the service is used more frequently?
https://git.eclipse.org/c/app4mc/org.eclipse.app4mc.cloud.git/tree/org.eclipse.app4mc.converter.cloud/converter-service/src/main/java/org/eclipse/app4mc/org/eclipse/app4mc/converter/cloud/MigrationRestService.java?h=develop

I'm just asking because I haven't found a clear description on this. And I would like to explain it better if someone else comes across the same question. I am not against PROTOTYPE scope, I just want to understand it better. :)

Greez,
Dirk

On Thu, Jan 7, 2021 at 4:01 PM Raymond Auge <raymond.auge@xxxxxxxxxxx> wrote:
JAX-RS natively expects to re-create resources on every request, so unless you know very well the behaviour and have _no_ context (i.e. request, session) based injections into your resources _only_ then can you avoid PROTOTYPE scope.

- Ray

On Thu, Jan 7, 2021 at 4:50 AM Fauth Dirk (XC-ECO/ESM1) <Dirk.Fauth@xxxxxxxxxxxx> wrote:

Hi all,

 

New year -> new mailing list -> new question. 😊

 

I wish everyone on this mailing list a happy and healthy new year!

 

I’m currently writing the blog post about JAX-RS Whiteboard as promised last year. There is one question that came up where I am not sure about the answer. In the specification all JAX-RS Whiteboard Resource examples are configured with PROTOTYPE scope. In chapter 151.4.2 JAX-RS Whiteboard Resource Lifecycle it is explained that stateless services can also be registered as singletons (which is more common in OSGi). If the JAX-RS Whiteboard Resource service has a state (e.g. a JAX-RS context value in a field) it should be PROTOTYPE scope to get a new instance for each request.

 

All examples in the specification are stateless, so my question is, is there a reason/best practice to create all JAX-RS Whiteboard Resource services with PROTOTYPE scope?

 

Mit freundlichen Grüßen / Best regards

Dirk Fauth


Cross-Domain Computing Solutions, Cross Automotive Platforms - System, Software and Tools Engineering Engineering Software Methods and Tools1 (XC-ECO/ESM1)
Robert Bosch GmbH | Postfach 30 02 40 | 70442 Stuttgart | GERMANY |
www.bosch.com
Tel.
+49 711 811-57819 | Telefax +49 711 811 | Dirk.Fauth@xxxxxxxxxxxx

Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000;
Aufsichtsratsvorsitzender: Franz Fehrenbach; Geschäftsführung: Dr. Volkmar Denner,
Prof. Dr. Stefan Asenkerschbaumer, Filiz Albrecht, Dr. Michael Bolle, Dr. Christian Fischer,
Dr. Stefan Hartung, Dr. Markus Heyn, Harald Kröger, Rolf Najork, Uwe Raschke

_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users


--
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
OSGi Fellow
_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

Back to the top