From: gu.martinm@gmail.com Date: Sun, 9 Feb 2014 14:18:20 +0000 (+0100) Subject: Avoid inheritance in XSD files with JAXB custom bindings. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=abe44cad08fa92ff34d2ae7e053b1097a3ba73b3;p=SpringWebServicesForFun%2F.git Avoid inheritance in XSD files with JAXB custom bindings. --- diff --git a/pom.xml b/pom.xml index 3486faa..450e486 100644 --- a/pom.xml +++ b/pom.xml @@ -285,6 +285,7 @@ true ${project.xsd.schemas.source.path}/examples.xsd + ${project.xsd.schemas.source.path}/custombinding.xjb ${project.xsd.schemas.package.name} -Xinheritance @@ -323,7 +324,10 @@ ${project.xsd.schemas.target.path} + + ${project.wsdl.sources.path}/custombindingexample.wsdl -xjc-Xinheritance diff --git a/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java b/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java new file mode 100644 index 0000000..864afa9 --- /dev/null +++ b/src/main/java/de/spring/webservices/business/CustomBindingBusinessExample.java @@ -0,0 +1,24 @@ +package de.spring.webservices.business; + +import de.spring.webservices.auto.CustomBindingExampleRequest; +import de.spring.webservices.auto.CustomBindingExampleResponse; +import de.spring.webservices.auto.ObjectFactory; +import de.spring.webservices.operations.Operations; + +/** + * Example of business class + * + */ +public class CustomBindingBusinessExample + implements Operations.RequestResponse { + + @Override + public CustomBindingExampleResponse requestResponse(final CustomBindingExampleRequest request) { + final CustomBindingExampleResponse response = new ObjectFactory().createCustomBindingExampleResponse(); + + response.setData("CUSTOM BINDING SNAKE EYES AND " + request.getData()); + + return response; + } + +} diff --git a/src/main/java/de/spring/webservices/client/ExampleClient.java b/src/main/java/de/spring/webservices/client/ExampleClient.java index 6a7ccc3..3512d28 100644 --- a/src/main/java/de/spring/webservices/client/ExampleClient.java +++ b/src/main/java/de/spring/webservices/client/ExampleClient.java @@ -1,5 +1,7 @@ package de.spring.webservices.client; +import localhost._8888.spring_ws.example.CustomBindingExampleRequest; +import localhost._8888.spring_ws.example.CustomBindingExampleResponse; import localhost._8888.spring_ws.example.ExampleRequest; import localhost._8888.spring_ws.example.ExampleResponse; import localhost._8888.spring_ws.example.Examples; @@ -30,19 +32,29 @@ public class ExampleClient { public void sendAndReceive() { final Examples exampleService = new ExamplesService().getExamplesSoap11(); final ExampleRequest exampleRequest = new ObjectFactory().createExampleRequest(); + final CustomBindingExampleRequest customBindingxampleRequest = + new ObjectFactory().createCustomBindingExampleRequest(); exampleRequest.setData("SCARLETT. IT IS CANON."); + customBindingxampleRequest.setData("CUSTOM BINDING. SCARLETT. IT IS CANON."); //There are two options O.o: //1. Through Java: ExampleResponse exampleResponse = exampleService.example(exampleRequest); System.out.println(exampleResponse.getData()); + CustomBindingExampleResponse customBindingExampleResponse = + exampleService.customBindingExample(customBindingxampleRequest); + System.out.println(customBindingExampleResponse.getData()); //2. Using Spring: this.webServiceTemplate.setDefaultUri(this.Uri); exampleResponse = (ExampleResponse) this.webServiceTemplate.marshalSendAndReceive(exampleRequest); + this.webServiceTemplate.setDefaultUri(this.Uri); + customBindingExampleResponse = (CustomBindingExampleResponse) this.webServiceTemplate + .marshalSendAndReceive(customBindingxampleRequest); System.out.println(exampleResponse.getData()); + System.out.println(customBindingExampleResponse.getData()); } } diff --git a/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java index d423e5e..cef1f83 100644 --- a/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java +++ b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java @@ -7,6 +7,8 @@ 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; @@ -16,6 +18,7 @@ import de.spring.webservices.operations.Operations; public class ExampleEndPoint { private static final String NAMESPACE_URI = "http://localhost:8888/spring-ws/example"; private Operations.RequestResponse example; + private Operations.RequestResponse customBindingExample; public ExampleEndPoint() {} @@ -31,10 +34,25 @@ public class ExampleEndPoint { return example.requestResponse(requestObject); } + @PayloadRoot(localPart = "CustomBindingExampleRequest", namespace = NAMESPACE_URI) + @ResponsePayload + public CustomBindingExampleResponse order( + @RequestPayload final CustomBindingExampleRequest requestObject, + @RequestPayload final Element element, + final MessageContext messageContext) { + + return this.customBindingExample.requestResponse(requestObject); + } + /** Setter required by Spring **/ public void setExample( final Operations.RequestResponse example) { this.example = example; } + + public void setCustomBindingExample( + final Operations.RequestResponse customBindingExample) { + this.customBindingExample = customBindingExample; + } } diff --git a/src/main/resources/spring-configuration.xml b/src/main/resources/spring-configuration.xml index c7a3ffd..0d81fa1 100644 --- a/src/main/resources/spring-configuration.xml +++ b/src/main/resources/spring-configuration.xml @@ -26,7 +26,11 @@ --> - + + @@ -67,9 +71,14 @@ + + + + + diff --git a/src/main/resources/wsdl/custombindingexample.wsdl b/src/main/resources/wsdl/custombindingexample.wsdl new file mode 100644 index 0000000..0f163b1 --- /dev/null +++ b/src/main/resources/wsdl/custombindingexample.wsdl @@ -0,0 +1,116 @@ + + + + + + + + + + + de.spring.webservices.operations.Request + + + + + + + + + + + + de.spring.webservices.operations.Response + + + + + + + + + + + + + de.spring.webservices.operations.Request + + + + + + + + + + + + de.spring.webservices.operations.Response + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/wsdl/example.wsdl b/src/main/resources/wsdl/example.wsdl deleted file mode 100644 index 8a75ff5..0000000 --- a/src/main/resources/wsdl/example.wsdl +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - de.spring.webservices.operations.Request - - - - - - - - - - - - de.spring.webservices.operations.Response - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/xsd/custombinding.xjb b/src/main/resources/xsd/custombinding.xjb new file mode 100644 index 0000000..9ceb3a9 --- /dev/null +++ b/src/main/resources/xsd/custombinding.xjb @@ -0,0 +1,36 @@ + + + + + + + + + de.spring.webservices.operations.Request + + + + + + + de.spring.webservices.operations.Response + + + + diff --git a/src/main/resources/xsd/examples.xsd b/src/main/resources/xsd/examples.xsd index 897d024..d951278 100644 --- a/src/main/resources/xsd/examples.xsd +++ b/src/main/resources/xsd/examples.xsd @@ -34,4 +34,21 @@ + + + + + + + + + + + + + + + + +