Using the servlet transport without Spring - 7.3

Talend ESB Service Developer Guide

Version
7.3
Language
English
Product
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend ESB
Talend Runtime
Content
Design and Development
Installation and Upgrade
Last publication date
2023-04-17

A user who doesn't want to use the Spring libraries can alternatively publish the endpoint with CXF servlet transport. To do this, extend the CXFNonSpringServlet and then override the method loadBus, e.g.:

@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 factroy = new ServerFactoryBean();
   factory.setBus(bus);
   factory.setServiceClass(GreeterImpl.class);
   factory.setAddress("/Greeter");
   factory.create();              
}

If you are using Jetty as the embedded servlet engine, the endpoint can be published as follows:

// Set up 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);
   }
}