You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID" <dk...@att.com> on 2012/06/06 19:30:22 UTC
Configuring JAX-RS without Spring: specify relative address?
I've developed a handful of CXF JAX-RS services that work with Spring. I'm going to have to quickly learn about how to do it in a new service that doesn't use Spring. I've found some of the references that talk about this, although they're spread around, and not necessarily consistent.
I think I'd prefer to do as much configuration in the web.xml, as opposed to programmatic configuration. In the example on the wiki, at http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSservicesincontainerwithoutSpring , it doesn't even mention setting the server address, which in my Spring-based services set this with a relative path on the "address" property of the "jaxrs:server" element. How is the server address configured when you do it this way?
Re: Configuring JAX-RS without Spring: specify relative address?
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 07/06/12 04:24, KARR, DAVID wrote:
>> -----Original Message-----
>> From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
>> Sent: Wednesday, June 06, 2012 8:07 PM
>> To: users@cxf.apache.org
>> Subject: Re: Configuring JAX-RS without Spring: specify relative
>> address?
>>
>> I'm using a non-Spring web.xml similar to this:
>>
>>
>> <servlet>
>> <servlet-name>HelloWorld</servlet-name>
>> <servlet-
>> class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-
>> class>
>> <init-param>
>> <param-name>jaxrs.serviceClasses</param-name>
>> <param-value>
>> com.example.jaxrs.AlgorithmService
>> </param-value>
>> </init-param>
>> <init-param>
>> <param-name>jaxrs.providers</param-name>
>> <param-value>
>> com.example.jaxrs.GsonProvider
>> </param-value>
>> </init-param>
>> <init-param>
>> <param-name>jaxrs.extensions</param-name>
>> <param-value>
>> json=application/json
>> </param-value>
>> </init-param>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>HelloWorld</servlet-name>
>> <url-pattern>/servicesRest/*</url-pattern>
>> </servlet-mapping>
>
> Ah, I see. Using the url-pattern is a natural fit.
>
In addition to that you can also introduce a 'jaxrs.address' parameter
for setting the relative path (default is '/'), but I guess it's of
little use in the non-Spring case
Cheers, Sergey
>> ________________________________
>> From: "KARR, DAVID"<dk...@att.com>
>> To: "users@cxf.apache.org"<us...@cxf.apache.org>
>> Sent: Wednesday, June 6, 2012 1:30 PM
>> Subject: Configuring JAX-RS without Spring: specify relative address?
>>
>> I've developed a handful of CXF JAX-RS services that work with Spring.
>> I'm going to have to quickly learn about how to do it in a new service
>> that doesn't use Spring. I've found some of the references that talk
>> about this, although they're spread around, and not necessarily
>> consistent.
>>
>> I think I'd prefer to do as much configuration in the web.xml, as
>> opposed to programmatic configuration. In the example on the wiki, at
>> http://cxf.apache.org/docs/jaxrs-services-
>> configuration.html#JAXRSServicesConfiguration-
>> ConfiguringJAXRSservicesincontainerwithoutSpring , it doesn't even
>> mention setting the server address, which in my Spring-based services
>> set this with a relative path on the "address" property of the
>> "jaxrs:server" element. How is the server address configured when you
>> do it this way?
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
RE: Configuring JAX-RS without Spring: specify relative address?
Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
> Sent: Wednesday, June 06, 2012 8:07 PM
> To: users@cxf.apache.org
> Subject: Re: Configuring JAX-RS without Spring: specify relative
> address?
>
> I'm using a non-Spring web.xml similar to this:
>
>
> <servlet>
> <servlet-name>HelloWorld</servlet-name>
> <servlet-
> class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-
> class>
> <init-param>
> <param-name>jaxrs.serviceClasses</param-name>
> <param-value>
> com.example.jaxrs.AlgorithmService
> </param-value>
> </init-param>
> <init-param>
> <param-name>jaxrs.providers</param-name>
> <param-value>
> com.example.jaxrs.GsonProvider
> </param-value>
> </init-param>
> <init-param>
> <param-name>jaxrs.extensions</param-name>
> <param-value>
> json=application/json
> </param-value>
> </init-param>
> </servlet>
> <servlet-mapping>
> <servlet-name>HelloWorld</servlet-name>
> <url-pattern>/servicesRest/*</url-pattern>
> </servlet-mapping>
Ah, I see. Using the url-pattern is a natural fit.
> ________________________________
> From: "KARR, DAVID" <dk...@att.com>
> To: "users@cxf.apache.org" <us...@cxf.apache.org>
> Sent: Wednesday, June 6, 2012 1:30 PM
> Subject: Configuring JAX-RS without Spring: specify relative address?
>
> I've developed a handful of CXF JAX-RS services that work with Spring.
> I'm going to have to quickly learn about how to do it in a new service
> that doesn't use Spring. I've found some of the references that talk
> about this, although they're spread around, and not necessarily
> consistent.
>
> I think I'd prefer to do as much configuration in the web.xml, as
> opposed to programmatic configuration. In the example on the wiki, at
> http://cxf.apache.org/docs/jaxrs-services-
> configuration.html#JAXRSServicesConfiguration-
> ConfiguringJAXRSservicesincontainerwithoutSpring , it doesn't even
> mention setting the server address, which in my Spring-based services
> set this with a relative path on the "address" property of the
> "jaxrs:server" element. How is the server address configured when you
> do it this way?
Re: Configuring JAX-RS without Spring: specify relative address?
Posted by Ron Grabowski <ro...@yahoo.com>.
I'm using a non-Spring web.xml similar to this:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>
com.example.jaxrs.AlgorithmService
</param-value>
</init-param>
<init-param>
<param-name>jaxrs.providers</param-name>
<param-value>
com.example.jaxrs.GsonProvider
</param-value>
</init-param>
<init-param>
<param-name>jaxrs.extensions</param-name>
<param-value>
json=application/json
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servicesRest/*</url-pattern>
</servlet-mapping>
During development I have a junit test case that spins up a local Jetty server for faster testing:
public class JaxRsClientServerTest {
private static Server server = null;
private final static String serverAddress = "http://localhost:9000/";
@BeforeClass
public static void runBeforeClass() throws Exception {
ProviderFactory.getSharedInstance().registerUserProvider(new GsonProvider());
JAXRSServerFactoryBean serverFactory = new JAXRSServerFactoryBean();
serverFactory.setResourceClasses(
AlgorithmService.class
/* etc... */);
serverFactory.setAddress(serverAddress);
serverFactory.getInInterceptors().add(new LoggingInInterceptor());
serverFactory.getOutInterceptors().add(new LoggingOutInterceptor());
server = serverFactory.create();
server.start();
assertTrue(server.isStarted());
}
@AfterClass
public static void runAfterClass() {
if (server != null && server.isStarted()) {
server.stop();
assertFalse(server.isStarted());
}
}
// snip
}
Did that answer your question?
________________________________
From: "KARR, DAVID" <dk...@att.com>
To: "users@cxf.apache.org" <us...@cxf.apache.org>
Sent: Wednesday, June 6, 2012 1:30 PM
Subject: Configuring JAX-RS without Spring: specify relative address?
I've developed a handful of CXF JAX-RS services that work with Spring. I'm going to have to quickly learn about how to do it in a new service that doesn't use Spring. I've found some of the references that talk about this, although they're spread around, and not necessarily consistent.
I think I'd prefer to do as much configuration in the web.xml, as opposed to programmatic configuration. In the example on the wiki, at http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-ConfiguringJAXRSservicesincontainerwithoutSpring , it doesn't even mention setting the server address, which in my Spring-based services set this with a relative path on the "address" property of the "jaxrs:server" element. How is the server address configured when you do it this way?