Discussion:
REST app with CXF 2.4 gives Can't find request for observer error.
odyssey045
2011-06-09 17:24:46 UTC
Permalink
Hi,

I saw many users complain about a similar error with WSDL based CXF apps but
none for REST based apps and hence this question..
I am trying to get started with a simple REST based CXF and spring app. I
followed a demo and created a simple service called "categoryService" which
lists some categories and books in each category.

My beans.xml looks something like this:'


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="categoryService" address="/">
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="categoryServiceBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="categoryServiceBean"
class="com.demo.cxf.server.CategoryService"/>
</beans>

And my jaxrs.xml used by spring looks something like tis:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="categoryService" class="com.demo.cxf.server.CategoryService">
<property name="categoryDAO">
<ref bean="categoryDAO"/>
</property>
</bean>

<bean id="categoryDAO" class="com.demo.cxf.dao.CategoryDao"></bean>
</beans>


Finally my web.xml looks something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
&lt;!DOCTYPE web-app
PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
&quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/beans.xml
WEB-INF/jaxrs.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>



Is there something that i am missing over here besides the configuration
files?? When i deploy my war into tomcat 7, i get the following message:

eBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'categoryService': replacing
[Generic
bean: class
[org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser$
SpringJAXRSServerFactoryBean]; scope=; abstract=false; lazyInit=false;
autowireM
ode=0; dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName
=null; factoryMethodName=null; initMethodName=create;
destroyMethodName=null] wi
th [Generic bean: class [com.demo.cxf.server.CategoryService]; scope=;
abstract
=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=tru
e; primary=false; factoryBeanName=null; factoryMethodName=null;
initMethodName=n
ull; destroyMethodName=null; defined in ServletContext resource
[/WEB-INF/jaxrs.
xml]]


But when i try to access, something like
http://localhost:8080/jaxws/categoryservice/category/001

Tomcat just says back to me

WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryserv
ice/category/001's Observer


--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4473536.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2011-06-09 17:45:59 UTC
Permalink
Hi
Post by odyssey045
Hi,
I saw many users complain about a similar error with WSDL based CXF apps but
none for REST based apps and hence this question..
That happens for REST apps as well...

jaxrs:server/@address is "/" so an initial match should've been
successful (not sure if your root resource actually starts with /jaxws
- but that is the next stage). It appears the endpoint has not been
created at all ...

Can you get some more info from the logs ? Perhaps CategoryService is
not a valid root resource...

Cheers Sergey
Post by odyssey045
I am trying to get started with a simple REST based CXF and spring app. I
followed a demo and created a simple service called "categoryService" which
lists some categories and books in each category.
My beans.xml looks something like this:'
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
   <import resource="classpath:META-INF/cxf/cxf.xml" />
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
   <jaxrs:server id="categoryService" address="/">
       <jaxrs:features>
           <cxf:logging/>
       </jaxrs:features>
       <jaxrs:serviceBeans>
           <ref bean="categoryServiceBean" />
       </jaxrs:serviceBeans>
   </jaxrs:server>
   <bean id="categoryServiceBean"
class="com.demo.cxf.server.CategoryService"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
   <bean id="categoryService" class="com.demo.cxf.server.CategoryService">
       <property name="categoryDAO">
           <ref bean="categoryDAO"/>
           </property>
   </bean>
   <bean id="categoryDAO" class="com.demo.cxf.dao.CategoryDao"></bean>
</beans>
<?xml version="1.0" encoding="ISO-8859-1"?>
&lt;!DOCTYPE web-app
PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
<web-app>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
WEB-INF/beans.xml
WEB-INF/jaxrs.xml
       </param-value>
   </context-param>
   <listener>
       <listener-class>
