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" <[email protected]>
To: "[email protected]" <[email protected]> 
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?

Reply via email to