Hi Rice,
On 02/03/12 09:31, Rice Yeh wrote:
Hi,
   I am moving my project to OSGi environment. My project uses JAXRS with
CXFServlet, so I can have many servlets (one of them is mapped path '/s1')
in a servlet context (with context path '/c') with many JAXRS root resource
classes (with @Path "r1", "r2", etc.). When accessing a resource, the url
is like http://localhost:8080/c/s1/r1. How do I move this common address
mapping mechanism to an OSGi environment? From the example in
http://www.liquid-reality.de/display/liquid/2011/12/22/Karaf+Tutorial+Part+4+-+CXF+Services+in+OSGi,
it seems that I cannot have multiple servlets? And the only servlet
registered to HttpService represents the CXF. The jaxrs:sever as shown in
the following directly represents the root resource class and hence can
have only one serviceBean.

     <jaxrs:server address="/person" id="personService">
         <jaxrs:serviceBeans>
             <ref component-id="personServiceImpl" />
         </jaxrs:serviceBeans>
     </jaxrs:server>

Let me start from this one, the above represents an individual endpoint in CXF terms, so you can have as many endpoints as you like, but also with every endpoint referencing as many root resources as needed, ex

<jaxrs:server address="/s1" id="s1">
     <jaxrs:serviceBeans>
              <!-- links to the root resource with @Path("r1") -->
              <ref component-id="r1" />
              <!-- links to the root resource with @Path("r2") -->
              <ref component-id="r1" />
     </jaxrs:serviceBeans>
<jaxrs:server

<jaxrs:server address="/s2" id="s2">
     <jaxrs:serviceBeans>
              <!-- links to the root resource with @Path("r1") -->
              <ref component-id="r1" />
              <!-- links to the root resource with @Path("r2") -->
              <ref component-id="r1" />
     </jaxrs:serviceBeans>
<jaxrs:server

This should cover the s1/r1, s1/r2, s2/r1, s2/r2, etc.

About the context part...Yes, the default servlet handler registered with HTTP service can cover a single context, say "/c1".

I think if you need /c1/, /c2/, etc supported then you do need to use web.xml as usual but create a web app bundle (war) as opposed to the regular bundle packaged as a jar but with only the beans.xml included. JB explained me how to do it the other day, and I used a web app bundle in the jaxrs_jaxws_transformations demo in the Talend distro, where multiple context paths are also provided....

I'm also planning to introduce an activator specific to the JAX-RS frontend which will listen for custom JAX-RS applications - that should offer another option for dealing with multiple contexts...

Cheers, Sergey


>


Rice

Reply via email to