I am using Apache Camel with Camel Cxf Component for webservices. I have 4-5 JAX-WS web-services. I want to publish these web-services using Endpoint.publish. What I am currently doing is publish these services on statrtup i.e. in WebApplicationContextInitializer. Can any one please guide me what is the best and more suitable way to publish these services on server startup? Note: I don't want to publish as I saw examples on Internet i.e.
public static void main() {
HelloWorldImpl implementor = new HelloWorldImpl();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, implementor);
}
I don't want to do this above thing to publish web-services.
Based on your question, I assume you are not using Spring. Commonly, you would configure CXF web services as part of the Spring context. Given this, you will want to use the CXF servlet transport and then publish the endpoint in a class that extends the CXF class CXFNonSpringServlet. In that class, you will need to write code similar to the following for publishing the endpoint:
@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());
// You can als use the simple frontend API to do this
ServerFactoryBean factory = new ServerFactoryBean();
factory.setBus(bus);
factory.setServiceClass(GreeterImpl.class);
factory.setAddress("/Greeter");
factory.create();
}
I retrieved this from the following link on CXF's website: