A lot of changes.
authorgumartinm <gustavo@gumartinm.name>
Thu, 8 Nov 2012 01:07:25 +0000 (02:07 +0100)
committergumartinm <gustavo@gumartinm.name>
Thu, 8 Nov 2012 01:07:25 +0000 (02:07 +0100)
Client and server code auto generation.
Server integration tests.
Launching Jetty using a maven plugin.

17 files changed:
pom.xml
src/main/java/de/spring/webservices/business/BusinessExample.java [new file with mode: 0644]
src/main/java/de/spring/webservices/client/ExampleClient.java [new file with mode: 0644]
src/main/java/de/spring/webservices/endpoints/ExampleEndPoint.java [new file with mode: 0644]
src/main/java/de/spring/webservices/porttypes/PortType.java [new file with mode: 0644]
src/main/java/de/spring/webservices/porttypes/Request.java [new file with mode: 0644]
src/main/java/de/spring/webservices/porttypes/Response.java [new file with mode: 0644]
src/main/java/de/spring/webservices/service/TestService.java [deleted file]
src/main/java/de/spring/webservices/ws/HolidayEndpoint.java [deleted file]
src/main/resources/log4j.properties [new file with mode: 0644]
src/main/resources/spring-configuration.xml [new file with mode: 0644]
src/main/resources/wsdl/example.wsdl [new file with mode: 0644]
src/main/resources/xsd/examples.xsd [new file with mode: 0644]
src/main/webapp/WEB-INF/spring-ws-servlet.xml
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/xsd/messages.xsd [deleted file]
src/test/java/de/spring/webservices/tests/ExampleEndPointIntegrationTest.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index b2b904f..3486faa 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-       <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>    
        <groupId>de.spring.webservices</groupId>
        <artifactId>web-services-spring</artifactId>
        <version>1</version>
                <name>Gustavo Martin Inc.</name>
                <url>http://www.gumartinm.name</url>
        </organization>
-
-    <distributionManagement>
-        <repository>
-            <id>gumartinm-releases</id>
-            <name>gumartinm-releases</name>
-            <url>http://gumartinm.name/artifactory</url>
-        </repository>
-        <snapshotRepository>
-            <id>gumartinm-snapshots-releases</id>
-            <name>gumartinm-snapshots-releases</name>
-            <url>http://gumartinm.name/artifactory</url>
-        </snapshotRepository>
-        <site>
-            <id>gumartinm</id>
-            <url>file:///opt/javadoc</url>
-        </site>
-    </distributionManagement>
-
-
+       
        <scm>
-               <developerConnection>scm:git:http://git.gumartinm.name/web-services-spring</developerConnection>
-               <url>http://git.gumartinm.name/web-services-spring</url>
-       </scm>
+        <developerConnection>scm:git:http://git.gumartinm.name/SpringWebServicesForFun</developerConnection>
+        <url>http://git.gumartinm.name/SpringWebServicesForFun</url>
+    </scm>
        
        <properties>
-               <!-- Listado con las versiones de los proyectos de Arquitectura -->
-               <spring.ws.version>2.1.0.RELEASE</spring.ws.version>
+        <project.xsd.schemas.source.path>src/main/resources/xsd</project.xsd.schemas.source.path>
+        <project.xsd.schemas.target.path>${basedir}/target/generated-sources/src/main/java</project.xsd.schemas.target.path>
+        <project.xsd.schemas.package.name>de.spring.webservices.auto</project.xsd.schemas.package.name>
+        <project.wsdl.sources.path>src/main/resources/wsdl</project.wsdl.sources.path>
+        <spring.ws.version>2.1.0.RELEASE</spring.ws.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <spring.version>3.1.1.RELEASE</spring.version>
-       </properties>
+        <warTarget>${basedir}/target/jetty</warTarget>
+    </properties>
+       
 
        <dependencies>
                        <dependency>
                                <version>${spring.ws.version}</version>                                                 
                        </dependency>
                        <dependency>
+                <groupId>org.springframework.ws</groupId>
+                <artifactId>spring-ws-test</artifactId>
+                <version>${spring.ws.version}</version>
+                <scope>test</scope>                        
+            </dependency>
+                       <dependency>
                                <groupId>org.jdom</groupId>
                                <artifactId>jdom</artifactId>
                                <version>2.0.1</version>
             <version>4.10</version>
             <scope>test</scope>
         </dependency>
