Java tutorial
/** * Copyright (c) 2013 Sveriges Kommuner och Landsting (SKL). <http://www.skl.se/> * * This file is part of SKLTP. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package se.skltp; import org.apache.cxf.Bus; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.transport.servlet.CXFServlet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.boot.context.web.SpringBootServletInitializer; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ImportResource; import se.skltp.ei.intsvc.integrationtests.notifyservice.ProcessNotificationTestProducer; @SpringBootApplication @ImportResource({ "classpath:META-INF/cxf/cxf.xml" }) public class MockServer extends SpringBootServletInitializer { @Autowired @Qualifier(Bus.DEFAULT_BUS_ID) Bus bus; public static void main(String[] args) { SpringApplication.run(MockServer.class, args); } @Bean public EndpointImpl setupProcessNotificationService() { return setupEndpoint("/ProcessNotification", new ProcessNotificationTestProducer()); } @Bean public ServletRegistrationBean servletRegistrationBean(ApplicationContext context) { return new ServletRegistrationBean(new CXFServlet(), "/services/*"); } // Used when deploying to a standalone servlet container, i.e. tomcat @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(MockServer.class); } private EndpointImpl setupEndpoint(String uri, Object implementor) { EndpointImpl endpoint = new EndpointImpl(bus, implementor); endpoint.publish(uri); endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); return endpoint; } }