From: gumartinm Date: Thu, 8 Nov 2012 01:07:25 +0000 (+0100) Subject: A lot of changes. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=4cdfe4738e22a7c7a4033a09a92aae689c993130;p=SpringWebServicesForFun%2F.git A lot of changes. Client and server code auto generation. Server integration tests. Launching Jetty using a maven plugin. --- diff --git a/pom.xml b/pom.xml index b2b904f..3486faa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ - 4.0.0 + 4.0.0 de.spring.webservices web-services-spring 1 @@ -13,36 +13,23 @@ Gustavo Martin Inc. http://www.gumartinm.name - - - - gumartinm-releases - gumartinm-releases - http://gumartinm.name/artifactory - - - gumartinm-snapshots-releases - gumartinm-snapshots-releases - http://gumartinm.name/artifactory - - - gumartinm - file:///opt/javadoc - - - - + - scm:git:http://git.gumartinm.name/web-services-spring - http://git.gumartinm.name/web-services-spring - + scm:git:http://git.gumartinm.name/SpringWebServicesForFun + http://git.gumartinm.name/SpringWebServicesForFun + - - 2.1.0.RELEASE + src/main/resources/xsd + ${basedir}/target/generated-sources/src/main/java + de.spring.webservices.auto + src/main/resources/wsdl + 2.1.0.RELEASE UTF-8 3.1.1.RELEASE - + ${basedir}/target/jetty + + @@ -56,6 +43,12 @@ ${spring.ws.version} + org.springframework.ws + spring-ws-test + ${spring.ws.version} + test + + org.jdom jdom 2.0.1 @@ -170,8 +163,48 @@ 4.10 test + + + + org.jvnet.jaxb2_commons + jaxb2-basics-runtime + 0.6.3 + + + + + + org.apache.cxf + cxf-xjc-plugin + 2.3.0 + + + + org.apache.cxf + cxf-codegen-plugin + 2.3.0 + + + org.codehaus.mojo + build-helper-maven-plugin + 1.1 + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.14 + + + org.apache.maven.plugins + maven-war-plugin + 2.1-alpha-2 + + + org.apache.maven.plugins @@ -227,30 +260,141 @@ - - - - - org.apache.cxf - cxf-xjc-plugin - 2.3.0 - - - org.apache.cxf - cxf-codegen-plugin - 2.3.0 - - - org.codehaus.mojo - build-helper-maven-plugin - 1.1 - - - org.apache.maven.plugins - maven-war-plugin - 2.1.1 - - - + + + + org.apache.cxf + cxf-xjc-plugin + + + org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0 + + + + + generate-sources-from-xsd + generate-sources + + xsdtojava + + + ${project.xsd.schemas.target.path} + + + true + ${project.xsd.schemas.source.path}/examples.xsd + ${project.xsd.schemas.package.name} + + -Xinheritance + + + + + + + + + + org.jvnet.jaxb2_commons + jaxb2-basics + 0.6.3 + + + + + + + org.apache.cxf + cxf-codegen-plugin + + + generate-sources-from-wsdl + generate-sources + + wsdl2java + + + ${project.xsd.schemas.target.path} + + + ${project.wsdl.sources.path}/example.wsdl + + -xjc-Xinheritance + + + + + + + + + + org.jvnet.jaxb2_commons + jaxb2-basics + 0.6.3 + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-source + generate-sources + + add-source + + + + ${project.xsd.schemas.target.path} + + + + + + + org.mortbay.jetty + maven-jetty-plugin + + + / + + + ${basedir}/src/main/webapp, + ${warTarget} + + + + + + 8888 + 60000 + + + 3 + + ${warTarget} + + + + + org.apache.maven.plugins + maven-war-plugin + + ${basedir}/src/main/webapp + ${warTarget} + ${project.artifactId} + + + diff --git a/src/main/java/de/spring/webservices/business/BusinessExample.java b/src/main/java/de/spring/webservices/business/BusinessExample.java new file mode 100644 index 0000000..9590c7d --- /dev/null +++ b/src/main/java/de/spring/webservices/business/BusinessExample.java @@ -0,0 +1,23 @@ +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; + +/** + * Example of business class + * + */ +public class BusinessExample implements PortType.RequestResponse { + + @Override + public ExampleResponse requestResponse(ExampleRequest request) { + final ExampleResponse response = new ObjectFactory().createExampleResponse(); + + response.setData("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 new file mode 100644 index 0000000..2612b07 --- /dev/null +++ b/src/main/java/de/spring/webservices/client/ExampleClient.java @@ -0,0 +1,54 @@ +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.ExampleResponse; +import localhost._8888.spring_ws.example.Examples; +import localhost._8888.spring_ws.example.ExamplesService; +import localhost._8888.spring_ws.example.ExampleRequest; + +public class ExampleClient { + private WebServiceTemplate webServiceTemplate; + private String Uri; + + + public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) { + this.webServiceTemplate = webServiceTemplate; + } + + public void setDefaultUri(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); + + + this.webServiceTemplate.setDefaultUri(this.Uri); + ExampleResponse 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/endpoints/ExampleEndPoint.java b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java new file mode 100644 index 0000000..8a1acda --- /dev/null +++ b/src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java @@ -0,0 +1,53 @@ +package de.spring.webservices.endpoints; + +import org.jdom2.Element; +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.ExampleRequest; +import de.spring.webservices.auto.ExampleResponse; +import de.spring.webservices.porttypes.PortType; + + +@Endpoint +public class ExampleEndPoint { + private static final String NAMESPACE_URI = "http://localhost:8888/spring-ws/example"; + private PortType.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); + } + + + /** Setter required by Spring **/ + public void setExample( + PortType.RequestResponse example) { + this.example = example; + } +} diff --git a/src/main/java/de/spring/webservices/porttypes/PortType.java b/src/main/java/de/spring/webservices/porttypes/PortType.java new file mode 100644 index 0000000..da73454 --- /dev/null +++ b/src/main/java/de/spring/webservices/porttypes/PortType.java @@ -0,0 +1,50 @@ +package de.spring.webservices.porttypes; + +/** + *

