diff --git a/distribution/src/main/release/samples/jaxrs_spring_boot/README b/distribution/src/main/release/samples/jaxrs_spring_boot/README new file mode 100644 index 00000000000..c9487d79b5a --- /dev/null +++ b/distribution/src/main/release/samples/jaxrs_spring_boot/README @@ -0,0 +1,13 @@ +== Spring Boot - Samples - CXF Rest Web Services + +This sample project demonstrates how to use http://projects.spring.io/spring-rs-cxf/[CXF Rest Web Services] +with Spring Boot. + +The sample uses Maven. It can be built and run from the command line: + +---- +$ mvn spring-boot:run +---- + +http://localhost:8080/services/helloservice/sayHello/Elan will now display the output in the browser +like "Hello Elan, Welcome to CXF RS Spring Boot World!!!" diff --git a/distribution/src/main/release/samples/jaxrs_spring_boot/pom.xml b/distribution/src/main/release/samples/jaxrs_spring_boot/pom.xml new file mode 100644 index 00000000000..0cb276d06b2 --- /dev/null +++ b/distribution/src/main/release/samples/jaxrs_spring_boot/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-samples + 1.3.0.BUILD-SNAPSHOT + + spring-boot-sample-rs-cxf + Spring Boot Web Services Sample + Spring Boot CXF Restful Web Services Sample + http://projects.spring.io/spring-boot/ + + ${basedir}/../.. + 3.0.0 + 4.2.0.BUILD-SNAPSHOT + 2.3.0 + 8.1.5.v20120716 + 1.7 + / + + + + org.springframework.boot + spring-boot-starter + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-core + ${spring.version} + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf.version} + + + org.apache.cxf + cxf-rt-transports-http + ${cxf.version} + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + org.apache.cxf + cxf-bundle-jaxrs + 2.7.14 + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + org.eclipse.jetty + jetty-webapp + ${jetty.version} + + + org.eclipse.jetty + jetty-servlets + ${jetty.version} + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.cxf + cxf-rt-rs-service-description + 3.0.0-milestone1 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/HelloService.java b/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/HelloService.java new file mode 100644 index 00000000000..72e2a667f71 --- /dev/null +++ b/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/HelloService.java @@ -0,0 +1,18 @@ +package sample.rs.service; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/sayHello") +public class HelloService { + + @GET + @Path("/{a}") + @Produces(MediaType.TEXT_PLAIN) + public String sayHello(@PathParam("a") String a) { + return "Hello "+a+", Welcome to CXF RS Spring Boot World!!!"; + } + +} \ No newline at end of file diff --git a/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/SampleRestWSApplication.java b/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/SampleRestWSApplication.java new file mode 100644 index 00000000000..5bd90db3255 --- /dev/null +++ b/distribution/src/main/release/samples/jaxrs_spring_boot/src/main/java/sample/rs/service/SampleRestWSApplication.java @@ -0,0 +1,56 @@ +package sample.rs.service; +import org.apache.cxf.Bus; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; +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.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; + +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.bus.spring.SpringBus; +import sample.rs.service.HelloService; +import org.apache.cxf.jaxrs.JAXRSBindingFactory; + +@Configuration +@EnableAutoConfiguration +@ImportResource({ "classpath:META-INF/cxf/cxf.xml" }) +public class SampleRestWSApplication extends SpringBootServletInitializer { + + @Autowired + private ApplicationContext applicationContext; + + public static void main(String[] args) { + SpringApplication.run(SampleRestWSApplication.class, args); + } + + @Bean + public ServletRegistrationBean servletRegistrationBean(ApplicationContext context) { + return new ServletRegistrationBean(new CXFServlet(), "/services/*"); + } + + + @Bean + public Server rsServer() { + Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID); + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); + endpoint.setServiceBean(new HelloService()); + endpoint.setAddress("/helloservice"); + endpoint.setBus(bus); + return endpoint.create(); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleRestWSApplication.class); + } + +} \ No newline at end of file diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/README b/distribution/src/main/release/samples/jaxws_spring_boot/README new file mode 100644 index 00000000000..748feb1c034 --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/README @@ -0,0 +1,15 @@ +== Spring Boot - CXF Samples - Web Services + +This sample project demonstrates how to use http://projects.spring.io/spring-ws-cxf/[CXF Web Services] +with Spring Boot. + +The sample uses Maven. It can be built and run from the command line: + +---- +$ mvn spring-boot:run +---- + +http://localhost:8080/Service/Hello?WSDL will now display the generated WSDL. + +to run the client navigate to the client folder. + diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/client/README_CLIENT.txt b/distribution/src/main/release/samples/jaxws_spring_boot/client/README_CLIENT.txt new file mode 100644 index 00000000000..edd222f42f3 --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/client/README_CLIENT.txt @@ -0,0 +1,11 @@ +== Spring Boot - CXF Samples - Web Services Client + +This sample project demonstrates how to run the client CXF Web Services with Spring Boot. + +The sample uses Maven. It can be built and run from the command line: + +---- +$ mvn exec:java +---- + +Will display the execution result in the console. diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/client/pom.xml b/distribution/src/main/release/samples/jaxws_spring_boot/client/pom.xml new file mode 100644 index 00000000000..a6ce3615456 --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/client/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + spring-boot-sample-ws-cxf-Client + Spring Boot CXF Web Services Sample Client + Spring Boot CXF Web Services Sample Client + org.apache.cxf.spring.boot + 1.0.0 + + + org.apache.cxf + cxf-bundle + 3.0.0-milestone2 + + + javax.xml + jaxws-api + 2.0 + + + org.eclipse.jetty + jetty-webapp + 9.3.0.M2 + + + org.springframework.boot + spring-boot-starter-ws + 1.2.3.RELEASE + + + jaxen + jaxen + 1.1.6 + + + org.jdom + jdom2 + 2.0.6 + + + wsdl4j + wsdl4j + 1.6.3 + + + + + + org.codehaus.mojo + exec-maven-plugin + + sample.ws.service.client.HelloClient + + + + + diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/Hello.java b/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/Hello.java new file mode 100644 index 00000000000..1f48ffc38fc --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/Hello.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.ws.service; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +/** + * Examples code for spring boot with CXF services. + * Hello is the interface for sayHello interface. + * + * This class was generated by Apache CXF 3.1.0 2015-05-18T13:02:03.098-05:00 + * Generated source version: 3.1.0 + * + */ +@WebService(targetNamespace = "http://service.ws.sample/", name = "Hello" , serviceName = "HelloService") +public interface Hello { + + @WebResult(name = "return", targetNamespace = "") + @RequestWrapper(localName = "sayHello", targetNamespace = "http://service.ws.sample/", className = "sample.ws.service.SayHello") + @WebMethod(action = "urn:SayHello") + @ResponseWrapper(localName = "sayHelloResponse", targetNamespace = "http://service.ws.sample/", className = "sample.ws.service.SayHelloResponse") + public java.lang.String sayHello( + @WebParam(name = "myname", targetNamespace = "") java.lang.String myname); +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/client/HelloClient.java b/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/client/HelloClient.java new file mode 100644 index 00000000000..59ba1043d2c --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/client/src/main/java/sample/ws/service/client/HelloClient.java @@ -0,0 +1,24 @@ +package sample.ws.service.client; + +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; + +import sample.ws.service.Hello; + +public class HelloClient { + + public static void main(String[] args) { + try { + URL wsdlURL = new URL("http://localhost:8080/Service/Hello?wsdl"); + QName SERVICE_NAME = new QName("http://service.ws.sample/","HelloService"); + Service service = Service.create(wsdlURL, SERVICE_NAME); + Hello client = service.getPort(Hello.class); + System.out.println(client.sayHello("Elan")); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/pom.xml b/distribution/src/main/release/samples/jaxws_spring_boot/pom.xml new file mode 100644 index 00000000000..1526af704f4 --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 1.2.3.RELEASE + + spring-boot-sample-ws-cxf + Spring Boot CXF Web Services Sample + Spring Boot CXF Web Services Sample + org.apache.cxf.spring.boot + 1.0.0 + + + org.springframework.boot + spring-boot-starter-test + 1.2.3.RELEASE + test + + + org.apache.cxf + cxf-bundle + 3.0.0-milestone2 + + + javax.xml + jaxws-api + 2.0 + + + org.eclipse.jetty + jetty-webapp + 9.3.0.M2 + + + org.springframework.boot + spring-boot-starter-ws + 1.2.3.RELEASE + + + jaxen + jaxen + 1.1.6 + + + org.jdom + jdom2 + 2.0.6 + + + wsdl4j + wsdl4j + 1.6.3 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/SampleWsApplication.java b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/SampleWsApplication.java new file mode 100644 index 00000000000..f84f65d8e6f --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/SampleWsApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.ws; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleWsApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleWsApplication.class, args); + } + + + +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/WebServiceConfig.java b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/WebServiceConfig.java new file mode 100644 index 00000000000..12691a080df --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/WebServiceConfig.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.ws; + +import org.springframework.boot.context.embedded.ServletRegistrationBean; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.ws.config.annotation.EnableWs; +import org.springframework.ws.config.annotation.WsConfigurerAdapter; +import org.springframework.ws.transport.http.MessageDispatcherServlet; +import org.apache.cxf.bus.spring.SpringBus; +import sample.ws.service.Hello; +import sample.ws.service.HelloPortImpl; +import javax.xml.ws.Endpoint; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.apache.cxf.jaxws.EndpointImpl +; + +@EnableWs +@Configuration +public class WebServiceConfig extends WsConfigurerAdapter { + + @Bean + public ServletRegistrationBean dispatcherServlet() { + CXFServlet cxfServlet = new CXFServlet(); + return new ServletRegistrationBean(cxfServlet, "/Service/*"); + } + + @Bean(name="cxf") + public SpringBus springBus() { + return new SpringBus(); + } + + @Bean + public Hello myService() { + return new HelloPortImpl(); + } + + @Bean + public Endpoint endpoint() { + EndpointImpl endpoint = new EndpointImpl(springBus(), myService()); + endpoint.publish("/Hello"); + return endpoint; + } +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/Hello.java b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/Hello.java new file mode 100644 index 00000000000..cd520cbd79a --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/Hello.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.ws.service; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +/** + * Examples code for spring boot with CXF services. + * Hello is the interface for sayHello interface. + * + * This class was generated by Apache CXF 3.1.0 2015-05-18T13:02:03.098-05:00 + * Generated source version: 3.1.0 + * + */ +@WebService(targetNamespace = "http://service.ws.sample/", name = "Hello") +public interface Hello { + + @WebResult(name = "return", targetNamespace = "") + @RequestWrapper(localName = "sayHello", targetNamespace = "http://service.ws.sample/", className = "sample.ws.service.SayHello") + @WebMethod(action = "urn:SayHello") + @ResponseWrapper(localName = "sayHelloResponse", targetNamespace = "http://service.ws.sample/", className = "sample.ws.service.SayHelloResponse") + public java.lang.String sayHello( + @WebParam(name = "myname", targetNamespace = "") java.lang.String myname); +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/HelloPortImpl.java b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/HelloPortImpl.java new file mode 100644 index 00000000000..e721698fef9 --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws/service/HelloPortImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.ws.service; + +import java.util.logging.Logger; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +/** + * Examples code for spring boot with CXF services. + * HelloPortImpl is the implementation for Hello interface. + * + * This class was generated by Apache CXF 3.1.0 2015-05-18T13:02:03.098-05:00 + * Generated source version: 3.1.0 + * + */ + +@javax.jws.WebService(serviceName = "HelloService", portName = "HelloPort", targetNamespace = "http://service.ws.sample/", endpointInterface = "sample.ws.service.Hello") +public class HelloPortImpl implements Hello { + + private static final Logger LOG = Logger.getLogger(HelloPortImpl.class + .getName()); + + public java.lang.String sayHello(java.lang.String myname) { + LOG.info("Executing operation sayHello" + myname); + try { + return "Hello, Welcome to CXF Spring boot " + myname + "!!!"; + + } catch (java.lang.Exception ex) { + ex.printStackTrace(); + throw new RuntimeException(ex); + } + } + +} diff --git a/distribution/src/main/release/samples/jaxws_spring_boot/src/test/java/sample/ws/service/SampleWsApplicationTests.java b/distribution/src/main/release/samples/jaxws_spring_boot/src/test/java/sample/ws/service/SampleWsApplicationTests.java new file mode 100644 index 00000000000..6e195b52fef --- /dev/null +++ b/distribution/src/main/release/samples/jaxws_spring_boot/src/test/java/sample/ws/service/SampleWsApplicationTests.java @@ -0,0 +1,73 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.ws.service; + +import java.io.StringReader; + +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.ws.client.core.WebServiceTemplate; +import sample.ws.SampleWsApplication; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleWsApplication.class) +@WebAppConfiguration +@IntegrationTest("server.port=0") +public class SampleWsApplicationTests { + + @Rule + public OutputCapture output = new OutputCapture(); + + private WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); + + @Value("${local.server.port}") + private int serverPort; + + @Before + public void setUp() { + this.webServiceTemplate.setDefaultUri("http://localhost:" + this.serverPort + + "/Service/Hello"); + } + + @Test + public void testHelloRequest() { + //final String request = "Elan"; + final String request = "Elan"; + + + StreamSource source = new StreamSource(new StringReader(request)); + StreamResult result = new StreamResult(System.out); + + this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); + assertThat(this.output.toString(), containsString("Hello, Welcome to CXF Spring boot Elan!!!")); + } + +}