Reputation: 1387
How to deploy CXF SOAP web service on tomcat instead of jetty server
if i try to use tomcat port to run ServerFactoryBean
it is showing an error:
port already running.
Is there any way to use tomcat instead of in-build jetty server?
Following is my code that i am trying to create a Server.
SoapBindingFactory bindingFactory = new SoapBindingFactory();
Bus bus = BusFactory.newInstance().createBus();
bindingFactory.setBus(bus);
bus.getExtension(BindingFactoryManager.class).registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bindingFactory);
bus.getExtension(BindingFactoryManager.class).registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/http", bindingFactory);
Service service = new WSDLServiceFactory(bus, "wsdl path here", null).create();
ServerFactoryBean serverFactory = new ServerFactoryBean();
serverFactory.setBus(bus);
InboundRMHttpInvoker invoker = new InboundRMHttpInvoker(serviceImpl);
serverFactory.setInvoker(invoker);
serverFactory.setServiceBean(serviceImpl);
serverFactory.setDataBinding(service.getDataBinding());
serverFactory.setServiceName(service.getName());
serverFactory.setBindingId(service.getServiceInfos().get(0).getBindings().iterator().next().getBindingId());
serverFactory.setWsdlLocation("wsdl path");
serverFactory.setEndpointName(service.getServiceInfos().iterator().next().getEndpoints().iterator().next().getName());
serverFactory.setAddress("http://localhost:8080/services/sampleservice");
Server server = serverFactory.create();
If I use another port (other than tomcat) then it deploy my service on that port but how to run it on tomcat port.
Upvotes: 0
Views: 488
Reputation: 112
You can consider developing your application with Spring Boot or similar. When you deploy the war in the application container (eg tomcat), the ports configured in the container will be used.
Update
@SpringBootApplication
public class AwesomeApp extends SpringBootServletInitializer {
public static void main(String[] args) {
new SpringApplicationBuilder(AwesomeApp.class)
.run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(AwesomeApp.class);
}
}
@Configuration
class.@Configuration
public class ServletConfig implements WebMvcConfigurer {
public ServletRegistrationBean<CXFServlet> cxfServletRegistration() {
ServletRegistrationBean<CXFServlet> bean = new ServletRegistrationBean<>(
new CXFServlet(), "/services/*");
bean.setLoadOnStartup(1);
return bean;
}
}
Implements the service.
Configure the Endpoint in @Configuration
class and register the implementation.
@Configuration
public class IntegrationConfig {
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean(name = "awesomeServiceImpl")
public AwesomeServiceImpl awesomeServiceImpl() {
return new AwesomeServiceImpl();
}
@Bean
public Endpoint awesomeEndpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), awesomeServiceImpl());
endpoint.publish("/awesomeService");
return endpoint;
}
}
/services/awesomeService
.Upvotes: 1