Trying to implement web services with Spring.
authorgumartinm <gustavo@gumartinm.name>
Sun, 4 Nov 2012 23:43:12 +0000 (00:43 +0100)
committergumartinm <gustavo@gumartinm.name>
Sun, 4 Nov 2012 23:43:12 +0000 (00:43 +0100)
pom.xml [new file with mode: 0644]
src/main/java/de/spring/webservices/service/TestService.java [new file with mode: 0644]
src/main/java/de/spring/webservices/ws/HolidayEndpoint.java [new file with mode: 0644]
src/main/webapp/WEB-INF/spring-ws-servlet.xml [new file with mode: 0644]
src/main/webapp/WEB-INF/web.xml [new file with mode: 0644]
src/main/webapp/WEB-INF/xsd/messages.xsd [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..b2b904f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,256 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+       <groupId>de.spring.webservices</groupId>
+       <artifactId>web-services-spring</artifactId>
+       <version>1</version>
+       <name>web-services-spring</name>
+       <url>http://www.gumartinm.name</url>
+       <description>Web Services Spring Framework</description>
+       <organization>
+               <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>
+       
+       <properties>
+               <!-- Listado con las versiones de los proyectos de Arquitectura -->
+               <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>
+
+       <dependencies>
+                       <dependency>
+                               <groupId>org.springframework.ws</groupId>
+                               <artifactId>spring-ws-core</artifactId>
+                               <version>${spring.ws.version}</version>                         
+                       </dependency>
+                       <dependency>
+                               <groupId>org.springframework.ws</groupId>
+                               <artifactId>spring-xml</artifactId>
+                               <version>${spring.ws.version}</version>                                                 
+                       </dependency>
+                       <dependency>
+                               <groupId>org.jdom</groupId>
+                               <artifactId>jdom</artifactId>
+                               <version>2.0.1</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>com.sun.xml.ws</groupId>
+                               <artifactId>jaxws-rt</artifactId>
+                               <version>2.2.5</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>jaxen</groupId>
+                               <artifactId>jaxen</artifactId>
+                               <version>1.1.3</version>
+                               <exclusions>
+                                       <exclusion>
+                                               <artifactId>maven-cobertura-plugin</artifactId>
+                                               <groupId>maven-plugins</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>maven-findbugs-plugin</artifactId>
+                                               <groupId>maven-plugins</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>xml-apis</artifactId>
+                                               <groupId>xml-apis</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>dom4j</artifactId>
+                                               <groupId>dom4j</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>jdom</artifactId>
+                                               <groupId>jdom</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>xom</artifactId>
+                                               <groupId>xom</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>xmlParserAPIs</artifactId>
+                                               <groupId>xerces</groupId>
+                                       </exclusion>
+                                       <exclusion>
+                                               <artifactId>xercesImpl</artifactId>
+                                               <groupId>xerces</groupId>
+                                       </exclusion>
+                               </exclusions>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.mortbay.jetty</groupId>
+                               <artifactId>jsp-2.1</artifactId>
+                               <version>6.1.14</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.mortbay.jetty</groupId>
+                               <artifactId>jsp-api-2.1</artifactId>
+                               <version>6.1.14</version>
+                       </dependency>
+                       <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-continuation</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-http</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-io</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-security</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlet</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-util</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-xml</artifactId>
+            <version>7.0.0.v20091005</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.10</version>
+            <scope>test</scope>
+        </dependency>
+       </dependencies>
+       <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.0.2</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.6</version>
+                <configuration>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <version>2.6</version>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>jdepend-maven-plugin</artifactId>
+                <version>2.0-beta-2</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.4.2</version>
+                <configuration>
+                    <testFailureIgnore>true</testFailureIgnore>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.3.1</version>
+                <configuration>
+                    <archive>
+                        <manifestEntries>
+                            <Specification-Title>${project.description}</Specification-Title>
+                            <Specification-Version>${project.version}</Specification-Version>
+                            <Specification-Vendor>${project.organization.name}</Specification-Vendor>
+                            <Implementation-Title>${project.description}</Implementation-Title>
+                            <Implementation-Version>${project.version}</Implementation-Version>
+                            <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+                        </manifestEntries>
+                    </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>
+       </build>
+</project>
diff --git a/src/main/java/de/spring/webservices/service/TestService.java b/src/main/java/de/spring/webservices/service/TestService.java
new file mode 100644 (file)
index 0000000..82db9be
--- /dev/null
@@ -0,0 +1,13 @@
+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
new file mode 100644 (file)
index 0000000..216f484
--- /dev/null
@@ -0,0 +1,46 @@
+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/webapp/WEB-INF/spring-ws-servlet.xml b/src/main/webapp/WEB-INF/spring-ws-servlet.xml
new file mode 100644 (file)
index 0000000..43e9e57
--- /dev/null
@@ -0,0 +1,29 @@
+<?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>
+
+    
+</beans>
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..f455591
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         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>
+
+    <servlet>
+        <servlet-name>spring-ws</servlet-name>
+        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+        <init-param>
+            <param-name>transformWsdlLocations</param-name>
+            <param-value>true</param-value>
+        </init-param>
+    </servlet>
+
+
+    <servlet-mapping>
+        <servlet-name>spring-ws</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+    
+
+</web-app>
diff --git a/src/main/webapp/WEB-INF/xsd/messages.xsd b/src/main/webapp/WEB-INF/xsd/messages.xsd
new file mode 100644 (file)
index 0000000..33b9613
--- /dev/null
@@ -0,0 +1,17 @@
+<?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>