From 8a40e7e51e35cba48c5a237ae9595325f992973a Mon Sep 17 00:00:00 2001 From: gumartinm Date: Tue, 13 Nov 2012 05:11:11 +0100 Subject: [PATCH] Loads of changes. Client Integration Test is not working yet. :( --- .../webservices/business/BusinessExample.java | 4 +- .../spring/webservices/client/ExampleClient.java | 64 ++++++------ .../java/de/spring/webservices/client/Test.java | 27 +++++ .../webservices/endpoints/ExampleEndPoint.java | 29 ++---- .../spring/webservices/operations/Operations.java | 111 +++++++++++++++++++++ .../de/spring/webservices/operations/Request.java | 5 + .../de/spring/webservices/operations/Response.java | 5 + .../de/spring/webservices/porttypes/PortType.java | 69 ------------- .../de/spring/webservices/porttypes/Request.java | 5 - .../de/spring/webservices/porttypes/Response.java | 5 - src/main/resources/client-spring-configuration.xml | 60 +++++++++++ src/main/resources/spring-configuration.xml | 38 ++++--- src/main/resources/wsdl/example.wsdl | 4 +- src/main/resources/xsd/examples.xsd | 4 +- .../tests/ExampleEndPointIntegrationTest.java | 45 --------- .../tests/client/ExampleClientIntegrationTest.java | 48 +++++++++ .../server/ExampleEndPointIntegrationTest.java | 45 +++++++++ 17 files changed, 366 insertions(+), 202 deletions(-) create mode 100644 src/main/java/de/spring/webservices/client/Test.java create mode 100644 src/main/java/de/spring/webservices/operations/Operations.java create mode 100644 src/main/java/de/spring/webservices/operations/Request.java create mode 100644 src/main/java/de/spring/webservices/operations/Response.java delete mode 100644 src/main/java/de/spring/webservices/porttypes/PortType.java delete mode 100644 src/main/java/de/spring/webservices/porttypes/Request.java delete mode 100644 src/main/java/de/spring/webservices/porttypes/Response.java create mode 100644 src/main/resources/client-spring-configuration.xml delete mode 100644 src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java create mode 100644 src/test/java/de/spring/webservices/tests/client/ExampleClientIntegrationTest.java create mode 100644 src/test/java/de/spring/webservices/tests/server/ExampleEndPointIntegrationTest.java diff --git a/src/main/java/de/spring/webservices/business/BusinessExample.java b/src/main/java/de/spring/webservices/business/BusinessExample.java index c3852db..8a722b8 100644 --- a/src/main/java/de/spring/webservices/business/BusinessExample.java +++ b/src/main/java/de/spring/webservices/business/BusinessExample.java @@ -3,13 +3,13 @@ package de.spring.webservices.business; import de.spring.webservices.auto.ExampleRequest; import de.spring.webservices.auto.ExampleResponse; import de.spring.webservices.auto.ObjectFactory; -import de.spring.webservices.porttypes.PortType; +import de.spring.webservices.operations.Operations; /** * Example of business class * */ -public class BusinessExample implements PortType.RequestResponse { +public class BusinessExample implements Operations.RequestResponse { @Override public ExampleResponse requestResponse(final ExampleRequest request) { diff --git a/src/main/java/de/spring/webservices/client/ExampleClient.java b/src/main/java/de/spring/webservices/client/ExampleClient.java index 2612b07..6a7ccc3 100644 --- a/src/main/java/de/spring/webservices/client/ExampleClient.java +++ b/src/main/java/de/spring/webservices/client/ExampleClient.java @@ -1,54 +1,48 @@ package de.spring.webservices.client; -import org.springframework.oxm.jaxb.Jaxb2Marshaller; -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; - +import localhost._8888.spring_ws.example.ExampleRequest; import localhost._8888.spring_ws.example.ExampleResponse; import localhost._8888.spring_ws.example.Examples; import localhost._8888.spring_ws.example.ExamplesService; -import localhost._8888.spring_ws.example.ExampleRequest; +import localhost._8888.spring_ws.example.ObjectFactory; +import org.springframework.ws.client.core.WebServiceTemplate; + +/** + * Someone could write code like this one in order to send and receive + * information from our Web Services. + * + */ public class ExampleClient { private WebServiceTemplate webServiceTemplate; private String Uri; - - public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) { + + public void setWebServiceTemplate( + final WebServiceTemplate webServiceTemplate) { this.webServiceTemplate = webServiceTemplate; } - - public void setDefaultUri(String defaultUri) { + + public void setDefaultUri(final String defaultUri) { this.Uri = defaultUri; } - + public void sendAndReceive() { - //Examples exampleService = new ExamplesService().getExamplesSoap11(); - ExampleRequest exampleRequest = new ExampleRequest(); - exampleRequest.setData("I am John Smith."); - //exampleService.example(exampleRequest); - - + final Examples exampleService = new ExamplesService().getExamplesSoap11(); + final ExampleRequest exampleRequest = new ObjectFactory().createExampleRequest(); + exampleRequest.setData("SCARLETT. IT IS CANON."); + + //There are two options O.o: + + //1. Through Java: + ExampleResponse exampleResponse = exampleService.example(exampleRequest); + System.out.println(exampleResponse.getData()); + + //2. Using Spring: this.webServiceTemplate.setDefaultUri(this.Uri); - ExampleResponse exampleResponse = - (ExampleResponse) this.webServiceTemplate.marshalSendAndReceive(exampleRequest); - + exampleResponse = (ExampleResponse) + this.webServiceTemplate.marshalSendAndReceive(exampleRequest); + System.out.println(exampleResponse.getData()); } - - /** - * @param args - */ - public static void main(String[] args) { - ExampleClient prueba = new ExampleClient(); - SaajSoapMessageFactory joer = new SaajSoapMessageFactory(); - joer.afterPropertiesSet(); - WebServiceTemplate laleche = new WebServiceTemplate(joer); - laleche.afterPropertiesSet(); - laleche.setMarshaller(new Jaxb2Marshaller()); - - prueba.setDefaultUri("http://localhost:8888/spring-ws/example"); - prueba.setWebServiceTemplate(laleche); - prueba.sendAndReceive(); - } } diff --git a/src/main/java/de/spring/webservices/client/Test.java b/src/main/java/de/spring/webservices/client/Test.java new file mode 100644 index 0000000..37f979c --- /dev/null +++ b/src/main/java/de/spring/webservices/client/Test.java @@ -0,0 +1,27 @@ +package de.spring.webservices.client; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * 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 Test { + public ApplicationContext context; + + /** + * @param args + */ + public static void main(final String[] args) { + final Test test = new Test(); + + test.context = new ClassPathXmlApplicationContext( + "client-spring-configuration.xml"); + + final ExampleClient example = (ExampleClient) test.context.getBean("exampleClient"); + + example.sendAndReceive(); + } +} diff --git a/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java index 8a1acda..d423e5e 100644 --- a/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java +++ b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java @@ -9,45 +9,32 @@ import org.springframework.ws.server.endpoint.annotation.ResponsePayload; import de.spring.webservices.auto.ExampleRequest; import de.spring.webservices.auto.ExampleResponse; -import de.spring.webservices.porttypes.PortType; +import de.spring.webservices.operations.Operations; @Endpoint public class ExampleEndPoint { private static final String NAMESPACE_URI = "http://localhost:8888/spring-ws/example"; - private PortType.RequestResponse example; - + private Operations.RequestResponse example; + public ExampleEndPoint() {} - /*Este codigo debe ser escrito por los usuarios :(*/ - /*Los usuarios debe hacer lo siguiente en este proyecto: - * 1. Crearse sus propios xsds - * 2. Auto generar los objetos Request/Response asociados con sus xsds - * 3. Crear los tests de integracion - * 4. Generar este código y el setter para inyectar con Spring en este código - * la clase que implementa el interfaz WebService. Esta clase será implementada en un proyecto - * de negocio. - * - * Los usuarios deben hacer lo siguiente en sus proyectos: - * 1. Implementar la clase del interfaz WebService - * 2. Generar bean con dicha clase en su proyecto - * 3. Inyectar ese bean en el bean de esta clase (lo dicho en puntos 4 y 5) - * LOS USUARIOS TIENEN QUE HACER DEMASIADAS COSAS????? */ + @PayloadRoot(localPart = "ExampleRequest", namespace = NAMESPACE_URI) @ResponsePayload public ExampleResponse order( @RequestPayload final ExampleRequest requestObject, @RequestPayload final Element element, final MessageContext messageContext) { - - return example.requestResponse(requestObject); + + return example.requestResponse(requestObject); } - + /** Setter required by Spring **/ public void setExample( - PortType.RequestResponse example) { + final Operations.RequestResponse example) { this.example = example; } } diff --git a/src/main/java/de/spring/webservices/operations/Operations.java b/src/main/java/de/spring/webservices/operations/Operations.java new file mode 100644 index 0000000..13b5113 --- /dev/null +++ b/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/src/main/java/de/spring/webservices/operations/Request.java b/src/main/java/de/spring/webservices/operations/Request.java new file mode 100644 index 0000000..77d81f4 --- /dev/null +++ b/src/main/java/de/spring/webservices/operations/Request.java @@ -0,0 +1,5 @@ +package de.spring.webservices.operations; + +public interface Request { + +} diff --git a/src/main/java/de/spring/webservices/operations/Response.java b/src/main/java/de/spring/webservices/operations/Response.java new file mode 100644 index 0000000..3a2cbea --- /dev/null +++ b/src/main/java/de/spring/webservices/operations/Response.java @@ -0,0 +1,5 @@ +package de.spring.webservices.operations; + +public interface Response { + +} diff --git a/src/main/java/de/spring/webservices/porttypes/PortType.java b/src/main/java/de/spring/webservices/porttypes/PortType.java deleted file mode 100644 index d0e7d1f..0000000 --- a/src/main/java/de/spring/webservices/porttypes/PortType.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.spring.webservices.porttypes; - -/** - *

- * WSDL 1.1 Port Types - *

- *

- * WSDL 2.0 is different, so this interface just works with 1.1. Indeed I should - * not implement this interface because of the differences between 2.0 and 1.1 but I - * am doing it because I want to improve my skills related to Java Generics. - *

- * See: http://www.w3.org/TR/wsdl# - * _porttypes - * - */ -public interface PortType { - - /** - *

- * Request-response operation - *

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

- * One-way operation - *

- * 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 - *

- * See: http://www.w3.org/TR - * /wsdl#_notification - * - * @param - * Describes {@link Response} - * @param - * Describes {@link Request} - */ - public interface Notification { - T notification(); - } -} diff --git a/src/main/java/de/spring/webservices/porttypes/Request.java b/src/main/java/de/spring/webservices/porttypes/Request.java deleted file mode 100644 index dbc29e7..0000000 --- a/src/main/java/de/spring/webservices/porttypes/Request.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.spring.webservices.porttypes; - -public interface Request { - -} diff --git a/src/main/java/de/spring/webservices/porttypes/Response.java b/src/main/java/de/spring/webservices/porttypes/Response.java deleted file mode 100644 index 797d946..0000000 --- a/src/main/java/de/spring/webservices/porttypes/Response.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.spring.webservices.porttypes; - -public interface Response { - -} diff --git a/src/main/resources/client-spring-configuration.xml b/src/main/resources/client-spring-configuration.xml new file mode 100644 index 0000000..83c6910 --- /dev/null +++ b/src/main/resources/client-spring-configuration.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/spring-configuration.xml b/src/main/resources/spring-configuration.xml index b222b49..c7a3ffd 100644 --- a/src/main/resources/spring-configuration.xml +++ b/src/main/resources/spring-configuration.xml @@ -4,15 +4,27 @@ xmlns:context="http://www.springframework.org/schema/context" xmlns:sws="http://www.springframework.org/schema/web-services" xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + http://www.springframework.org/schema/context/spring-context-3.1.xsd"> + + @@ -52,18 +72,4 @@ - - - - - - - - - - - - - - diff --git a/src/main/resources/wsdl/example.wsdl b/src/main/resources/wsdl/example.wsdl index 755803e..8a75ff5 100644 --- a/src/main/resources/wsdl/example.wsdl +++ b/src/main/resources/wsdl/example.wsdl @@ -8,7 +8,7 @@ - de.spring.webservices.porttypes.Request + de.spring.webservices.operations.Request @@ -20,7 +20,7 @@ - de.spring.webservices.porttypes.Response + de.spring.webservices.operations.Response diff --git a/src/main/resources/xsd/examples.xsd b/src/main/resources/xsd/examples.xsd index 60acae6..897d024 100644 --- a/src/main/resources/xsd/examples.xsd +++ b/src/main/resources/xsd/examples.xsd @@ -14,7 +14,7 @@ - de.spring.webservices.porttypes.Request + de.spring.webservices.operations.Request @@ -26,7 +26,7 @@ - de.spring.webservices.porttypes.Response + de.spring.webservices.operations.Response diff --git a/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java b/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java deleted file mode 100644 index 4c102c6..0000000 --- a/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.spring.webservices.tests; - -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("/spring-configuration.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)); - } -} diff --git a/src/test/java/de/spring/webservices/tests/client/ExampleClientIntegrationTest.java b/src/test/java/de/spring/webservices/tests/client/ExampleClientIntegrationTest.java new file mode 100644 index 0000000..db51938 --- /dev/null +++ b/src/test/java/de/spring/webservices/tests/client/ExampleClientIntegrationTest.java @@ -0,0 +1,48 @@ +package de.spring.webservices.tests.client; + +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.test.client.MockWebServiceServer; +import org.springframework.xml.transform.StringSource; + +import de.spring.webservices.client.ExampleClient; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("/client-spring-configuration.xml") +public class ExampleClientIntegrationTest { + + @Autowired + private ExampleClient client; + + private MockWebServiceServer mockServer; + + @Before + public void createServer() throws Exception { + // mockServer = MockWebServiceServer.createServer(client); + } + + @Test + public void customerClient() throws Exception { + final Source requestPayload = new StringSource( + "" + + "SCARLETT. IT IS CANON." + + ""); + final Source responsePayload = new StringSource( + "" + + "SNAKE EYES AND SCARLETT. IT IS CANON." + + ""); + mockServer.expect(payload(requestPayload)).andRespond( + withPayload(responsePayload)); + + mockServer.verify(); + } +} diff --git a/src/test/java/de/spring/webservices/tests/server/ExampleEndPointIntegrationTest.java b/src/test/java/de/spring/webservices/tests/server/ExampleEndPointIntegrationTest.java new file mode 100644 index 0000000..ee41c24 --- /dev/null +++ b/src/test/java/de/spring/webservices/tests/server/ExampleEndPointIntegrationTest.java @@ -0,0 +1,45 @@ +package de.spring.webservices.tests.server; + +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("/spring-configuration.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)); + } +} -- 2.1.4