You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Rice Yeh <ri...@gmail.com> on 2012/03/02 10:31:28 UTC

Multiple servlets in JAXRS+OSGi+blueprint

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>

Rice

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Rice
On 03/03/12 09:25, Rice Yeh wrote:
> Hi,
>    Finally, I realise that the stuff to hookup servlet is done on extension
> of pax-web. It is done by the feature cxf-war-java5 feature in
> http://repo1.maven.org/maven2/org/apache/cxf/karaf/apache-cxf/2.5.2/apache-cxf-2.5.2-features.xml
> .
>
Indeed, sorry I did not mention that.
As for the cxf-jaxrs feature, I was looking at the trunk:
http://svn.apache.org/repos/asf/cxf/trunk/osgi/karaf/features/src/main/resources/features.xml

I think the front-end specific activator will be really handy for 
dealing with multiple JAX-RS applications,

Thanks, Sergey

> Rice
>

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Rice Yeh <ri...@gmail.com>.
Hi,
  Finally, I realise that the stuff to hookup servlet is done on extension
of pax-web. It is done by the feature cxf-war-java5 feature in
http://repo1.maven.org/maven2/org/apache/cxf/karaf/apache-cxf/2.5.2/apache-cxf-2.5.2-features.xml
.

Rice

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Rice Yeh <ri...@gmail.com>.
Hi Sergey,

Let me explain my first problem more clearer as inlined below.

On Sat, Mar 3, 2012 at 1:33 AM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi Rice
>
> On 02/03/12 16:47, Rice Yeh wrote:
>
>> Hi Sergey,
>>   After looking into the source code in cxf, I find  a lot of classes for
>> OSGi are added in cxf now. I know there is a osgiservlet in
>> cxf-rf-transports-http and run in Karaf, it seems that it is constructed
>> but it is not added to the http service. Do you know where the code is for
>> adding osgiservlet to http service?
>>
>
> It's activated by Blueprint finding the resource in OSGI-INF in
> cxf-rt-transports-http; you can view it as a default CXF servlet and if a
> single context will do for then you can rely on it...
>
>

>
After installing cxf feature from repository
mvn:org.apache.cxf.karaf/apache-cxf/2.5.2/xml/features, I can access
http://localhost:8080/cxf. On the other hand, if I just add
cxf-bundle-jaxrs-2.5.2.jar bundle, I cannot access http://localhost:8080/cxf.
For cxf feature, karaf ls command shows me the following services:

Apache CXF Bundle Jar (133) provides:
-------------------------------------
org.osgi.service.cm.ManagedServiceFactory
org.osgi.service.cm.ManagedService
org.osgi.service.cm.ManagedService
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
javax.servlet.Servlet
javax.servlet.ServletContext
org.apache.aries.blueprint.NamespaceHandler
org.apache.aries.blueprint.NamespaceHandler
org.apache.cxf.transport.http.DestinationRegistry
org.osgi.service.blueprint.container.BlueprintContainer

For the cxf-bundle-jaxrs-2.5.2.jar, ls command gives me the following
services:

Apache CXF JAX-RS Bundle Jar (111) provides:
--------------------------------------------
org.osgi.service.cm.ManagedServiceFactory
org.osgi.service.cm.ManagedService
org.osgi.service.cm.ManagedService
org.apache.aries.blueprint.NamespaceHandler
org.apache.cxf.transport.http.DestinationRegistry
org.apache.aries.blueprint.NamespaceHandler
javax.servlet.Servlet
org.osgi.service.blueprint.container.BlueprintContainer


I think the biggest difference is the javax.servlet.ServletContext.
jaxrs-bundle has osgiservlet constructed but it is not registered to the
http service. Where is the registering done? Also, you say there is a
cxf-jaxrs feature, I cannot find in the above repository for the cxf
feature.

Rice


>
>  Also, I do not use karf feature from
>> apache cxf because it is too big in  terms of bundles included. For my
>> project, I just need jaxrs.
>>
>>  If you look at the karaf feature file, there's a cxf-jaxrs feature
> there. The cxf-jaxrs bundle can help too. I'm hoping to look into the
> better osgi-ification of the jaxrs frontend in more depth probably
> immediately after 2.6.0 (frontend specific activator, etc), though I might
> get a bit of time before the release too,
>
> Let me know please how this project goes
>
> Cheers, Sergey
>
>  Rice
>>
>>

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Rice Yeh <ri...@gmail.com>.
>
> Hi, Sergey,


> If you look at the karaf feature file, there's a cxf-jaxrs feature there.

Do you mean this repository
http://repo1.maven.org/maven2/org/apache/cxf/karaf/apache-cxf/2.5.2/apache-cxf-2.5.2-features.xml?
I cannot find a cxf-jaxrs feature.


Rice

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Rice
On 02/03/12 16:47, Rice Yeh wrote:
> Hi Sergey,
>    After looking into the source code in cxf, I find  a lot of classes for
> OSGi are added in cxf now. I know there is a osgiservlet in
> cxf-rf-transports-http and run in Karaf, it seems that it is constructed
> but it is not added to the http service. Do you know where the code is for
> adding osgiservlet to http service?

It's activated by Blueprint finding the resource in OSGI-INF in 
cxf-rt-transports-http; you can view it as a default CXF servlet and if 
a single context will do for then you can rely on it...

> Also, I do not use karf feature from
> apache cxf because it is too big in  terms of bundles included. For my
> project, I just need jaxrs.
>
If you look at the karaf feature file, there's a cxf-jaxrs feature 
there. The cxf-jaxrs bundle can help too. I'm hoping to look into the 
better osgi-ification of the jaxrs frontend in more depth probably 
immediately after 2.6.0 (frontend specific activator, etc), though I 
might get a bit of time before the release too,

Let me know please how this project goes

Cheers, Sergey

> Rice
>

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Rice Yeh <ri...@gmail.com>.
Hi Sergey,
  After looking into the source code in cxf, I find  a lot of classes for
OSGi are added in cxf now. I know there is a osgiservlet in
cxf-rf-transports-http and run in Karaf, it seems that it is constructed
but it is not added to the http service. Do you know where the code is for
adding osgiservlet to http service? Also, I do not use karf feature from
apache cxf because it is too big in  terms of bundles included. For my
project, I just need jaxrs.

Rice

Re: Multiple servlets in JAXRS+OSGi+blueprint

Posted by Sergey Beryozkin <sb...@gmail.com>.
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
>