THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||
---|---|---|---|---|
| ||||
// cxf is the instance of the CXFServlet, you could also get this instance by extending the CXFServlet
Bus bus = cxf.getBus();
BusFactory.setDefaultBus(bus);
Endpoint.publish("/Greeter", new GreeterImpl());
|
The one thing you must ensure is that your CXFServlet is set up to listen on that path. Otherwise the CXFServlet will never receive the requests.
Using the servlet transport without Spring
Some user who don't want to touch any Spring stuff could also publish the endpoint with CXF servlet transport. First you should extends the CXFNonSpringServlet and override the method loadBus which below codes:
Code Block | ||||
---|---|---|---|---|
| ||||
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException {
super.loadBus(servletConfig);
// You could add the endpoint publish codes here
Bus bus = cxf.getBus();
BusFactory.setDefaultBus(bus);
Endpoint.publish("/Greeter", new GreeterImpl());
}
|
If you are using the Jetty as the embedded servlet engine, you could publish endpoint like this:
Code Block | ||||
---|---|---|---|---|
| ||||
// Setup the system properties to use the CXFBusFactory not the SpringBusFactory
String busFactory = System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, "org.apache.cxf.bus.CXFBusFactory");
try {
// Start up the jetty embedded server
httpServer = new Server(9000);
ContextHandlerCollection contexts = new ContextHandlerCollection();
httpServer.setHandler(contexts);
Context root = new Context(contexts, "/", Context.SESSIONS);
CXFNonSpringServlet cxf = new CXFNonSpringServlet();
ServletHolder servlet = new ServletHolder(cxf);
servlet.setName("soap");
servlet.setForcedPath("soap");
root.addServlet(servlet, "/soap/*");
httpServer.start();
Bus bus = cxf.getBus();
setBus(bus);
BusFactory.setDefaultBus(bus);
GreeterImpl impl = new GreeterImpl();
Endpoint.publish("/Greeter", impl);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// clean up the system properties
if (busFactory != null) {
System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, busFactory);
} else {
System.clearProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
}
}
|
Accessing the MessageContext and/or HTTP Request and Response
...