org.springframework.web.context.ContextLoaderListener
       </listener-class>
   </listener>
   <servlet>
       <servlet-name>CXFServlet</servlet-name>
       <display-name>CXF Servlet</display-name>
       <servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>CXFServlet</servlet-name>
       <url-pattern>/*</url-pattern>
   </servlet-mapping>
</web-app>
Is there something that i am missing over here besides the configuration
eBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'categoryService': replacing
[Generic
bean: class
[org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser$
SpringJAXRSServerFactoryBean]; scope=; abstract=false; lazyInit=false;
autowireM
ode=0; dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName
=null; factoryMethodName=null; initMethodName=create;
destroyMethodName=null] wi
th [Generic bean: class [com.demo.cxf.server.CategoryService]; scope=;
abstract
=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=tru
e; primary=false; factoryBeanName=null; factoryMethodName=null;
initMethodName=n
ull; destroyMethodName=null; defined in ServletContext resource
[/WEB-INF/jaxrs.
xml]]
But when i try to access, something like
http://localhost:8080/jaxws/categoryservice/category/001
Tomcat just says back to me
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryserv
ice/category/001's Observer
--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4473536.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com
odyssey045
2011-06-09 18:01:07 UTC
Permalink
The /jaxws happens to be the context root of the application.

Not sure if this helps, but my simple java code goes something like this..

@Path("/categoryservice")
@Produces("application/xml")
public class CategoryService {

CategoryDao categoryDAO = null;
public CategoryDao getCategoryDAO() {
return categoryDAO;
}
//injected with spring
public void setCategoryDAO(CategoryDao categoryDAO) {
this.categoryDAO = categoryDAO;
}


@GET
@Path("/category/{id}")
@Consumes("application/xml")
public Category getCategory(@PathParam("id") String id) {
System.out.println("The id to fetch is "+id);
Category cat = (Category)getCategoryDAO().getCategory(id);
return cat;
}
....
....
/*<rest of the code continues> */

And from my tomcat logs, when the app is started