+        
+        <!-- Required by jaxb2-basics as specified: 
+            http://confluence.highsource.org/display/J2B/Using+JAXB2+Basics+Plugins+with+CXF
+         -->
+        <dependency>
+            <groupId>org.jvnet.jaxb2_commons</groupId>
+            <artifactId>jaxb2-basics-runtime</artifactId>
+            <version>0.6.3</version>
+        </dependency>
        </dependencies>
        <build>
+          <pluginManagement>
+            <plugins>
+                <!-- Generate code from xsd files -->
+                <plugin>
+                    <groupId>org.apache.cxf</groupId>
+                    <artifactId>cxf-xjc-plugin</artifactId>
+                    <version>2.3.0</version>
+                </plugin>
+                <!-- Generate code from wsdl files (the client's code) -->
+                <plugin>
+                    <groupId>org.apache.cxf</groupId>
+                    <artifactId>cxf-codegen-plugin</artifactId>
+                    <version>2.3.0</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>build-helper-maven-plugin</artifactId>
+                    <version>1.1</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.mortbay.jetty</groupId>
+                    <artifactId>maven-jetty-plugin</artifactId>
+                    <version>6.1.14</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-war-plugin</artifactId>
+                    <version>2.1-alpha-2</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                     </archive>
                 </configuration>
             </plugin>
-        </plugins>
-               <pluginManagement>
-                       <plugins>
-                               <plugin>
-                                       <groupId>org.apache.cxf</groupId>
-                                       <artifactId>cxf-xjc-plugin</artifactId>
-                                       <version>2.3.0</version>
-                               </plugin>
-                               <plugin>
-                                       <groupId>org.apache.cxf</groupId>
-                                       <artifactId>cxf-codegen-plugin</artifactId>
-                                       <version>2.3.0</version>
-                               </plugin>
-                               <plugin>
-                                       <groupId>org.codehaus.mojo</groupId>
-                                       <artifactId>build-helper-maven-plugin</artifactId>
-                                       <version>1.1</version>
-                               </plugin>
-                <plugin>
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-war-plugin</artifactId>
-                    <version>2.1.1</version>
-                </plugin>
-                       </plugins>
-               </pluginManagement>
+            
+            <!-- We could use maven-jaxb2-plugin in order to generate Java classes from XSD files but
+                this plugin seems more useful so, I keep using it. Besides, it is based on Apache CXF which
+                as well, uses jaxb. -->
+            <plugin>
+                <groupId>org.apache.cxf</groupId>
+                <artifactId>cxf-xjc-plugin</artifactId>
+                <configuration>
+                    <extensions>
+                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
+                    </extensions>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>generate-sources-from-xsd</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>xsdtojava</goal>
+                        </goals>
+                        <configuration>
+                            <sourceRoot>${project.xsd.schemas.target.path}</sourceRoot>
+                            <xsdOptions>
+                                <xsdOption>
+                                    <extension>true</extension>
+                                    <xsd>${project.xsd.schemas.source.path}/examples.xsd</xsd>
+                                    <packagename>${project.xsd.schemas.package.name}</packagename>
+                                    <extensionArgs>
+                                        <extraarg>-Xinheritance</extraarg>
+                                     </extensionArgs> 
+                                </xsdOption>
+                            </xsdOptions>
+                        </configuration>
+                    </execution>
+                </executions>
+                <!-- We make this plugin work with this jaxb2 version.
+                     This particular version let us generate inherited classes using
+                     the -Xinheritance argument. -->
+                <dependencies>
+                    <dependency>
+                        <groupId>org.jvnet.jaxb2_commons</groupId>
+                        <artifactId>jaxb2-basics</artifactId>
+                        <version>0.6.3</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+            
+            <!-- We could use maven-jaxb2-plugin in order to generate Java classes from WSDL files but
+                this plugin seems more useful so, I keep using it. Besides, it is based on Apache CXF which
+                as well, uses jaxb. -->
+            <plugin>
+                <groupId>org.apache.cxf</groupId>
+                <artifactId>cxf-codegen-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-sources-from-wsdl</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>wsdl2java</goal>
+                        </goals>
+                        <configuration>
+                            <sourceRoot>${project.xsd.schemas.target.path}</sourceRoot>
+                            <wsdlOptions>
+                                <wsdlOption>
+                                    <wsdl>${project.wsdl.sources.path}/example.wsdl</wsdl>
+                                    <extraargs>
+                                        <extraarg>-xjc-Xinheritance</extraarg>
+                                    </extraargs>
+                                </wsdlOption>
+                            </wsdlOptions>
+                        </configuration>
+                     </execution>
+                </executions>
+                <!-- We make this plugin work with this jaxb2 version.
+                     This particular version let us generate inherited classes using
+                     the -xjc-Xinheritance argument. -->
+                <dependencies>
+                    <dependency>
+                        <groupId>org.jvnet.jaxb2_commons</groupId>
+                        <artifactId>jaxb2-basics</artifactId>
+                        <version>0.6.3</version>
+                    </dependency>
+                </dependencies>
+            </plugin> 
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>${project.xsd.schemas.target.path}</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.mortbay.jetty</groupId>
+                <artifactId>maven-jetty-plugin</artifactId>
+                <configuration>
+                    <webAppConfig>
+                        <contextPath>/</contextPath>
+                        <baseResource implementation="org.mortbay.resource.ResourceCollection">
+                            <resourcesAsCSV>
+                                ${basedir}/src/main/webapp,
+                                ${warTarget}
+                            </resourcesAsCSV>
+                        </baseResource>
+                    </webAppConfig>
+                    <connectors>
+                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+                            <port>8888</port>
+                            <maxIdleTime>60000</maxIdleTime>
+                        </connector>
+                    </connectors>
+                    <scanIntervalSeconds>3</scanIntervalSeconds>
+                    <scanTargets>
+                        <scanTarget>${warTarget}</scanTarget>
+                    </scanTargets>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <configuration>
+                    <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
+                    <webappDirectory>${warTarget}</webappDirectory>
+                    <warName>${project.artifactId}</warName>
+                </configuration>
+            </plugin>
+        </plugins>     
        </build>
 </project>
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 (file)
index 0000000..9590c7d
--- /dev/null
@@ -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<ExampleResponse, ExampleRequest> {
+
+    @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 (file)
index 0000000..2612b07
--- /dev/null
@@ -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 (file)
index 0000000..8a1acda
--- /dev/null
@@ -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<ExampleResponse, ExampleRequest> 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<ExampleResponse, ExampleRequest> 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 (file)
index 0000000..da73454
--- /dev/null
@@ -0,0 +1,50 @@
+package de.spring.webservices.porttypes;
+
+/**
+ * <p>
+ * WSDL Port Types
+ * </p>
+ * See: <a href="http://www.w3.org/TR/wsdl#_porttypes">http://www.w3.org/TR/wsdl#_porttypes</a>
+ *
+ */
+public interface PortType<E extends Request, T extends Response> {
+
+    /**
+     * <p>
+     * Request-response operation
+     * </p>
+     * See: <a href="http://www.w3.org/TR/wsdl#_request-response">http://www.w3.org/TR/wsdl#_request-response</a>
+     *
+     * @param <T> Describes {@link Response}
+     * @param <E> Describes {@link Request}
+     */
+    public interface RequestResponse<T, E> {
+        T requestResponse (E request);
+    }
+    
+    /**
+     * <p>
+     * One-way operation
+     * </p>
+     * See: <a href="http://www.w3.org/TR/wsdl#_one-way">http://www.w3.org/TR/wsdl#_one-way</a>
+     *
+     * @param <T> Describes {@link Response}
+     * @param <E> Describes {@link Request}
+     */
+    public interface OneWay<E> {
+        void oneWay (E request);
+    }
+    
+    /**
+     * <p>
+     * Notification operation
+     * </p>
+     * See: <a href="http://www.w3.org/TR/wsdl#_notification">http://www.w3.org/TR/wsdl#_notification</a>
+     *
+     * @param <T> Describes {@link Response}
+     * @param <E> Describes {@link Request}
+     */
+    public interface Notification<T> {
+        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 (file)
index 0000000..dbc29e7
--- /dev/null
@@ -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 (file)
index 0000000..797d946
--- /dev/null
@@ -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 (file)
index 82db9be..0000000
+++ /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 (file)
index 216f484..0000000
+++ /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 (file)
index 0000000..999a154
--- /dev/null
@@ -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 (file)
index 0000000..b222b49
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  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/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">
+
+
+    <context:component-scan base-package="de.spring.webservices"/>
+
+    <sws:annotation-driven/>
+    
+    <sws:dynamic-wsdl id="example"
+            portTypeName="Examples"
+            locationUri="/spring-ws/example">
+        <sws:xsd location="classpath:xsd/examples.xsd"/>
+    </sws:dynamic-wsdl>
+    
+    <sws:interceptors>
+        <bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor">
+            <property name="logRequest" value="true"/>
+            <property name="logResponse" value="true"/>
+        </bean>
+    </sws:interceptors>
+    
+    <bean id="validatingInterceptor" 
+        class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
+        <property name="schema" value="classpath:xsd/examples.xsd"/>
+        <property name="validateRequest" value="false"/>
+        <property name="validateResponse" value="true"/>
+    </bean>
+    
+    <bean id="exceptionResolver"
+        class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
+        <property name="defaultFault" value="SERVER"/>
+        <property name="exceptionMappings">
+            <value>
+                org.springframework.oxm.ValidationFailureException=CLIENT,Invalid request
+            </value>
+        </property>
+    </bean>
+    
+    <bean id="exampleBusiness" class="de.spring.webservices.business.BusinessExample">
+    </bean>
+    
+    <bean id="exampleEndPoint" class="de.spring.webservices.endpoints.ExampleEndPoint" >
+        <property name="example" ref="exampleBusiness" />  
+    </bean>
+    
+    
+    <!-- CLIENT  -->
+    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
+
+    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
+        <constructor-arg ref="messageFactory"/>
+        <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
+    </bean>
+    
+    <bean id="exampleClient" class="de.spring.webservices.client.ExampleClient">
+        <property name="webServiceTemplate" ref="webServiceTemplate"/>
+        <property name="defaultUri" value="http://localhost:8888/spring-ws/example"/>
+    </bean>
+    
+</beans>
diff --git a/src/main/resources/wsdl/example.wsdl b/src/main/resources/wsdl/example.wsdl
new file mode 100644 (file)
index 0000000..755803e
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://localhost:8888/spring-ws/example" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8888/spring-ws/example" targetNamespace="http://localhost:8888/spring-ws/example">
+  <wsdl:types>
+    <xs:schema xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" jaxb:extensionBindingPrefixes="inheritance" jaxb:version="2.1" targetNamespace="http://localhost:8888/spring-ws/example">
+       
+
+       <xs:element name="ExampleRequest">
+          <xs:complexType>
+              <xs:annotation>
+                <xs:appinfo>
+                    <inheritance:implements>de.spring.webservices.porttypes.Request</inheritance:implements>
+                </xs:appinfo>
+            </xs:annotation>   
+            <xs:all>
+                <xs:element name="data" type="xs:string"/>
+            </xs:all>
+        </xs:complexType>
+       </xs:element>
+    <xs:element name="ExampleResponse">
+        <xs:complexType>
+        <xs:annotation>
+                <xs:appinfo>
+                    <inheritance:implements>de.spring.webservices.porttypes.Response</inheritance:implements>
+                </xs:appinfo>
+            </xs:annotation>  
+            <xs:all>
+                <xs:element name="data" type="xs:string"/>
+            </xs:all>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>
+  </wsdl:types>
+  <wsdl:message name="ExampleRequest">
+    <wsdl:part element="tns:ExampleRequest" name="ExampleRequest">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:message name="ExampleResponse">
+    <wsdl:part element="tns:ExampleResponse" name="ExampleResponse">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:portType name="Examples">
+    <wsdl:operation name="Example">
+      <wsdl:input message="tns:ExampleRequest" name="ExampleRequest">
+    </wsdl:input>
+      <wsdl:output message="tns:ExampleResponse" name="ExampleResponse">
+    </wsdl:output>
+    </wsdl:operation>
+  </wsdl:portType>
+  <wsdl:binding name="ExamplesSoap11" type="tns:Examples">
+    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+    <wsdl:operation name="Example">
+      <soap:operation soapAction=""/>
+      <wsdl:input name="ExampleRequest">
+        <soap:body use="literal"/>
+      </wsdl:input>
+      <wsdl:output name="ExampleResponse">
+        <soap:body use="literal"/>
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+  <wsdl:service name="ExamplesService">
+    <wsdl:port binding="tns:ExamplesSoap11" name="ExamplesSoap11">
+      <soap:address location="http://localhost:8888/spring-ws/example"/>
+    </wsdl:port>
+  </wsdl:service>
+</wsdl:definitions>
\ 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 (file)
index 0000000..60acae6
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
+    jaxb:version="2.1"
+    jaxb:extensionBindingPrefixes="inheritance"
+    elementFormDefault="qualified"
+    targetNamespace="http://localhost:8888/spring-ws/example">
+       
+
+       <xs:element name="ExampleRequest">
+          <xs:complexType>
+              <xs:annotation>
+                <xs:appinfo>
+                    <inheritance:implements>de.spring.webservices.porttypes.Request</inheritance:implements>
+                </xs:appinfo>
+            </xs:annotation>   
+            <xs:all>
+                <xs:element name="data" type="xs:string" />
+            </xs:all>
+        </xs:complexType>
+       </xs:element>
+    <xs:element name="ExampleResponse">
+        <xs:complexType>
+        <xs:annotation>
+                <xs:appinfo>
+                    <inheritance:implements>de.spring.webservices.porttypes.Response</inheritance:implements>
+                </xs:appinfo>
+            </xs:annotation>  
+            <xs:all>
+                <xs:element name="data" type="xs:string" />
+            </xs:all>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>
index 43e9e57..88b4eb1 100644 (file)
@@ -1,29 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  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/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">
-
-
-    <context:component-scan base-package="de.spring.webservices"/>
-
-    <sws:annotation-driven/>
-    
-    <sws:dynamic-wsdl id="orders"
-            portTypeName="Orders"
-            locationUri="http://localhost:8080/ordersService/">
-        <sws:xsd location="/WEB-INF/xsd/messages.xsd"/>
-    </sws:dynamic-wsdl>
-
-    <bean id="testService" class="de.spring.webservices.service.TestService">
-
-    </bean>
-
-    
+       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">
+       
+       <import resource="classpath:spring-configuration.xml"/>
+       
 </beans>
index f455591..2789794 100644 (file)
@@ -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">
 
-    <display-name>Archetype Created Web Application</display-name>
+    <display-name>Spring Web Services: example</display-name>
 
     <servlet>
         <servlet-name>spring-ws</servlet-name>
@@ -18,7 +18,7 @@
 
     <servlet-mapping>
         <servlet-name>spring-ws</servlet-name>
-        <url-pattern>/*</url-pattern>
+        <url-pattern>/spring-ws/*</url-pattern>
     </servlet-mapping>
     
 
diff --git a/src/main/webapp/WEB-INF/xsd/messages.xsd b/src/main/webapp/WEB-INF/xsd/messages.xsd
deleted file mode 100644 (file)
index 33b9613..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       xmlns:pos="http://localhost:8080/spring-ws/orders"
-       elementFormDefault="qualified"
-       targetNamespace="http://localhost:8080/spring-ws/orders">
-
-       <xs:element name="GetOrdersRequest">
-       </xs:element>
-    <xs:element name="GetOrdersResponse">
-        <xs:sequence>
-            <xs:all>
-                <xs:element name="data" type="xs:string" />
-            </xs:all>
-        </xs:sequence>
-    </xs:element>
-</xs:schema>
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 (file)
index 0000000..8ae72c2
--- /dev/null
@@ -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(
+               "<ExampleRequest xmlns='http://localhost:8888/spring-ws/example'>" +
+                       "<data>Houston</data>" +
+            "</ExampleRequest>");
+      Source responsePayload = new StringSource(
+              "<ns2:ExampleResponse xmlns:ns2='http://localhost:8888/spring-ws/example'>" +
+              "     <ns2:data>SNAKE EYES AND Houston</ns2:data>" +
+              "</ns2:ExampleResponse>");
+      mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload));
+    }
+}