You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Reed, Nate" <nr...@hoovers.com> on 2010/06/09 23:03:47 UTC

CXF JAX-RS with Spring-WS

Hi,

 

I'm having problems getting CXF-JAXRS to work with Spring-WS in my
project.   I was able to get a very simple "HelloResource" example
working.  In this example, I passed in beans.xml to CXF as an
init-param, but this is not a solution because in my real project I have
some beans that are shared with Spring-WS.  When I tried to get CXF to
load both in its init-param, requests for the Hello resource failed with
an error similar to below.

 

So, as an alternative approach, I am trying to get Spring
MessageDispatcherServlet to load all the beans needed by CXF, but it
still doesn't work.

 

I wonder what I'm missing?  When I make a request for my service, I see
the following log message:

 

WARNING: Can't find the request for
http://localhost:8080/HooversAPI-trunk/rest/company/1's Observer

 

I have defined a root resource as follows:

 

@Path("/company")

public class CompanyResource

                                extends

 
BaseEndPoint<GetCompanyDetailRequestDocument,
GetCompanyDetailResponseDocument> {

 

                public CompanyResource() {

                                super(logger);

                }

 

                private static final Logger logger = LoggerFactory

 
.getLogger(CompanyResource.class);

 

                @Context

                protected org.apache.cxf.jaxrs.ext.MessageContext mc;

 

                @GET

                @Path("{id}")

                @Produces("text/html")

                public GetCompanyDetailResponse echo(@PathParam("id")
long id) {

                ....

                }

 

In web.xml, I have configured Spring MessageDispatcherServlet to load
the application context from beans.xml, which defines my JAX-RS server
and imports all the beans it needs from spring-ws-servlet.xml:

 

      <servlet>

            <servlet-name>CXFServlet</servlet-name>

            <servlet-class>

                  org.apache.cxf.transport.servlet.CXFServlet

            </servlet-class>

            <load-on-startup>2</load-on-startup>

      </servlet>

 

      <servlet-mapping>

            <servlet-name>CXFServlet</servlet-name>

            <url-pattern>/rest/*</url-pattern>

      </servlet-mapping>

      

      <servlet>

            <servlet-name>spring-ws</servlet-name>

            <servlet-class>

 
org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-
class>

            <init-param>

                  <param-name>contextConfigLocation</param-name>

                  <param-value>/WEB-INF/beans.xml</param-value>

            </init-param>

            <load-on-startup>1</load-on-startup>

      </servlet>

 

      <servlet-mapping>

            <servlet-name>spring-ws</servlet-name>

            <url-pattern>/*</url-pattern>

      </servlet-mapping>

 

In beans.xml:

 

 

      <import resource="classpath:META-INF/cxf/cxf.xml"/>

      <import
resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />

      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

      <import resource="spring-ws-servlet.xml" />

      

      <bean id="helloResourceBean"
class="com.dnb.applications.webservice.resource.HelloResource"/>

      <bean id="companyResourceBean"
class="com.dnb.applications.webservice.resource.CompanyResource">

            <property name="handler" ref="companyHandler" />

      </bean>

      

      <bean id="xmlBeansProvider"
class="org.apache.cxf.jaxrs.provider.XMLBeansJSONProvider" />

 

      <bean id="xmlBeansDataBinding"
class="org.apache.cxf.xmlbeans.XmlBeansDataBinding">

            <property name="namespaceMap" ref="jsonNamespaceMap"/>

      </bean>

      

      <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">

            <entry key="http://applications.dnb.com/webservice/schema"
value="ns10"/>

            <entry key="http://www.w3.org/2001/XMLSchema-instance"
value="xsi"/>

      </util:map>

      

      <jaxrs:server id="HooversRestAPI" address="/rest"
staticSubresourceResolution="true">

            <jaxrs:serviceBeans>

                  <ref bean="companyResourceBean" />

                  <ref bean="helloResourceBean" />

            </jaxrs:serviceBeans>

            <jaxrs:providers>

                  <ref bean="xmlBeansProvider"/>

            </jaxrs:providers>

            <jaxrs:dataBinding>

                  <ref bean="xmlBeansDataBinding" />

            </jaxrs:dataBinding>

      </jaxrs:server>

 

Any ideas?  I also tried address="/" but get the same result.

 

Thanks,

Nate

 


Re: CXF JAX-RS with Spring-WS

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

sorry, really not sure how to fix it.

Is it possible in Sping to refer to the initialized application context
without it being refreshed/reinitialized ?
This way CXFServlet could point to its own beans.xml which only 'links' to
the context already created by SpringWS ?

Or may be the context used by SpringWS should be linked to through the
context parameter ?



cheers, Sergey


On Thu, Jun 10, 2010 at 3:47 PM, Reed, Nate <nr...@hoovers.com> wrote:

> Right, but if you look at the code I sent, in this case I'm not passing
> in beans.xml as an init-param to CXF but instead I'm passing it to
> Spring's MessageDispatcherServlet.  I'm letting Spring create the beans
> that CXF needs, but it seems like CXF is not getting them.
>
> Is there a way to make CXF "aware" of the beans in the application
> context created by Spring-WS?
>
> Nate
>
> -----Original Message-----
> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> Sent: Wednesday, June 09, 2010 5:17 PM
> To: users@cxf.apache.org
> Subject: Re: CXF JAX-RS with Spring-WS
>
> Hi
>
> I think one of the users had a similar problems recently. When
> CXFServlet
> links to beans.xml using its init-param, then this beans.xml should have
> no
> import statements, comment them out
>
> hope it helps, Sergey
>
> On Wed, Jun 9, 2010 at 10:03 PM, Reed, Nate <nr...@hoovers.com> wrote:
>
> > Hi,
> >
> >
> >
> > I'm having problems getting CXF-JAXRS to work with Spring-WS in my
> > project.   I was able to get a very simple "HelloResource" example
> > working.  In this example, I passed in beans.xml to CXF as an
> > init-param, but this is not a solution because in my real project I
> have
> > some beans that are shared with Spring-WS.  When I tried to get CXF to
> > load both in its init-param, requests for the Hello resource failed
> with
> > an error similar to below.
> >
> >
> >
> > So, as an alternative approach, I am trying to get Spring
> > MessageDispatcherServlet to load all the beans needed by CXF, but it
> > still doesn't work.
> >
> >
> >
> > I wonder what I'm missing?  When I make a request for my service, I
> see
> > the following log message:
> >
> >
> >
> > WARNING: Can't find the request for
> >
> http://localhost:8080/HooversAPI-trunk/rest/company/1's<http://localhost:8080/HooversAPI-trunk/rest/company/1%27s>
> <http://localhost
> :8080/HooversAPI-trunk/rest/company/1%27s>Observer
> >
> >
> >
> > I have defined a root resource as follows:
> >
> >
> >
> > @Path("/company")
> >
> > public class CompanyResource
> >
> >                                extends
> >
> >
> > BaseEndPoint<GetCompanyDetailRequestDocument,
> > GetCompanyDetailResponseDocument> {
> >
> >
> >
> >                public CompanyResource() {
> >
> >                                super(logger);
> >
> >                }
> >
> >
> >
> >                private static final Logger logger = LoggerFactory
> >
> >
> > .getLogger(CompanyResource.class);
> >
> >
> >
> >                @Context
> >
> >                protected org.apache.cxf.jaxrs.ext.MessageContext mc;
> >
> >
> >
> >                @GET
> >
> >                @Path("{id}")
> >
> >                @Produces("text/html")
> >
> >                public GetCompanyDetailResponse echo(@PathParam("id")
> > long id) {
> >
> >                ....
> >
> >                }
> >
> >
> >
> > In web.xml, I have configured Spring MessageDispatcherServlet to load
> > the application context from beans.xml, which defines my JAX-RS server
> > and imports all the beans it needs from spring-ws-servlet.xml:
> >
> >
> >
> >      <servlet>
> >
> >            <servlet-name>CXFServlet</servlet-name>
> >
> >            <servlet-class>
> >
> >                  org.apache.cxf.transport.servlet.CXFServlet
> >
> >            </servlet-class>
> >
> >            <load-on-startup>2</load-on-startup>
> >
> >      </servlet>
> >
> >
> >
> >      <servlet-mapping>
> >
> >            <servlet-name>CXFServlet</servlet-name>
> >
> >            <url-pattern>/rest/*</url-pattern>
> >
> >      </servlet-mapping>
> >
> >
> >
> >      <servlet>
> >
> >            <servlet-name>spring-ws</servlet-name>
> >
> >            <servlet-class>
> >
> >
> >
> org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-
> > class>
> >
> >            <init-param>
> >
> >                  <param-name>contextConfigLocation</param-name>
> >
> >                  <param-value>/WEB-INF/beans.xml</param-value>
> >
> >            </init-param>
> >
> >            <load-on-startup>1</load-on-startup>
> >
> >      </servlet>
> >
> >
> >
> >      <servlet-mapping>
> >
> >            <servlet-name>spring-ws</servlet-name>
> >
> >            <url-pattern>/*</url-pattern>
> >
> >      </servlet-mapping>
> >
> >
> >
> > In beans.xml:
> >
> >
> >
> >
> >
> >      <import resource="classpath:META-INF/cxf/cxf.xml"/>
> >
> >      <import
> > resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
> >
> >      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
> >
> >      <import resource="spring-ws-servlet.xml" />
> >
> >
> >
> >      <bean id="helloResourceBean"
> > class="com.dnb.applications.webservice.resource.HelloResource"/>
> >
> >      <bean id="companyResourceBean"
> > class="com.dnb.applications.webservice.resource.CompanyResource">
> >
> >            <property name="handler" ref="companyHandler" />
> >
> >      </bean>
> >
> >
> >
> >      <bean id="xmlBeansProvider"
> > class="org.apache.cxf.jaxrs.provider.XMLBeansJSONProvider" />
> >
> >
> >
> >      <bean id="xmlBeansDataBinding"
> > class="org.apache.cxf.xmlbeans.XmlBeansDataBinding">
> >
> >            <property name="namespaceMap" ref="jsonNamespaceMap"/>
> >
> >      </bean>
> >
> >
> >
> >      <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
> >
> >            <entry key="http://applications.dnb.com/webservice/schema"
> > value="ns10"/>
> >
> >            <entry key="http://www.w3.org/2001/XMLSchema-instance"
> > value="xsi"/>
> >
> >      </util:map>
> >
> >
> >
> >      <jaxrs:server id="HooversRestAPI" address="/rest"
> > staticSubresourceResolution="true">
> >
> >            <jaxrs:serviceBeans>
> >
> >                  <ref bean="companyResourceBean" />
> >
> >                  <ref bean="helloResourceBean" />
> >
> >            </jaxrs:serviceBeans>
> >
> >            <jaxrs:providers>
> >
> >                  <ref bean="xmlBeansProvider"/>
> >
> >            </jaxrs:providers>
> >
> >            <jaxrs:dataBinding>
> >
> >                  <ref bean="xmlBeansDataBinding" />
> >
> >            </jaxrs:dataBinding>
> >
> >      </jaxrs:server>
> >
> >
> >
> > Any ideas?  I also tried address="/" but get the same result.
> >
> >
> >
> > Thanks,
> >
> > Nate
> >
> >
> >
> >
>

RE: CXF JAX-RS with Spring-WS

Posted by "Reed, Nate" <nr...@hoovers.com>.
Right, but if you look at the code I sent, in this case I'm not passing
in beans.xml as an init-param to CXF but instead I'm passing it to
Spring's MessageDispatcherServlet.  I'm letting Spring create the beans
that CXF needs, but it seems like CXF is not getting them.

Is there a way to make CXF "aware" of the beans in the application
context created by Spring-WS?  

Nate

-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozkin@gmail.com] 
Sent: Wednesday, June 09, 2010 5:17 PM
To: users@cxf.apache.org
Subject: Re: CXF JAX-RS with Spring-WS

Hi

I think one of the users had a similar problems recently. When
CXFServlet
links to beans.xml using its init-param, then this beans.xml should have
no
import statements, comment them out

hope it helps, Sergey

On Wed, Jun 9, 2010 at 10:03 PM, Reed, Nate <nr...@hoovers.com> wrote:

> Hi,
>
>
>
> I'm having problems getting CXF-JAXRS to work with Spring-WS in my
> project.   I was able to get a very simple "HelloResource" example
> working.  In this example, I passed in beans.xml to CXF as an
> init-param, but this is not a solution because in my real project I
have
> some beans that are shared with Spring-WS.  When I tried to get CXF to
> load both in its init-param, requests for the Hello resource failed
with
> an error similar to below.
>
>
>
> So, as an alternative approach, I am trying to get Spring
> MessageDispatcherServlet to load all the beans needed by CXF, but it
> still doesn't work.
>
>
>
> I wonder what I'm missing?  When I make a request for my service, I
see
> the following log message:
>
>
>
> WARNING: Can't find the request for
>
http://localhost:8080/HooversAPI-trunk/rest/company/1's<http://localhost
:8080/HooversAPI-trunk/rest/company/1%27s>Observer
>
>
>
> I have defined a root resource as follows:
>
>
>
> @Path("/company")
>
> public class CompanyResource
>
>                                extends
>
>
> BaseEndPoint<GetCompanyDetailRequestDocument,
> GetCompanyDetailResponseDocument> {
>
>
>
>                public CompanyResource() {
>
>                                super(logger);
>
>                }
>
>
>
>                private static final Logger logger = LoggerFactory
>
>
> .getLogger(CompanyResource.class);
>
>
>
>                @Context
>
>                protected org.apache.cxf.jaxrs.ext.MessageContext mc;
>
>
>
>                @GET
>
>                @Path("{id}")
>
>                @Produces("text/html")
>
>                public GetCompanyDetailResponse echo(@PathParam("id")
> long id) {
>
>                ....
>
>                }
>
>
>
> In web.xml, I have configured Spring MessageDispatcherServlet to load
> the application context from beans.xml, which defines my JAX-RS server
> and imports all the beans it needs from spring-ws-servlet.xml:
>
>
>
>      <servlet>
>
>            <servlet-name>CXFServlet</servlet-name>
>
>            <servlet-class>
>
>                  org.apache.cxf.transport.servlet.CXFServlet
>
>            </servlet-class>
>
>            <load-on-startup>2</load-on-startup>
>
>      </servlet>
>
>
>
>      <servlet-mapping>
>
>            <servlet-name>CXFServlet</servlet-name>
>
>            <url-pattern>/rest/*</url-pattern>
>
>      </servlet-mapping>
>
>
>
>      <servlet>
>
>            <servlet-name>spring-ws</servlet-name>
>
>            <servlet-class>
>
>
>
org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-
> class>
>
>            <init-param>
>
>                  <param-name>contextConfigLocation</param-name>
>
>                  <param-value>/WEB-INF/beans.xml</param-value>
>
>            </init-param>
>
>            <load-on-startup>1</load-on-startup>
>
>      </servlet>
>
>
>
>      <servlet-mapping>
>
>            <servlet-name>spring-ws</servlet-name>
>
>            <url-pattern>/*</url-pattern>
>
>      </servlet-mapping>
>
>
>
> In beans.xml:
>
>
>
>
>
>      <import resource="classpath:META-INF/cxf/cxf.xml"/>
>
>      <import
> resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
>
>      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>      <import resource="spring-ws-servlet.xml" />
>
>
>
>      <bean id="helloResourceBean"
> class="com.dnb.applications.webservice.resource.HelloResource"/>
>
>      <bean id="companyResourceBean"
> class="com.dnb.applications.webservice.resource.CompanyResource">
>
>            <property name="handler" ref="companyHandler" />
>
>      </bean>
>
>
>
>      <bean id="xmlBeansProvider"
> class="org.apache.cxf.jaxrs.provider.XMLBeansJSONProvider" />
>
>
>
>      <bean id="xmlBeansDataBinding"
> class="org.apache.cxf.xmlbeans.XmlBeansDataBinding">
>
>            <property name="namespaceMap" ref="jsonNamespaceMap"/>
>
>      </bean>
>
>
>
>      <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>
>            <entry key="http://applications.dnb.com/webservice/schema"
> value="ns10"/>
>
>            <entry key="http://www.w3.org/2001/XMLSchema-instance"
> value="xsi"/>
>
>      </util:map>
>
>
>
>      <jaxrs:server id="HooversRestAPI" address="/rest"
> staticSubresourceResolution="true">
>
>            <jaxrs:serviceBeans>
>
>                  <ref bean="companyResourceBean" />
>
>                  <ref bean="helloResourceBean" />
>
>            </jaxrs:serviceBeans>
>
>            <jaxrs:providers>
>
>                  <ref bean="xmlBeansProvider"/>
>
>            </jaxrs:providers>
>
>            <jaxrs:dataBinding>
>
>                  <ref bean="xmlBeansDataBinding" />
>
>            </jaxrs:dataBinding>
>
>      </jaxrs:server>
>
>
>
> Any ideas?  I also tried address="/" but get the same result.
>
>
>
> Thanks,
>
> Nate
>
>
>
>

Re: CXF JAX-RS with Spring-WS

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I think one of the users had a similar problems recently. When CXFServlet
links to beans.xml using its init-param, then this beans.xml should have no
import statements, comment them out

hope it helps, Sergey

On Wed, Jun 9, 2010 at 10:03 PM, Reed, Nate <nr...@hoovers.com> wrote:

> Hi,
>
>
>
> I'm having problems getting CXF-JAXRS to work with Spring-WS in my
> project.   I was able to get a very simple "HelloResource" example
> working.  In this example, I passed in beans.xml to CXF as an
> init-param, but this is not a solution because in my real project I have
> some beans that are shared with Spring-WS.  When I tried to get CXF to
> load both in its init-param, requests for the Hello resource failed with
> an error similar to below.
>
>
>
> So, as an alternative approach, I am trying to get Spring
> MessageDispatcherServlet to load all the beans needed by CXF, but it
> still doesn't work.
>
>
>
> I wonder what I'm missing?  When I make a request for my service, I see
> the following log message:
>
>
>
> WARNING: Can't find the request for
> http://localhost:8080/HooversAPI-trunk/rest/company/1's<http://localhost:8080/HooversAPI-trunk/rest/company/1%27s>Observer
>
>
>
> I have defined a root resource as follows:
>
>
>
> @Path("/company")
>
> public class CompanyResource
>
>                                extends
>
>
> BaseEndPoint<GetCompanyDetailRequestDocument,
> GetCompanyDetailResponseDocument> {
>
>
>
>                public CompanyResource() {
>
>                                super(logger);
>
>                }
>
>
>
>                private static final Logger logger = LoggerFactory
>
>
> .getLogger(CompanyResource.class);
>
>
>
>                @Context
>
>                protected org.apache.cxf.jaxrs.ext.MessageContext mc;
>
>
>
>                @GET
>
>                @Path("{id}")
>
>                @Produces("text/html")
>
>                public GetCompanyDetailResponse echo(@PathParam("id")
> long id) {
>
>                ....
>
>                }
>
>
>
> In web.xml, I have configured Spring MessageDispatcherServlet to load
> the application context from beans.xml, which defines my JAX-RS server
> and imports all the beans it needs from spring-ws-servlet.xml:
>
>
>
>      <servlet>
>
>            <servlet-name>CXFServlet</servlet-name>
>
>            <servlet-class>
>
>                  org.apache.cxf.transport.servlet.CXFServlet
>
>            </servlet-class>
>
>            <load-on-startup>2</load-on-startup>
>
>      </servlet>
>
>
>
>      <servlet-mapping>
>
>            <servlet-name>CXFServlet</servlet-name>
>
>            <url-pattern>/rest/*</url-pattern>
>
>      </servlet-mapping>
>
>
>
>      <servlet>
>
>            <servlet-name>spring-ws</servlet-name>
>
>            <servlet-class>
>
>
> org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-
> class>
>
>            <init-param>
>
>                  <param-name>contextConfigLocation</param-name>
>
>                  <param-value>/WEB-INF/beans.xml</param-value>
>
>            </init-param>
>
>            <load-on-startup>1</load-on-startup>
>
>      </servlet>
>
>
>
>      <servlet-mapping>
>
>            <servlet-name>spring-ws</servlet-name>
>
>            <url-pattern>/*</url-pattern>
>
>      </servlet-mapping>
>
>
>
> In beans.xml:
>
>
>
>
>
>      <import resource="classpath:META-INF/cxf/cxf.xml"/>
>
>      <import
> resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
>
>      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>
>      <import resource="spring-ws-servlet.xml" />
>
>
>
>      <bean id="helloResourceBean"
> class="com.dnb.applications.webservice.resource.HelloResource"/>
>
>      <bean id="companyResourceBean"
> class="com.dnb.applications.webservice.resource.CompanyResource">
>
>            <property name="handler" ref="companyHandler" />
>
>      </bean>
>
>
>
>      <bean id="xmlBeansProvider"
> class="org.apache.cxf.jaxrs.provider.XMLBeansJSONProvider" />
>
>
>
>      <bean id="xmlBeansDataBinding"
> class="org.apache.cxf.xmlbeans.XmlBeansDataBinding">
>
>            <property name="namespaceMap" ref="jsonNamespaceMap"/>
>
>      </bean>
>
>
>
>      <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>
>            <entry key="http://applications.dnb.com/webservice/schema"
> value="ns10"/>
>
>            <entry key="http://www.w3.org/2001/XMLSchema-instance"
> value="xsi"/>
>
>      </util:map>
>
>
>
>      <jaxrs:server id="HooversRestAPI" address="/rest"
> staticSubresourceResolution="true">
>
>            <jaxrs:serviceBeans>
>
>                  <ref bean="companyResourceBean" />
>
>                  <ref bean="helloResourceBean" />
>
>            </jaxrs:serviceBeans>
>
>            <jaxrs:providers>
>
>                  <ref bean="xmlBeansProvider"/>
>
>            </jaxrs:providers>
>
>            <jaxrs:dataBinding>
>
>                  <ref bean="xmlBeansDataBinding" />
>
>            </jaxrs:dataBinding>
>
>      </jaxrs:server>
>
>
>
> Any ideas?  I also tried address="/" but get the same result.
>
>
>
> Thanks,
>
> Nate
>
>
>
>