..........
..........
...........
INFO: Deploying web application archive jaxws.war
Jun 9, 2011 10:37:58 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 9, 2011 10:37:58 PM
org.springframework.context.support.AbstractApplicationContext
prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Thu Jun 09
22:37:58 IST 2011]; root of context hierarchy
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource
[/WEB-INF/beans.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf-servlet.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource
[/WEB-INF/jaxrs.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
registerBeanDefinition
INFO: Overriding bean definition for bean 'categoryService': replacing
[Generic bean: class
[org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser$SpringJAXRSServerFactoryBean];
scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=true; primary=false; factoryBeanName=null;
factoryMethodName=null; initMethodName=create; destroyMethodName=null] with
[Generic bean: class [com.cisco.cxf.server.CategoryService]; scope=;
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=true; primary=false; factoryBeanName=null;
factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined
in ServletContext resource [/WEB-INF/jaxrs.xml]]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
preInstantiateSingletons
INFO: Pre-instantiating singletons in
***@691dee:
defining beans
[cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,categoryService,categoryServiceBean,categoryDAO];
root of factory hierarchy
Jun 9, 2011 10:37:58 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 750 ms
........
........


And when i try to access a resource, this is all i get in my tomcat logs..


Jun 9, 2011 10:38:28 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001's Observer
Jun 9, 2011 10:58:50 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001's Observer
Jun 9, 2011 10:59:08 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001/books's Observer


Sorry if my question seems dumb, but is there a way by which i can ensure
the service endpoint is created?

--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4473635.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2011-06-09 21:17:49 UTC
Permalink
You should see something like:

09-Jun-2011 22:14:37 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be /

Try also check the services list from the browser:
http://localhost:8080/jaxws/services

Cheers, Sergey
Post by odyssey045
The /jaxws happens to be the context root of the application.
Not sure if this helps, but my simple java code goes something like this..
@Path("/categoryservice")
@Produces("application/xml")
public class CategoryService {
   CategoryDao categoryDAO = null;
   public CategoryDao getCategoryDAO() {
       return categoryDAO;
   }
   //injected with spring
   public void setCategoryDAO(CategoryDao categoryDAO) {
       this.categoryDAO = categoryDAO;
   }
       System.out.println("The id to fetch is "+id);
       Category cat = (Category)getCategoryDAO().getCategory(id);
       return cat;
   }
....
....
/*<rest of the code continues> */
And from my tomcat logs, when the app is started
..........
..........
...........
INFO: Deploying web application archive jaxws.war
Jun 9, 2011 10:37:58 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 9, 2011 10:37:58 PM
org.springframework.context.support.AbstractApplicationContext
prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Thu Jun 09
22:37:58 IST 2011]; root of context hierarchy
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource
[/WEB-INF/beans.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf-servlet.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource
[/WEB-INF/jaxrs.xml]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
registerBeanDefinition
INFO: Overriding bean definition for bean 'categoryService': replacing
[Generic bean: class
[org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser$SpringJAXRSServerFactoryBean];
scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=true; primary=false; factoryBeanName=null;
factoryMethodName=null; initMethodName=create; destroyMethodName=null] with
[Generic bean: class [com.cisco.cxf.server.CategoryService]; scope=;
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
autowireCandidate=true; primary=false; factoryBeanName=null;
factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined
in ServletContext resource [/WEB-INF/jaxrs.xml]]
Jun 9, 2011 10:37:58 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
preInstantiateSingletons
INFO: Pre-instantiating singletons in
defining beans
[cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,categoryService,categoryServiceBean,categoryDAO];
root of factory hierarchy
Jun 9, 2011 10:37:58 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 750 ms
........
........
And when i try to access a resource, this is all i get in my tomcat logs..
Jun 9, 2011 10:38:28 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001's Observer
Jun 9, 2011 10:58:50 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001's Observer
Jun 9, 2011 10:59:08 PM org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the the request for
http://localhost:8080/jaxws/categoryservice/category/001/books's Observer
Sorry if my question seems dumb, but is there a way by which i can ensure
the service endpoint is created?
--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4473635.html
Sent from the cxf-user mailing list archive at Nabble.com.
odyssey045
2011-06-10 11:40:14 UTC
Permalink
Thanks! There was a typo in the book that was carried on without knowing the
significance of the error.. I am able to get a handle to the request now.. I
do have another error, which i will post in a separate post.

--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4475908.html
Sent from the cxf-user mailing list archive at Nabble.com.
Muller, Anthony
2011-06-10 13:45:25 UTC
Permalink
Hello,

I have quite basic questions about JAX-RS support in CXF (2.3.3) :

- If you look at servlet code and web.xml descriptor bellow, is it the good way to expose a REST ws (without using spring)
- How to remove "sf.setAddress("http://localhost:8080/")" ? => I don't know what will be the port number of the app server where my webapp will be deployed
- How to remove useless <init-param> for serviceClasses without runtime exception

Thanks and regards,
Anthony



Servlet code:

public class MyServlet extends CXFNonSpringJaxrsServlet {

public MyServlet() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setTransportId("http://cxf.apache.org/transports/http");
sf.setResourceClasses(MyResource.class);
sf.setResourceProvider(MyResource.class, new SingletonResourceProvider(new MyResource()));
sf.setAddress("http://localhost:8080/");
sf.create();
}
}

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com .... MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>com ... MyResource</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name> MyServlet </servlet-name>
<url-pattern>/MyResource/*</url-pattern>
</servlet-mapping>
</web-app>
Sergey Beryozkin
2011-06-10 15:01:38 UTC
Permalink
Hi
Post by Muller, Anthony
Hello,
- If you look at servlet code and web.xml descriptor bellow, is it the good way to expose a REST ws (without using spring)
The code which is currently in MyServlet is usually used only when
creating standalone JAX-RS endpoints, backed up by embedded Jetty - in
such cases absolute URIs have to specified.
I'd recommend using CXFNonSpringJaxrsServlet directly, unless you need
to customize the way CXFNonSpringJaxrsServlet handles its init().
Post by Muller, Anthony
- How to remove "sf.setAddress("http://localhost:8080/")" ? => I don't know what will be the port number of the app server where my webapp will be deployed
I think you do not need that code at all
Post by Muller, Anthony
- How to remove useless <init-param> for serviceClasses without runtime exception
At the moment MyServlet does not really override
CXFNonSpringJaxrsServlet but rather proceeds with creating endpoints
on its own, thus a possible conflict, given that
CXFNonSpringJaxrsServlet does expect this parameter.
Consider removing MyServlet.

Hope it helps
Sergey
Post by Muller, Anthony
Thanks and regards,
Anthony
public class MyServlet extends CXFNonSpringJaxrsServlet {
       public MyServlet() {
       JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
       sf.setTransportId("http://cxf.apache.org/transports/http");
       sf.setResourceClasses(MyResource.class);
       sf.setResourceProvider(MyResource.class, new SingletonResourceProvider(new MyResource()));
       sf.setAddress("http://localhost:8080/");
       sf.create();
       }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
 <servlet>
   <servlet-name>MyServlet</servlet-name>
   <servlet-class>com .... MyServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
       <init-param>
               <param-name>jaxrs.serviceClasses</param-name>
               <param-value>com ... MyResource</param-value>
       </init-param>
 </servlet>
 <servlet-mapping>
   <servlet-name> MyServlet </servlet-name>
   <url-pattern>/MyResource/*</url-pattern>
 </servlet-mapping>
</web-app>
--
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com
Muller, Anthony
2011-06-10 15:59:04 UTC
Permalink
Ok, I think I understand!

Thanks Sergey,
Anthony

-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozkin-***@public.gmane.org]
Sent: vendredi 10 juin 2011 17:02
To: users-qJ/***@public.gmane.org
Subject: Re: CXFNonSpringJaxrsServlet and JAX-RS questions

Hi
Post by Muller, Anthony
Hello,
- If you look at servlet code and web.xml descriptor bellow, is it the good way to expose a REST ws (without using spring)
The code which is currently in MyServlet is usually used only when
creating standalone JAX-RS endpoints, backed up by embedded Jetty - in
such cases absolute URIs have to specified.
I'd recommend using CXFNonSpringJaxrsServlet directly, unless you need
to customize the way CXFNonSpringJaxrsServlet handles its init().
Post by Muller, Anthony
- How to remove "sf.setAddress("http://localhost:8080/")" ? => I don't know what will be the port number of the app server where my webapp will be deployed
I think you do not need that code at all
Post by Muller, Anthony
- How to remove useless <init-param> for serviceClasses without runtime exception
At the moment MyServlet does not really override
CXFNonSpringJaxrsServlet but rather proceeds with creating endpoints
on its own, thus a possible conflict, given that
CXFNonSpringJaxrsServlet does expect this parameter.
Consider removing MyServlet.

Hope it helps
Sergey
Post by Muller, Anthony
Thanks and regards,
Anthony
public class MyServlet extends CXFNonSpringJaxrsServlet {
       public MyServlet() {
       JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
       sf.setTransportId("http://cxf.apache.org/transports/http");
       sf.setResourceClasses(MyResource.class);
       sf.setResourceProvider(MyResource.class, new SingletonResourceProvider(new MyResource()));
       sf.setAddress("http://localhost:8080/");
       sf.create();
       }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
 <servlet>
   <servlet-name>MyServlet</servlet-name>
   <servlet-class>com .... MyServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
       <init-param>
               <param-name>jaxrs.serviceClasses</param-name>
               <param-value>com ... MyResource</param-value>
       </init-param>
 </servlet>
 <servlet-mapping>
   <servlet-name> MyServlet </servlet-name>
   <url-pattern>/MyResource/*</url-pattern>
 </servlet-mapping>
</web-app>
--
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com
odyssey045
2011-06-10 11:40:16 UTC
Permalink
Thanks! There was a typo in the book that was carried on without knowing the
significance of the error.. I am able to get a handle to the request now.. I
do have another error, which i will post in a separate post.

--
View this message in context: http://cxf.547215.n5.nabble.com/REST-app-with-CXF-2-4-gives-Can-t-find-request-for-observer-error-tp4473536p4475909.html
Sent from the cxf-user mailing list archive at Nabble.com.
Loading...