Publishing JAX-WS Webservice with Guice in a Servlet Application

前端 未结 1 1567
小鲜肉
小鲜肉 2021-01-21 18:28

We are currently porting an existing JBoss EJB application to a pure servlet solution which is supposed to run in a Jetty (we\'re currently using version 6, but the version is m

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 19:09

    We finally solved it quite elegantly by extending CXFNonSpringServlet. You simply override the loadBus() method where you can configure all your service endpoints.

    @Singleton
    public class SoapServlet extends CXFNonSpringServlet {
        private static final long serialVersionUID = 1L;
    
        private final SomeFacade someFacade;
    
        @Inject
        SoapMachineServlet(final SomeFacade someFacade) {
            this.someFacade = someFacade;
        }
    
        @Override
        public void loadBus(ServletConfig servletConfig) throws ServletException {
            super.loadBus(servletConfig);
    
            Bus bus = getBus();
            BusFactory.setDefaultBus(bus);
            Endpoint.publish("/SomeFacade", someFacade);
        }
    }
    

    The class itself is a simply a servlet, which can then be bound using a ServletModule:

    public class SomeModule extends ServletModule {
        @Override
        protected void configureServlets() {
            serve("/some/path*").with(SoapServlet.class);
        }
    }
    

    0 讨论(0)
提交回复
热议问题