+ * WSDL Port Types + *

+ * 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 new file mode 100644 index 0000000..dbc29e7 --- /dev/null +++ b/src/main/java/de/spring/webservices/porttypes/Request.java @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..797d946 --- /dev/null +++ b/src/main/java/de/spring/webservices/porttypes/Response.java @@ -0,0 +1,5 @@ +package de.spring.webservices.porttypes; + +public interface Response { + +} diff --git a/src/main/java/de/spring/webservices/service/TestService.java b/src/main/java/de/spring/webservices/service/TestService.java deleted file mode 100644 index 82db9be..0000000 --- a/src/main/java/de/spring/webservices/service/TestService.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.spring.webservices.service; - -public class TestService { - private String notification = "HOLA GUS"; - - public void setNotification(final String notification) { - this.notification = notification; - } - - public String getNotification() { - return this.notification; - } -} diff --git a/src/main/java/de/spring/webservices/ws/HolidayEndpoint.java b/src/main/java/de/spring/webservices/ws/HolidayEndpoint.java deleted file mode 100644 index 216f484..0000000 --- a/src/main/java/de/spring/webservices/ws/HolidayEndpoint.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.spring.webservices.ws; - -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.Namespace; -import org.jdom2.xpath.XPath; -import org.springframework.beans.factory.annotation.Autowired; -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.service.TestService; - - - -@Endpoint -public class HolidayEndpoint { - private static final String NAMESPACE_URI = "http://localhost:8080/spring-ws/orders"; - private final XPath notificationExpression; - private TestService testService = new TestService(); - - @Autowired - public HolidayEndpoint(final TestService testService) throws JDOMException { - this.testService = testService; - final Namespace namespace = Namespace.getNamespace("", NAMESPACE_URI); - notificationExpression = XPath.newInstance("//ord:GetOrdersRequest"); - notificationExpression.addNamespace(namespace); - } - - @PayloadRoot(localPart = "GetOrdersRequest", namespace = NAMESPACE_URI) - public void order(@RequestPayload final Element notificationRequest) throws Exception { - - final String notification = notificationExpression.valueOf(notificationRequest); - //humanResourceService.bookHoliday(startDate, endDate, name); - testService.setNotification(notification); - } - - - @PayloadRoot(localPart = "GetOrdersResponse", namespace = NAMESPACE_URI) - @ResponsePayload - public Element getOrder(@RequestPayload final Element element) { - return new Element("hola", Namespace.getNamespace("", NAMESPACE_URI)); - // testService.getNotification(); - } -} diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..999a154 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootLogger=WARN, stdout +log4j.logger.org.springframework.ws=INFO +log4j.logger.org.springframework.xml=INFO +log4j.logger.de.spring.webservices=INFO + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyyMMddHHmmssSSS} - %-5p - [%t] - %m%n diff --git a/src/main/resources/spring-configuration.xml b/src/main/resources/spring-configuration.xml new file mode 100644 index 0000000..b222b49 --- /dev/null +++ b/src/main/resources/spring-configuration.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.springframework.oxm.ValidationFailureException=CLIENT,Invalid request + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/wsdl/example.wsdl b/src/main/resources/wsdl/example.wsdl new file mode 100644 index 0000000..755803e --- /dev/null +++ b/src/main/resources/wsdl/example.wsdl @@ -0,0 +1,66 @@ + + + + + + + + + + + de.spring.webservices.porttypes.Request + + + + + + + + + + + + de.spring.webservices.porttypes.Response + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/xsd/examples.xsd b/src/main/resources/xsd/examples.xsd new file mode 100644 index 0000000..60acae6 --- /dev/null +++ b/src/main/resources/xsd/examples.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + de.spring.webservices.porttypes.Request + + + + + + + + + + + + de.spring.webservices.porttypes.Response + + + + + + + + diff --git a/src/main/webapp/WEB-INF/spring-ws-servlet.xml b/src/main/webapp/WEB-INF/spring-ws-servlet.xml index 43e9e57..88b4eb1 100644 --- a/src/main/webapp/WEB-INF/spring-ws-servlet.xml +++ b/src/main/webapp/WEB-INF/spring-ws-servlet.xml @@ -1,29 +1,9 @@ - - - - - - - - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index f455591..2789794 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> - Archetype Created Web Application + Spring Web Services: example spring-ws @@ -18,7 +18,7 @@ spring-ws - /* + /spring-ws/* diff --git a/src/main/webapp/WEB-INF/xsd/messages.xsd b/src/main/webapp/WEB-INF/xsd/messages.xsd deleted file mode 100644 index 33b9613..0000000 --- a/src/main/webapp/WEB-INF/xsd/messages.xsd +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java b/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java new file mode 100644 index 0000000..8ae72c2 --- /dev/null +++ b/src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java @@ -0,0 +1,44 @@ +package de.spring.webservices.tests; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.xml.transform.Source; + +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; +import static org.springframework.ws.test.server.RequestCreators.*; +import static org.springframework.ws.test.server.ResponseMatchers.*; + +@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 { + Source requestPayload = new StringSource( + "" + + "Houston" + + ""); + Source responsePayload = new StringSource( + "" + + " SNAKE EYES AND Houston" + + ""); + mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload)); + } +}