You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by chengy <ch...@yahoo.com.cn> on 2010/05/30 16:32:59 UTC
Configuring JAX-RS services in container with Spring configuration
file...
I
followed:http://cxf.apache.org/docs/jax-rs.html#JAX-RS-ConfiguringJAXRSservicesincontainerwithSpringconfigurationfile
--------------------------------------------------------------------------------
<jaxrs:server id="customerService" address="/s" >
<jaxrs:serviceBeans>
<ref bean="customerBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
@Path("/customerservice/")
public class CustomerService {
@GET
@Path("/customers/{id}/")
public Customer getCustomer(@PathParam("id") String id) {
System.out.println("----invoking getCustomer, Customer id is: " +
id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
return c;
}
-----------------------------------------------------------------------------
tomcat start info:
-----------------------------------------------------------------------------
2010-5-30 22:08:42 org.apache.cxf.endpoint.ServerImpl initDestination
Setting the server's publish address to be /s
-----------------------------------------------------------------------------
But when I execute the url
"http://localhost:8088/rsproject/s/customerservice/customers/123/" in
browser,tomcat print a warn message:
Can't find the request for
http://localhost:8088/rsproject/s/customerservice/customers/123/'s Observer
any suggestions?
--
View this message in context: http://old.nabble.com/Configuring-JAX-RS-services-in-container-with-Spring-configuration-file...-tp28722375p28722375.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Configuring JAX-RS services in container with Spring
configuration file...
Posted by chengy <ch...@yahoo.com.cn>.
I find there are 2 instance of ServletTransportFactory,why??
--
View this message in context: http://old.nabble.com/Configuring-JAX-RS-services-in-container-with-Spring-configuration-file...-tp28722375p28726884.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Configuring JAX-RS services in container with Spring
configuration file...
Posted by chengy <ch...@yahoo.com.cn>.
<!-- do not use import statements if CXFServlet init parameters link to
this 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" />
!!!
--
View this message in context: http://old.nabble.com/Configuring-JAX-RS-services-in-container-with-Spring-configuration-file...-tp28722375p28727100.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Configuring JAX-RS services in container with Spring
configuration file...
Posted by chengy <ch...@yahoo.com.cn>.
I think this may be a bug,has anybody get through the container sping rs
service?? I just follow the example,tomcat is 6.0.20,cxf is 2.2.5:
web.xml:
------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<init-param>
<param-name>config-location</param-name>
<param-value>/WEB-INF/beans.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
----------------------------------------------------------------------------------------
beans.xml:
---------------------------------------------------------------------------------------
<?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"
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">
<!-- do not use import statements if CXFServlet init parameters link to
this 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" />
<jaxrs:server id="customerService" address="/service1">
<jaxrs:serviceBeans>
<ref bean="customerBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
</beans>
------------------------------------------------------------------------------------------
CustomerService.java:
------------------------------------------------------------------------------------------
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package demo.jaxrs.server;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/customerservice/")
public class CustomerService {
long currentId = 123;
Map<Long, Customer> customers = new HashMap<Long, Customer>();
public CustomerService() {
init();
}
@GET
@Path("/customers/{id}/")
public Customer getCustomer(@PathParam("id") String id) {
System.out.println("----invoking getCustomer, Customer id is: " +
id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
return c;
}
@PUT
@Path("/customers/")
public Response updateCustomer(Customer customer) {
System.out.println("----invoking updateCustomer, Customer name is: "
+ customer.getName());
Customer c = customers.get(customer.getId());
Response r;
if (c != null) {
customers.put(customer.getId(), customer);
r = Response.ok().build();
} else {
r = Response.notModified().build();
}
return r;
}
@POST
@Path("/customers/")
public Response addCustomer(Customer customer) {
System.out.println("----invoking addCustomer, Customer name is: " +
customer.getName());
customer.setId(++currentId);
customers.put(customer.getId(), customer);
return Response.ok(customer).build();
}
@DELETE
@Path("/customers/{id}/")
public Response deleteCustomer(@PathParam("id") String id) {
System.out.println("----invoking deleteCustomer, Customer id is: " +
id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
Response r;
if (c != null) {
r = Response.ok().build();
customers.remove(idNumber);
} else {
r = Response.notModified().build();
}
return r;
}
final void init() {
Customer c = new Customer();
c.setName("John");
c.setId(123);
customers.put(c.getId(), c);
}
}
------------------------------------------------------------------------------------
Customer.java
------------------------------------------------------------------------------------
package demo.jaxrs.server;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Customer")
public class Customer {
private long id;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
--
View this message in context: http://old.nabble.com/Configuring-JAX-RS-services-in-container-with-Spring-configuration-file...-tp28722375p28726826.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Configuring JAX-RS services in container with Spring
configuration file...
Posted by Sergey Beryozkin <sb...@gmail.com>.
It all looks ok...Providing some more information may help. CXF &
tomcat versions, how does web.xml look like.
It does look like that the endpoint has not been actually published
successfully or may be CustomerService has not been recognized as a JAXRS
resource due to the fact JAXRS annotations are not visible for whatever
reasons
cheers, Sergey
On Sun, May 30, 2010 at 4:42 PM, KARR, DAVID (ATTSI) <dk...@att.com> wrote:
> > -----Original Message-----
> > From: chengy [mailto:chy108.2007@yahoo.com.cn]
> > Sent: Sunday, May 30, 2010 7:33 AM
> > To: users@cxf.apache.org
> > Subject: Configuring JAX-RS services in container with Spring
> > configuration file...
> >
> >
> > I
> > followed:http://cxf.apache.org/docs/jax-rs.html#JAX-RS-
> > ConfiguringJAXRSservicesincontainerwithSpringconfigurationfile
> >
> -----------------------------------------------------------------------
> > ---------
> > <jaxrs:server id="customerService" address="/s" >
> > <jaxrs:serviceBeans>
> > <ref bean="customerBean" />
> > </jaxrs:serviceBeans>
> > </jaxrs:server>
> >
> > <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
> >
> > @Path("/customerservice/")
> > public class CustomerService {
> >
> > @GET
> > @Path("/customers/{id}/")
> > public Customer getCustomer(@PathParam("id") String id) {
> > System.out.println("----invoking getCustomer, Customer id is:
> "
> > +
> > id);
> > long idNumber = Long.parseLong(id);
> > Customer c = customers.get(idNumber);
> > return c;
> > }
> >
> -----------------------------------------------------------------------
> > ------
> >
> > tomcat start info:
> >
> -----------------------------------------------------------------------
> > ------
> > 2010-5-30 22:08:42 org.apache.cxf.endpoint.ServerImpl initDestination
> > Setting the server's publish address to be /s
> >
> -----------------------------------------------------------------------
> > ------
> > But when I execute the url
> > "http://localhost:8088/rsproject/s/customerservice/customers/123/" in
> > browser,tomcat print a warn message:
> > Can't find the request for
> > http://localhost:8088/rsproject/s/customerservice/customers/123/'s
> > Observer
>
> Try removing the trailing slash on all the path specifications. For
> instance, '@Path("/customerservice")'.
>
> It might have been useful if you had use SoapUI to read your WADL file
> and build a test framework. I believe you would have seen it generate
> sample urls with "//", which might have given you a clue to what the
> problem was.
>
>
RE: Configuring JAX-RS services in container with Spring configuration file...
Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
> -----Original Message-----
> From: chengy [mailto:chy108.2007@yahoo.com.cn]
> Sent: Sunday, May 30, 2010 7:33 AM
> To: users@cxf.apache.org
> Subject: Configuring JAX-RS services in container with Spring
> configuration file...
>
>
> I
> followed:http://cxf.apache.org/docs/jax-rs.html#JAX-RS-
> ConfiguringJAXRSservicesincontainerwithSpringconfigurationfile
>
-----------------------------------------------------------------------
> ---------
> <jaxrs:server id="customerService" address="/s" >
> <jaxrs:serviceBeans>
> <ref bean="customerBean" />
> </jaxrs:serviceBeans>
> </jaxrs:server>
>
> <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
>
> @Path("/customerservice/")
> public class CustomerService {
>
> @GET
> @Path("/customers/{id}/")
> public Customer getCustomer(@PathParam("id") String id) {
> System.out.println("----invoking getCustomer, Customer id is:
"
> +
> id);
> long idNumber = Long.parseLong(id);
> Customer c = customers.get(idNumber);
> return c;
> }
>
-----------------------------------------------------------------------
> ------
>
> tomcat start info:
>
-----------------------------------------------------------------------
> ------
> 2010-5-30 22:08:42 org.apache.cxf.endpoint.ServerImpl initDestination
> Setting the server's publish address to be /s
>
-----------------------------------------------------------------------
> ------
> But when I execute the url
> "http://localhost:8088/rsproject/s/customerservice/customers/123/" in
> browser,tomcat print a warn message:
> Can't find the request for
> http://localhost:8088/rsproject/s/customerservice/customers/123/'s
> Observer
Try removing the trailing slash on all the path specifications. For
instance, '@Path("/customerservice")'.
It might have been useful if you had use SoapUI to read your WADL file
and build a test framework. I believe you would have seen it generate
sample urls with "//", which might have given you a clue to what the
problem was.