From: Gustavo Martin Morcuende Date: Mon, 14 Dec 2015 03:19:31 +0000 (+0100) Subject: Using maven-jaxb2-plugin X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=99c81521038ec731d81eafe55df246d59e4092aa;p=SpringWebServicesForFun%2F.git Using maven-jaxb2-plugin --- diff --git a/jaxb2/web-services-spring-jaxb2-client/pom.xml b/jaxb2/web-services-spring-jaxb2-client/pom.xml new file mode 100644 index 0000000..a70061d --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/pom.xml @@ -0,0 +1,184 @@ + + 4.0.0 + + web-services-spring-jaxb2 + de.spring.webservices + 1.0-SNAPSHOT + + web-services-spring-jaxb2-client + web-services-spring-jaxb2-client + http://gumartinm.name + + + src/main/build-resources/wsdl + ${basedir}/target/generated-sources/src/main/java + src/main/build-resources/bindings + + ${basedir}/src/main/build-resources/catalogs + + + + + org.springframework.ws + spring-ws-core + + + org.springframework.ws + spring-xml + + + org.jdom + jdom + + + + + + de.spring.webservices + web-services-spring-jaxb2-globalxsds + ${project.version} + + + + + + wsdl4j + wsdl4j + + + + + org.jvnet.jaxb2_commons + jaxb2-basics-runtime + 0.9.4 + + + + + junit + junit + test + + + org.springframework + spring-test + test + + + org.springframework.ws + spring-ws-test + test + + + + + ${project.artifactId} + + + ${basedir}/src/main/resources/ + + **/*.* + + + + + + + org.apache.cxf + cxf-codegen-plugin + 3.1.0 + + + generate-sources-from-wsdl + generate-sources + + wsdl2java + + + true + ${project.wsdl.target.path} + + + + ${project.wsdl.sources.path}/example.wsdl + + ${project.bindings.path}/custombinding.xjb + + + -xjc-Xinheritance + -xjc-Xannotate + -catalog + ${project.catalogs.path}/catalog.cat + -verbose + + + + + + + + + + org.jvnet.jaxb2_commons + jaxb2-basics + 0.9.4 + + + + + org.jvnet.jaxb2_commons + jaxb2-basics-annotate + 1.0.1 + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + ${project.wsdl.target.path} + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/bindings/custombinding.xjb b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/bindings/custombinding.xjb new file mode 100644 index 0000000..95e1fd2 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/bindings/custombinding.xjb @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + de.spring.webservices.operations.Request + @java.lang.suppresswarnings({"unchecked","rawtypes"}) + + + + de.spring.webservices.operations.Response + @java.lang.suppresswarnings({"unchecked","rawtypes"}) + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/catalogs/catalog.cat b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/catalogs/catalog.cat new file mode 100644 index 0000000..4bc1c66 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/catalogs/catalog.cat @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/wsdl/example.wsdl b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/wsdl/example.wsdl new file mode 100644 index 0000000..02b2256 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/build-resources/wsdl/example.wsdl @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + @java.lang.SuppressWarnings({"unchecked","rawtypes"}) + de.spring.webservices.operations.Request + + + + + + + + + + + + de.spring.webservices.operations.Response + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/ExampleClientService.java b/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/ExampleClientService.java new file mode 100644 index 0000000..177c13e --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/ExampleClientService.java @@ -0,0 +1,72 @@ +package de.spring.webservices.client; + +import name.gumartinm.spring_ws.parent.ParentEnumType; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ws.client.core.WebServiceTemplate; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; +import de.spring.webservices.auto.Examples; +import de.spring.webservices.auto.ExamplesService; + +/** + * Someone could write code like this one in order to send and receive + * information from our Web Services. + * + */ +public class ExampleClientService { + private final WebServiceTemplate webServiceTemplate; + + @Autowired + public ExampleClientService(WebServiceTemplate webServiceTemplate) { + this.webServiceTemplate = webServiceTemplate; + } + + public ExampleResponse sendAndReceiveJava() { + final ExampleRequest exampleRequest = new ExampleRequest(); + exampleRequest.setData("SCARLETT JAVA. IT IS CANON."); + + final Examples exampleService = new ExamplesService().getExamplesSoap12(); + final ExampleResponse exampleResponse = exampleService.example(exampleRequest); + + return exampleResponse; + } + + public ExampleResponse sendAndReceiveSpring() { + final ExampleRequest exampleRequest = new ExampleRequest(); + exampleRequest.setData("SCARLETT SPRING. IT IS CANON."); + + final ExampleResponse exampleResponse = (ExampleResponse) + this.webServiceTemplate.marshalSendAndReceive(exampleRequest); + + return exampleResponse; + } + + public CustomBindingExampleResponse sendAndReceiveJavaCustom() { + final CustomBindingExampleRequest customBindingxampleRequest = + new CustomBindingExampleRequest(); + customBindingxampleRequest.setData("CUSTOM BINDING JAVA. SCARLETT. IT IS CANON."); + customBindingxampleRequest.setParentEnum(ParentEnumType.FIRST); + + final Examples exampleService = new ExamplesService().getExamplesSoap12(); + final CustomBindingExampleResponse customBindingExampleResponse = + exampleService.customBindingExample(customBindingxampleRequest); + + return customBindingExampleResponse; + } + + public CustomBindingExampleResponse sendAndReceiveSpringCustom() { + final CustomBindingExampleRequest customBindingxampleRequest = + new CustomBindingExampleRequest(); + customBindingxampleRequest.setData("CUSTOM BINDING SPRING. SCARLETT. IT IS CANON."); + + final CustomBindingExampleResponse customBindingExampleResponse = + (CustomBindingExampleResponse) this.webServiceTemplate + .marshalSendAndReceive(customBindingxampleRequest); + + return customBindingExampleResponse; + } +} diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/MainTest.java b/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/MainTest.java new file mode 100644 index 0000000..48fbdcd --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/java/de/spring/webservices/client/MainTest.java @@ -0,0 +1,52 @@ +package de.spring.webservices.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ExampleResponse; + +/** + * This class is used just like a nice example about how to write and run client + * code which will send data to and from the Web Services. + * + */ +public class MainTest { + private static final Logger logger = LoggerFactory.getLogger(MainTest.class); + + public ApplicationContext context; + + /** + * @param args + */ + public static void main(final String[] args) { + final MainTest test = new MainTest(); + + test.context = new ClassPathXmlApplicationContext( + "classpath:spring-configuration/ws/client-spring-configuration.xml"); + + final ExampleClientService example = + (ExampleClientService) test.context.getBean("exampleClient"); + + logger.info("ExampleResponse Java:"); + ExampleResponse response = example.sendAndReceiveJava(); + logger.info(response.getData()); + + + logger.info("CustomBindingExampleResponse Java:"); + CustomBindingExampleResponse customBindingResponse = example.sendAndReceiveJavaCustom(); + logger.info(customBindingResponse.getData()); + + + logger.info("ExampleResponse Spring:"); + response = example.sendAndReceiveSpring(); + logger.info(response.getData()); + + + logger.info("CustomBindingExampleResponse Spring:"); + customBindingResponse = example.sendAndReceiveSpringCustom(); + logger.info(customBindingResponse.getData()); + } +} diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/resources/examples.xsd b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/examples.xsd new file mode 100644 index 0000000..96c3737 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/examples.xsd @@ -0,0 +1,92 @@ + + + + + + + + + + + + + @java.lang.SuppressWarnings({"unchecked","rawtypes"}) + de.spring.webservices.operations.Request + + + + + + + + + + + + de.spring.webservices.operations.Response + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/resources/log4j2.xml b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/log4j2.xml new file mode 100644 index 0000000..18a4008 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/main/resources/spring-configuration/ws/client-spring-configuration.xml b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/spring-configuration/ws/client-spring-configuration.xml new file mode 100644 index 0000000..785d2db --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/main/resources/spring-configuration/ws/client-spring-configuration.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + classpath:examples.xsd + classpath:parent.xsd + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-client/src/test/java/de/spring/webservices/client/ExampleClientServiceIntegrationTest.java b/jaxb2/web-services-spring-jaxb2-client/src/test/java/de/spring/webservices/client/ExampleClientServiceIntegrationTest.java new file mode 100644 index 0000000..a536c47 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-client/src/test/java/de/spring/webservices/client/ExampleClientServiceIntegrationTest.java @@ -0,0 +1,78 @@ +package de.spring.webservices.client; + +import static org.junit.Assert.assertEquals; +import static org.springframework.ws.test.client.RequestMatchers.payload; +import static org.springframework.ws.test.client.ResponseCreators.withPayload; + +import javax.xml.transform.Source; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.test.client.MockWebServiceServer; +import org.springframework.xml.transform.StringSource; + +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ExampleResponse; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath*:spring-configuration/ws/client-spring-configuration.xml") +public class ExampleClientServiceIntegrationTest { + + @Autowired + ExampleClientService exampleClientService; + + @Autowired + private WebServiceTemplate webServiceTemplate; + + private MockWebServiceServer mockServer; + + @Before + public void createServer() throws Exception { + mockServer = MockWebServiceServer.createServer(webServiceTemplate); + } + + @Test + public void customerClient() throws Exception { + final Source requestPayload = new StringSource( + "" + + "SCARLETT SPRING. IT IS CANON." + + ""); + final Source responsePayload = new StringSource( + "" + + "SNAKE EYES AND SCARLETT SPRING. IT IS CANON." + + ""); + mockServer.expect(payload(requestPayload)).andRespond( + withPayload(responsePayload)); + + final ExampleResponse response = exampleClientService.sendAndReceiveSpring(); + + assertEquals(response.getData(), "SNAKE EYES AND SCARLETT SPRING. IT IS CANON."); + mockServer.verify(); + } + + @Test + public void customerCustomClient() throws Exception { + final Source customRequestPayload = new StringSource( + "" + + "CUSTOM BINDING SPRING. SCARLETT. IT IS CANON." + + ""); + final Source customResponsePayload = new StringSource( + "" + + "CUSTOM BINDING SNAKE EYES AND SCARLETT SPRING. IT IS CANON." + + ""); + mockServer.expect(payload(customRequestPayload)).andRespond( + withPayload(customResponsePayload)); + + final CustomBindingExampleResponse response = exampleClientService.sendAndReceiveSpringCustom(); + + assertEquals(response.getData(), "CUSTOM BINDING SNAKE EYES AND SCARLETT SPRING. IT IS CANON."); + mockServer.verify(); + } +} + diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/pom.xml b/jaxb2/web-services-spring-jaxb2-globalxsds/pom.xml new file mode 100644 index 0000000..b577d57 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/pom.xml @@ -0,0 +1,102 @@ + + 4.0.0 + + web-services-spring-jaxb2 + de.spring.webservices + 1.0-SNAPSHOT + + web-services-spring-jaxb2-globalxsds + web-services-spring-jaxb2-globalxsds + http://gumartinm.name + + + src/main/resources/schemas + ${project.build.directory}/generated-sources/src/main/java + de.spring.webservices.auto + src/main/build-resources/bindings + + + + + + + junit + junit + test + + + + + ${project.artifactId} + + + ${basedir}/src/main/resources + + **/*.* + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.13.1 + + + generate-sources-from-xsd + + generate + + generate-sources + + + + + ${project.xsd.schemas.source.path} + + + ${project.bindings.path} + + false + + + ${project.xsd.schemas.target.path} + + + ${project.xsd.schemas.package.name} + + + true + + true + + + ${project.build.sourceEncoding} + + + en + + + true + false + + + true + + true + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/build-resources/bindings/custombinding.xjb b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/build-resources/bindings/custombinding.xjb new file mode 100644 index 0000000..8b4a110 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/build-resources/bindings/custombinding.xjb @@ -0,0 +1,8 @@ + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/binders/XSDateTimeCustomBinder.java b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/binders/XSDateTimeCustomBinder.java new file mode 100644 index 0000000..f39921a --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/binders/XSDateTimeCustomBinder.java @@ -0,0 +1,35 @@ +package de.spring.webservices.binders; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + + +/** + * ATTENTION: if you are using this custombinder you will have to create custom payload + * validators for Spring (AS FAR AS I KNOW) + * + */ +public class XSDateTimeCustomBinder extends XmlAdapter { + + @Override + public Date unmarshal(final String dateTime) throws Exception { + // X pattern just works from Java >= 1.7 + final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); + formatter.setTimeZone(TimeZone.getTimeZone("Europe/Madrid")); + + return formatter.parse(dateTime); + } + + @Override + public String marshal(final Date dateTime) throws Exception { + // X pattern just works from Java >= 1.7 + final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); + formatter.setTimeZone(TimeZone.getTimeZone("Europe/Madrid")); + + return formatter.format(dateTime); + } +} diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Operations.java b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Operations.java new file mode 100644 index 0000000..13b5113 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Operations.java @@ -0,0 +1,111 @@ +package de.spring.webservices.operations; + +/** + *

