Hi Matthias, So it sounds as though you’re in the following situation: Providing a custom Application to the whiteboard The application service has the property osgi.jaxrs.name = MyApp set on the service registration Your application needs, but does not contain, JSON serialisation support You want to use an external MessageBodyReader and MessageBodyWriter service to extend your application
Assuming that these are correct then: Your Application needs to tell the whiteboard that it is missing some required extensions. This will prevent it being deployed until the extension is available. See the details of the osgi.jaxrs.extension.select <https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#service.jaxrs.common.properties> property which will need to match service properties on your whiteboard extension Your external MessageBodyReader and MessageBodyWriter will need to be registered with The service has the property osgi.jaxrs.extension = true (to say that this is an extension) The service registers the interfaces MessageBodyReader and MessageBodyWriter (defining the types that the whiteboard will use it as) The service has the relevant property(ies) to match your application’s extension select filter The service has the property osgi.jaxrs.application.select = (osgi.jaxrs.name=MyApp) to select your application as a target Another option is simply to set the extension as a part of your whiteboard application. This way you avoid the need to set quite so many service properties because the application is “complete” and doesn’t need to register a dependency or be targeted by an extension. All the best, Tim > On 15 Nov 2019, at 00:07, Matthias Leinweber <[email protected]> > wrote: > > Ok i hit an additional problem. > When i create a JaxRsApplication i can reference them in my resource > everything works fine except the MessageWriter and MessageReader e.g. Jackson > Extension is not found. > --> No message body writer has been found for class ... ContentType: > application/json > Without "osgi.jaxrs.application.select=(osgi.jaxrs.name > <http://osgi.jaxrs.name/>=MyApp)", serialization works. > > I also tried to explicitly select the whiteboard for the Application, with > "osgi.jaxrs.whiteboard.target=(service.pid=org.apache.aries.jax.rs.whiteboard.default)" > but that doesn't work. > How does the injection mechanism work? I couldn't figure it out reading the > aries source code. > > regards, > Matthias > > Am Fr., 8. Nov. 2019 um 10:28 Uhr schrieb Tim Ward <[email protected] > <mailto:[email protected]>>: > Hi, > > Yes, you can absolutely inject things using @Context (this is the only way to > do server sent events, so it’s not optional for any implementation). It’s > recommended that you inject into resource methods, rather than into fields, > unless you make your service prototype scope. This is to avoid any potential > threading mismatch if you inject invocation scoped objects (e.g. an incoming > HttpServletRequest) and get two http calls at the same time. > > Tim > >> On 7 Nov 2019, at 16:24, Matthias Leinweber <[email protected] >> <mailto:[email protected]>> wrote: >> >> Great. Thank you very much. >> >> I dont want to add CXF or Jersey. thank to your answer I have come up with >> the idea myself to inject the @Context HttpServletRequest into the JaxRS >> code. To mix in this: >> https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e120961 >> >> <https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e120961> >> I didn't test it yet but does it work? I don't see that the aries JaxRs >> whiteboard impl somewhere defined >> osgi.http.whiteboard.servlet.multipart.enabled=true >> >> Best regards, >> Matthias >> >> Am Do., 7. Nov. 2019 um 15:38 Uhr schrieb Tim Ward <[email protected] >> <mailto:[email protected]>>: >> Hi Matthias >> >>> I was a bit confused about how you could add a Servelt to the >>> JaxRsWhiteboard instead of the HttpWhiteboard for Multi-Part file uploads. >> >> I hope it’s now clear that the JAX-RS whiteboard does not support Servlets. >> You can either: >> Register a servlet with the Http Whiteboard and find a place to put the file >> Handle the multipart file upload using JAX-RS >> >> If the file upload is only needed by your JAX-RS components then I would >> recommend just using JAX-RS rather than a servlet. >> >>> * So a JaxRsResource can but most not belong to an application? >> >> A JAX-RS Whiteboard resource is just a “bare” resource in the service >> registry. In the most common case the resource service that you register >> will bind to the “default” application provided by the JAX-RS Whiteboard. >> There is no need to deploy a custom whiteboard application for resources to >> be hosted by the JAX-RS whiteboard. >> >>> * It's fine to put all your Resources into the same JaxRsWhiteboard even if >>> you could separate them? >> >> Yes. This will work fine. All the resources (by default) will get hosted in >> the default application. If you do want to provide some isolation between >> the resources (e.g. if you need differently configured JSON providers for >> different resources) then you can still do this with a single >> JAX-RSWhiteboard, but you will need to provide separate Applications for the >> resources and extensions. This is because applications within the whiteboard >> *are* isolated from each other, and can have different sets of resources and >> extensions. >> >> In general, however, you’re pretty safe just registering all the resources >> and extensions that you need directly with the whiteboard using the default >> application. >> >> All the best, >> >> Tim >> >> >>> On 7 Nov 2019, at 12:54, Matthias Leinweber <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> Hello Tim, >>> >>> thanks for your reply. I get the JaxRS Application thing wrong. I thought >>> that an application and a JaxRsResource is/can be the same. But obviously, >>> if you read the documentation correct, then not. >>> Then it also makes sense to inject the Application with @Context >>> Applicaiton app into a method. >>> I had also a misunderstanding with http and jaxrs whiteboard. I was a bit >>> confused about how you could add a Servelt to the JaxRsWhiteboard instead >>> of the HttpWhiteboard for Multi-Part file uploads. >>> I think the default app and the configuration of the default jaxrs >>> whiteboard caused some confusion for me. >>> >>> * So a JaxRsResource can but most not belong to an application? >>> * It's fine to put all your Resources into the same JaxRsWhiteboard even if >>> you could separate them? >>> >>> right? then I think, I understood the thing and i like it :) >>> >>> Best regards >>> Matthias >>> >>> Am Do., 7. Nov. 2019 um 13:24 Uhr schrieb Tim Ward <[email protected] >>> <mailto:[email protected]>>: >>>> in OSGI 6 I think we should be able to use >>>> @Component(property = {"osgi.jaxrs.name <http://osgi.jaxrs.name/>=myApp", >>>> "osgi.jaxrs.application.base=/foo"}, service = A.class) >>>> class... >>>> That does not work or did I misunderstood something? >>> >>> If you want to register an application with the whiteboard then you must >>> register it as a javax.ws.rs <http://javax.ws.rs/>.core.Application in the >>> service registry. This is outlined at >>> https://osgi.org/specification/osgi.cmpou >>> cann/7.0.0/service.jaxrs.html#service.jaxrs.application.services >>> <https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#service.jaxrs.application.services> >>> >>>> Second how do i create additional Servlets and how do I select them in a >>>> resource? >>>> E.g. A configfile/servicepid >>>> org.apache.aries.jax.rs.whiteboard-bar.cfg >>>> application.base.prefix=/bar >>>> should create an additional servlet container? >>> >>> I’m not sure that I totally follow here. It looks like you’re trying to >>> create a configuration for another Aries JAX-RS whitboard instance - is >>> this really what you want, a second JAX-RS whiteboard? The Aries JAX-RS >>> Whiteboard is designed to build on top of a compliant Http Whiteboard, if >>> you are actually trying to create another Http Whiteboard (e.g. to get HTTP >>> served on another port) then you will need to set that up in PAX-Web. >>> >>>> Then with >>>> @JaxrsWhiteboardTarget >>>> or >>>> "osgi.jaxrs.whiteboard.target=" >>>> >>>> I can select the servlet/Whiteboard, but how does the LDAP string look? >>>> (service.pid=org.apache.aries.jax.rs.whiteboard-bar)? >>> >>> This property only applies if you create more than one JAX-RS whiteboard, >>> and would be applied to your JAX-RS Whiteboard services (resources, >>> applications, extensions), and you would use the filter to select the >>> JAX-RS Whiteboard that you wanted them to use. If you do want to do this, >>> which seems unlikely, then you would typically add a marker property into >>> the configuration for your JAX-RS Whiteboard and then use that property >>> name/value in the filter. >>> >>> >>> Any questions that relate to setting up the Http Whiteboard will need to be >>> handled by someone with more PAX-Web experience. I would also recommend >>> that, in addition to describing the problems that you’ve encountered, you >>> include a description of what you’re trying to achieve with your system. >>> >>> E.g. >>> >>> Do you want multiple Http ports being served (this would be Http Whiteboard >>> not JAX-RS Whiteboard)? >>> Do you want JAX-RS Whiteboard support on top of one or more of the >>> available Http Whiteboards)? >>> Do you want to publish JAX-RS resource services, application services, or a >>> mixture of the two? >>> Do you want the JAX-RS services that you publish to appear on all >>> whiteboards, or just a subset? >>> >>> With this information it will be much easier to help you to achieve your >>> goal. >>> >>> All the best, >>> >>> Tim >>> >>>> On 6 Nov 2019, at 17:25, Matthias Leinweber <[email protected] >>>> <mailto:[email protected]>> wrote: >>>> >>>> Hi JB, >>>> yes that was my first place to start... really like the examples in the >>>> source, they are really helpful. >>>> >>>> ok: >>>> Fist thing are JAXRs Applications. In OSGI7 we will use >>>> @JaxrsName("myApp") >>>> @JaxrsApplicationBase("foo") >>>> @Component >>>> class.... >>>> >>>> in OSGI 6 I think we should be able to use >>>> @Component(property = {"osgi.jaxrs.name <http://osgi.jaxrs.name/>=myApp", >>>> "osgi.jaxrs.application.base=/foo"}, service = A.class) >>>> class... >>>> That does not work or did I misunderstood something? >>>> >>>> Second how do i create additional Servlets and how do I select them in a >>>> resource? >>>> E.g. A configfile/servicepid >>>> org.apache.aries.jax.rs.whiteboard-bar.cfg >>>> application.base.prefix=/bar >>>> should create an additional servlet container? >>>> >>>> Then with >>>> @JaxrsWhiteboardTarget >>>> or >>>> "osgi.jaxrs.whiteboard.target=" >>>> >>>> I can select the servlet/Whiteboard, but how does the LDAP string look? >>>> (service.pid=org.apache.aries.jax.rs.whiteboard-bar)? >>>> >>>> Best regards, >>>> Matthias >>>> >>>> >>>> Am Mi., 6. Nov. 2019 um 18:00 Uhr schrieb Jean-Baptiste Onofré >>>> <[email protected] <mailto:[email protected]>>: >>>> Hi Matthias, >>>> >>>> did you take a look on the Karaf example ? >>>> >>>> https://github.com/apache/karaf/tree/master/examples/karaf-rest-example >>>> <https://github.com/apache/karaf/tree/master/examples/karaf-rest-example> >>>> >>>> It contains different approaches, including whiteboard. >>>> >>>> Can you describe a bit what you are looking for ? We can then create the >>>> Jira at Karaf/Aries to improve example/documentation. >>>> >>>> Regards >>>> JB >>>> >>>> On 06/11/2019 17:56, Matthias Leinweber wrote: >>>> > Hello Karaf Team, >>>> > >>>> > I know that this not the 100% correct mailing list for aries jax-rs. >>>> > However my question is what do you plan for further releases of Karaf? I >>>> > try to use the aries implementation but I struggle with the >>>> > configuration. >>>> > Beside the incomplete documentation and the "very special" DSL which is >>>> > used I dug into the code and understood the following things. >>>> > >>>> > * You can not add additional JAXRSApplications. ("osgi.jaxrs.name >>>> > <http://osgi.jaxrs.name/> >>>> > <http://osgi.jaxrs.name <http://osgi.jaxrs.name/>>=myApp", >>>> > "osgi.jaxrs.application.base=/approot"} >>>> > although there is code which should do this? >>>> > * Additional configurations for other then the default servlet is not >>>> > possible although there is a service factory manager which should handle >>>> > additional configs? >>>> > * With org.apache.aries.jax.rs >>>> > <http://org.apache.aries.jax.rs/>.whiteboard.default.cfg >>>> > # application.base.prefix you can add a global url prefix to your >>>> > JaxRSResoureces. Would be nice if that could be documented somewhere. >>>> > >>>> > Don't get me wrong I do not say that the bundle is bad, but at some >>>> > point it could be easier to understand. >>>> > >>>> > regards Matthias >>>> > >>>> > >>>> >>>> -- >>>> Jean-Baptiste Onofré >>>> [email protected] <mailto:[email protected]> >>>> http://blog.nanthrax.net <http://blog.nanthrax.net/> >>>> Talend - http://www.talend.com <http://www.talend.com/> >>>> >>>> >>>> -- >>> >>> >>> >>> >> >> >> >> > > >