+ * Operations: WSDL v1.1 and v2.0 + *

+ * See: http://www.w3.org/TR/wsdl#_porttypes
+ * See: + * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns + * + */ +public interface Operations { + + /** + *

+ * Request-response operation WSDL v1.1 + *

+ * See: http://www.w3.org + * /TR/wsdl#_request-response + * + * @param + * Describes {@link Response} + * @param + * Describes {@link Request} + */ + public static interface RequestResponse { + T requestResponse(E request); + } + + /** + *

+ * One-way operation WSDL v1.1 + *

+ * See: http://www.w3.org/TR/wsdl + * #_one-way + * + * @param + * Describes {@link Response} + * @param + * Describes {@link Request} + */ + public interface OneWay { + void oneWay(E request); + } + + /** + *

+ * Notification operation WSDL v1.1 + *

+ * See: http://www.w3.org/TR + * /wsdl#_notification + * + * @param + * Describes {@link Response} + * @param + * Describes {@link Request} + */ + public interface Notification { + T notification(); + } + + /** + *

+ * In-Only message exchange pattern WSDL 2.0 + *

+ * See: + * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns + * + * @param + * Describes {@link Request} + */ + public interface InOnly { + void inOnly(E request); + } + + /** + *

+ * Robust In-Only message exchange pattern WSDL 2.0 + *

+ * See: + * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns + * + * @param + * Describes {@link Request} + */ + public interface RobustInOnly { + void robustInOnly(E request); + } + + /** + *

+ * In-Out message exchange pattern WSDL 2.0 + *

+ * See: + * http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#patterns + * + * @param + * Describes {@link Response} + * @param + * Describes {@link Request} + */ + public interface InOut { + T inOut(E request); + } +} \ No newline at end of file diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Request.java b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Request.java new file mode 100644 index 0000000..77d81f4 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Request.java @@ -0,0 +1,5 @@ +package de.spring.webservices.operations; + +public interface Request { + +} diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Response.java b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Response.java new file mode 100644 index 0000000..3a2cbea --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/java/de/spring/webservices/operations/Response.java @@ -0,0 +1,5 @@ +package de.spring.webservices.operations; + +public interface Response { + +} diff --git a/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/resources/schemas/parent.xsd b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/resources/schemas/parent.xsd new file mode 100644 index 0000000..0ce508e --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/resources/schemas/parent.xsd @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/pom.xml b/jaxb2/web-services-spring-jaxb2-server/pom.xml new file mode 100644 index 0000000..b12472a --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/pom.xml @@ -0,0 +1,199 @@ + + 4.0.0 + + web-services-spring-jaxb2 + de.spring.webservices + 1.0-SNAPSHOT + + web-services-spring-jaxb2-server + war + web-services-spring-jaxb2-server + http://gumartinm.name + + + 9.3.0.RC0 + + ${basedir}/src/main/build-resources/catalogs + + + src/main/resources/schemas + ${project.build.directory}/generated-sources/src/main/java + de.spring.webservices.auto + src/main/build-resources/bindings + + + + + + org.springframework.ws + spring-ws-core + + + org.springframework.ws + spring-xml + + + org.jdom + jdom + + + + + + de.spring.webservices + web-services-spring-jaxb2-globalxsds + ${project.version} + + + + + + wsdl4j + wsdl4j + + + + + junit + junit + test + + + org.springframework + spring-test + test + + + org.springframework.ws + spring-ws-test + test + + + org.mockito + mockito-core + test + + + + + ${project.artifactId} + + + ${basedir}/src/main/webapp + + **/*.* + + + + ${basedir}/src/main/resources/ + + **/*.* + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.13.1 + + + generate-sources-from-xsd + + generate + + generate-sources + + + + + ${project.xsd.schemas.source.path} + + + ${project.bindings.path} + + false + + + ${project.xsd.schemas.target.path} + + + ${project.xsd.schemas.package.name} + + + true + + true + + + ${project.build.sourceEncoding} + + + en + + + true + false + + + true + + true + + true + + -Xinheritance + -Xannotate + + + + org.jvnet.jaxb2_commons + jaxb2-basics + 0.9.5 + + + org.jvnet.jaxb2_commons + jaxb2-basics-annotate + 1.0.2 + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + + + true + src/main/webapp + + WEB-INF/web.xml + + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + ${basedir}/src/main/jetty/jetty-http.xml + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/bindings/custombinding.xjb b/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/bindings/custombinding.xjb new file mode 100644 index 0000000..a1430d5 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/bindings/custombinding.xjb @@ -0,0 +1,51 @@ + + + + + + + + + de.spring.webservices.operations.Request + @java.lang.SuppressWarnings({"unchecked","rawtypes"}) + + + + + + + de.spring.webservices.operations.Response + @java.lang.SuppressWarnings({"unchecked","rawtypes"}) + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/catalogs/catalog.cat b/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/catalogs/catalog.cat new file mode 100644 index 0000000..4bc1c66 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/build-resources/catalogs/catalog.cat @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java new file mode 100644 index 0000000..8fb4e40 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java @@ -0,0 +1,57 @@ +package de.spring.webservices.endpoints; + +import org.jdom2.Element; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.server.endpoint.annotation.Endpoint; +import org.springframework.ws.server.endpoint.annotation.PayloadRoot; +import org.springframework.ws.server.endpoint.annotation.RequestPayload; +import org.springframework.ws.server.endpoint.annotation.ResponsePayload; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; +import de.spring.webservices.operations.Operations; +import de.spring.webservices.operations.Operations.RequestResponse; +import de.spring.webservices.services.ExampleService; + + +@Endpoint +public class ExampleEndPoint { + private static final String NAMESPACE_URI = "http://gumartinm.name/spring-ws/example"; + + private final Operations.RequestResponse + customBindingExampleService; + + private final ExampleService exampleService; + + @Autowired + public ExampleEndPoint( + RequestResponse customBindingExampleService, + ExampleService exampleService) { + this.customBindingExampleService = customBindingExampleService; + this.exampleService = exampleService; + } + + @PayloadRoot(localPart = "ExampleRequest", namespace = NAMESPACE_URI) + @ResponsePayload + public ExampleResponse exampleResponse( + @RequestPayload final ExampleRequest request, + @RequestPayload final Element element, + final MessageContext messageContext) { + + return this.exampleService.doResponse(request); + } + + @PayloadRoot(localPart = "CustomBindingExampleRequest", namespace = NAMESPACE_URI) + @ResponsePayload + public CustomBindingExampleResponse cuntomBindingExampleResponse( + @RequestPayload final CustomBindingExampleRequest requestObject, + @RequestPayload final Element element, + final MessageContext messageContext) { + + return this.customBindingExampleService.requestResponse(requestObject); + } +} + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/ExampleService.java b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/ExampleService.java new file mode 100644 index 0000000..9d7eb79 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/ExampleService.java @@ -0,0 +1,11 @@ +package de.spring.webservices.services; + +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; + + +public interface ExampleService { + + public ExampleResponse doResponse(ExampleRequest request); + +} diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java new file mode 100644 index 0000000..caa7e41 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/CustomBindingExampleServiceImpl.java @@ -0,0 +1,27 @@ +package de.spring.webservices.services.impl; + +import org.springframework.stereotype.Service; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ParentEnumType; +import de.spring.webservices.operations.Operations; + + +@Service("customBindingExampleService") +public class CustomBindingExampleServiceImpl implements + Operations.RequestResponse { + + + @Override + public CustomBindingExampleResponse requestResponse(final CustomBindingExampleRequest request) { + + CustomBindingExampleResponse response = new CustomBindingExampleResponse(); + + response.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData()); + response.setParentEnum(ParentEnumType.FIRST); + + return response; + } + +} diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java new file mode 100644 index 0000000..7037776 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/java/de/spring/webservices/services/impl/ExampleServiceImpl.java @@ -0,0 +1,23 @@ +package de.spring.webservices.services.impl; + +import org.springframework.stereotype.Service; + +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; +import de.spring.webservices.services.ExampleService; + + +@Service("exampleService") +public class ExampleServiceImpl implements ExampleService { + + @Override + public ExampleResponse doResponse(final ExampleRequest request) { + + ExampleResponse response = new ExampleResponse(); + + response.setData("SNAKE EYES AND " + request.getData()); + + return response; + } + +} diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/jetty/jetty-http.xml b/jaxb2/web-services-spring-jaxb2-server/src/main/jetty/jetty-http.xml new file mode 100644 index 0000000..d995630 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/jetty/jetty-http.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + https + + + + 32768 + 8192 + 8192 + true + false + 512 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/resources/log4j2.xml b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/log4j2.xml new file mode 100644 index 0000000..18a4008 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/resources/schemas/examples.xsd b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/schemas/examples.xsd new file mode 100644 index 0000000..96c3737 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/schemas/examples.xsd @@ -0,0 +1,92 @@ + + + + + + + + + + + + + @java.lang.SuppressWarnings({"unchecked","rawtypes"}) + de.spring.webservices.operations.Request + + + + + + + + + + + + de.spring.webservices.operations.Response + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/spring-configuration.xml b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/spring-configuration.xml new file mode 100644 index 0000000..7341c77 --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/spring-configuration.xml @@ -0,0 +1,14 @@ + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/ws/soap-ws.xml b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/ws/soap-ws.xml new file mode 100644 index 0000000..afabf4e --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/ws/soap-ws.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + classpath:examples.xsd + classpath:parent.xsd + + + + + + + + + + + + + org.springframework.oxm.ValidationFailureException=CLIENT,Invalid request + + + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/main/webapp/WEB-INF/web.xml b/jaxb2/web-services-spring-jaxb2-server/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7e14eba --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,44 @@ + + + + Spring Web Services: example + + + + org.springframework.web.context.ContextLoaderListener + + + + + spring.profiles.active + ${environment.profile} + contextConfigLocation + + classpath*:spring-configuration/*.xml + + + + + + spring-ws + org.springframework.ws.transport.http.MessageDispatcherServlet + 1 + true + + contextConfigLocation + classpath*:spring-configuration/ws/*.xml + + + transformWsdlLocations + true + + + + + spring-ws + /spring-ws/* + + + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointIntegrationTest.java b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointIntegrationTest.java new file mode 100644 index 0000000..f0204cb --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointIntegrationTest.java @@ -0,0 +1,62 @@ +package de.spring.webservices.endpoints; + +import static org.springframework.ws.test.server.RequestCreators.withPayload; +import static org.springframework.ws.test.server.ResponseMatchers.payload; + +import javax.xml.transform.Source; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.ws.test.server.MockWebServiceClient; +import org.springframework.xml.transform.StringSource; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath*:spring-configuration/ws/soap-ws.xml" } ) +public class ExampleEndPointIntegrationTest { + + @Autowired + private ApplicationContext applicationContext; + + private MockWebServiceClient mockClient; + + @Before + public void createClient() { + mockClient = MockWebServiceClient.createClient(applicationContext); + } + + @Test + public void exampleEndpoint() throws Exception { + final Source requestPayload = new StringSource( + "" + + "SCARLETT" + + ""); + final Source responsePayload = new StringSource( + "" + + "SNAKE EYES AND SCARLETT" + + ""); + mockClient.sendRequest(withPayload(requestPayload)).andExpect( + payload(responsePayload)); + + + final Source customRequestPayload = new StringSource( + "" + + "SCARLETT" + + "2015-06-03T10:20:30Z" + + "FIRST" + + ""); + final Source customResponsePayload = new StringSource( + "" + + "CUSTOM BINDING SNAKE EYES AND SCARLETT" + + "FIRST" + + ""); + mockClient.sendRequest(withPayload(customRequestPayload)).andExpect( + payload(customResponsePayload)); + } +} + diff --git a/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java new file mode 100644 index 0000000..5b04c2f --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/endpoints/ExampleEndPointTest.java @@ -0,0 +1,52 @@ +package de.spring.webservices.endpoints; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.operations.Operations; +import de.spring.webservices.services.ExampleService; + + +public class ExampleEndPointTest { + + private ExampleService exampleService; + + private Operations.RequestResponse + customBindingExampleService; + + private ExampleEndPoint exampleEndPoint; + + @Before + public void init() { + exampleService = mock(ExampleService.class); + customBindingExampleService = mock(Operations.RequestResponse.class); + exampleEndPoint = new ExampleEndPoint(customBindingExampleService, exampleService); + } + + @Test + public void givenExampleRequestThenInvokeExampleService() { + ExampleRequest request = new ExampleRequest(); + request.setData("SCARLETT"); + + exampleEndPoint.exampleResponse(request, null, null); + + verify(exampleService).doResponse(request); + } + + @Test + public void givenCustomBindingExampleRequestThenInvokeCustomBindingExampleService() { + CustomBindingExampleRequest request = new CustomBindingExampleRequest(); + request.setData("SCARLETT"); + + exampleEndPoint.cuntomBindingExampleResponse(request, null, null); + + verify(customBindingExampleService).requestResponse(request); + } + +} diff --git a/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/CustomBindingExampleServiceTest.java b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/CustomBindingExampleServiceTest.java new file mode 100644 index 0000000..a6d493b --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/CustomBindingExampleServiceTest.java @@ -0,0 +1,34 @@ +package de.spring.webservices.services; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.operations.Operations; +import de.spring.webservices.services.impl.CustomBindingExampleServiceImpl; + + +public class CustomBindingExampleServiceTest { + + private Operations.RequestResponse + customBindingExampleService; + + @Before + public void init() { + customBindingExampleService = new CustomBindingExampleServiceImpl(); + } + + @Test + public void givenCustomBindingExampleRequestThenReturnCustomBindingExampleResponse() { + CustomBindingExampleRequest request = new CustomBindingExampleRequest(); + request.setData("SCARLETT"); + CustomBindingExampleResponse expected = new CustomBindingExampleResponse(); + expected.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData()); + + CustomBindingExampleResponse actual = customBindingExampleService.requestResponse(request); + + Assert.assertEquals(expected.getData(), actual.getData()); + } +} diff --git a/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java new file mode 100644 index 0000000..493c76d --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2-server/src/test/java/de/spring/webservices/services/ExampleServiceTest.java @@ -0,0 +1,32 @@ +package de.spring.webservices.services; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import de.spring.webservices.auto.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; +import de.spring.webservices.services.impl.ExampleServiceImpl; + +public class ExampleServiceTest { + + private ExampleService exampleService; + + @Before + public void init() { + exampleService = new ExampleServiceImpl(); + } + + @Test + public void givenExampleRequestThenReturnExampleResponse() { + ExampleRequest request = new ExampleRequest(); + request.setData("SCARLETT"); + ExampleResponse expected = new ExampleResponse(); + expected.setData("SNAKE EYES AND " + request.getData()); + + ExampleResponse actual = exampleService.doResponse(request); + + Assert.assertEquals(expected.getData(), actual.getData()); + } + +} diff --git a/jaxb2/web-services-spring-jaxb2/pom.xml b/jaxb2/web-services-spring-jaxb2/pom.xml new file mode 100644 index 0000000..da59eba --- /dev/null +++ b/jaxb2/web-services-spring-jaxb2/pom.xml @@ -0,0 +1,191 @@ + + 4.0.0 + de.spring.webservices + web-services-spring-jaxb2 + pom + 1.0-SNAPSHOT + web-services-spring-jaxb2 + http://gumartinm.name + Web Services Spring Framework + + Gustavo Martin Morcuende + http://www.gumartinm.name + + + scm:git:http://git.gumartinm.name/SpringWebServicesForFun + http://git.gumartinm.name/SpringWebServicesForFun + + + + UTF-8 + UTF-8 + + 4.0.9.RELEASE + 2.2.1.RELEASE + + + + + release + + release + + + true + + + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.3 + + + org.apache.logging.log4j + log4j-core + 2.3 + + + cglib + cglib + 2.2.2 + + + + + + org.springframework.ws + spring-ws-core + ${spring.ws.version} + + + org.springframework.ws + spring-xml + ${spring.ws.version} + + + org.jdom + jdom + 2.0.2 + + + + + wsdl4j + wsdl4j + 1.6.3 + + + + + junit + junit + 4.12 + test + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework.ws + spring-ws-test + ${spring.ws.version} + test + + + org.mockito + mockito-core + 2.0.11-beta + test + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.18.1 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + **/*IntegrationTest.java + + + + + +