Moved Spring-WS to separate dir.

This commit is contained in:
Arjen Poutsma
2006-09-24 19:22:56 +00:00
commit 66d3aef26c
623 changed files with 44122 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<project name="spring-ws-airline-sample-saaj-client" default="build">
<property name="bin.dir" value="bin"/>
<property name="src.dir" value="src"/>
<target name="build">
<mkdir dir="${bin.dir}"/>
<javac srcdir="${src.dir}" destdir="${bin.dir}">
<classpath>
<pathelement location="lib/saaj-api.jar"/>
</classpath>
</javac>
</target>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="run" depends="echo"/>
<target name="echo" depends="build">
<java classname="org.springframework.ws.samples.echo.client.saaj.EchoClient" fork="true" failonerror="true">
<classpath>
<pathelement location="${bin.dir}"/>
<pathelement location="lib/saaj-api.jar"/>
<pathelement location="lib/saaj-impl.jar"/>
<pathelement location="lib/mail.jar"/>
<pathelement location="lib/activation.jar"/>
<pathelement location="lib/xercesImpl.jar"/>
</classpath>
</java>
</target>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,10 @@
SPRING WEB SERVICES
This directory contains a Java clients for the Echo Web Service that uses SAAJ: SOAP with Attachments API for Java. It
creates a SOAP message for the 'echo' operation, and sends it using SAAJ. This client does not use Spring-WS in any way.
SAJA Client Sample table of contents
---------------------------------------------------
* src - The source files for the client
* build.xml - Ant build file with a 'build' and a 'run' target

View File

@@ -0,0 +1,101 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.echo.client.saaj;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
/**
* A client for the Echo Web Service that uses SAAJ.
*
* @author Ben Ethridge
* @author Arjen Poutsma
*/
public class EchoClient {
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
public static final String PREFIX = "tns";
private SOAPConnectionFactory connectionFactory;
private MessageFactory messageFactory;
private URL url;
public EchoClient(String url) throws SOAPException, MalformedURLException {
connectionFactory = SOAPConnectionFactory.newInstance();
messageFactory = MessageFactory.newInstance();
this.url = new URL(url);
}
private SOAPMessage createEchoRequest() throws SOAPException {
SOAPMessage message = messageFactory.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoRequestName = envelope.createName("echoRequest", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoRequestElement = message.getSOAPBody()
.addBodyElement(echoRequestName);
echoRequestElement.setValue("Hello");
return message;
}
public void callWebService() throws SOAPException, IOException {
SOAPMessage request = createEchoRequest();
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(request, url);
if (!response.getSOAPBody().hasFault()) {
writeEchoResponse(response);
}
else {
SOAPFault fault = response.getSOAPBody().getFault();
System.err.println("Received SOAP Fault");
System.err.println("SOAP Fault Code :" + fault.getFaultCode());
System.err.println("SOAP Fault String :" + fault.getFaultString());
}
}
private void writeEchoResponse(SOAPMessage message) throws SOAPException {
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoResponseName = envelope.createName("echoResponse", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoResponseElement = (SOAPBodyElement) message
.getSOAPBody().getChildElements(echoResponseName).next();
String echoValue = echoResponseElement.getTextContent();
System.out.println("Echo Response [" + echoValue + "]");
}
public static void main(String[] args) throws Exception {
String url = "http://localhost:8080/echo/services";
if (args.length > 0) {
url = args[0];
}
EchoClient echoClient = new EchoClient(url);
echoClient.callWebService();
}
}

18
samples/echo/pom.xml Normal file
View File

@@ -0,0 +1,18 @@
<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">
<parent>
<artifactId>spring-ws-samples</artifactId>
<groupId>org.springframework.ws</groupId>
<version>1.0-m3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>echo</artifactId>
<packaging>war</packaging>
<name>Spring WS Echo Sample</name>
<dependencies>
<!-- Spring-WS dependencies -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
</project>

13
samples/echo/readme.txt Normal file
View File

@@ -0,0 +1,13 @@
=====================================================
== Spring Web Service Echo sample application ==
=====================================================
1. INTRODUCTION
This sample shows a bare-bones echoing service. Incoming messages are handled via DOM, and a simple 'business logic'
service is used to obtain the result.
2. INSTALLATION
Simply run "mvn package" and deploy the war file generated in target

View File

@@ -0,0 +1,16 @@
log4j.rootCategory=WARN, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${@PROJECT_NAME@.root}/@PROJECT_NAME@.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
#Pattern to output : date priority [category] - <message>line_separator
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.echo.service;
/**
* Defines the "business logic" of the web service.
*
* @author Ingo Siebert
* @author Arjen Poutsma
*/
public interface EchoService {
/**
* Returns the given string.
*
* @return <code>s</code>
*/
String echo(String s);
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.echo.service.impl;
import org.springframework.ws.samples.echo.service.EchoService;
/**
* Default implementation of <code>EchoService</code>.
*
* @author Ingo Siebert
* @author Arjen Poutsma
*/
public class EchoServiceImpl implements EchoService {
public String echo(String s) {
return s;
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.echo.ws;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.springframework.util.Assert;
import org.springframework.ws.endpoint.AbstractDomPayloadEndpoint;
import org.springframework.ws.samples.echo.service.EchoService;
/**
* Simple echoing Web service endpoint. Uses a <code>EchoService</code> to create a response string.
*
* @author Ingo Siebert
* @author Arjen Poutsma
*/
public class EchoEndpoint extends AbstractDomPayloadEndpoint {
/**
* Namespace of both request and response.
*/
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
/**
* The local name of the expected request.
*/
public static final String ECHO_REQUEST_LOCAL_NAME = "echoRequest";
/**
* The local name of the created response.
*/
public static final String ECHO_RESPONSE_LOCAL_NAME = "echoResponse";
private EchoService echoService;
/**
* Sets the "business service" to delegate to.
*/
public void setEchoService(EchoService echoService) {
this.echoService = echoService;
}
/**
* Reads the given <code>requestElement</code>, and sends a the response back.
*
* @param requestElement the contents of the SOAP message as DOM elements
* @param document a DOM document to be used for constructing <code>Node</code>s
* @return the response element
*/
protected Element invokeInternal(Element requestElement, Document document) throws Exception {
Assert.isTrue(NAMESPACE_URI.equals(requestElement.getNamespaceURI()), "Invalid namespace");
Assert.isTrue(ECHO_REQUEST_LOCAL_NAME.equals(requestElement.getLocalName()), "Invalid local name");
NodeList children = requestElement.getChildNodes();
Text requestText = null;
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.TEXT_NODE) {
requestText = (Text) children.item(i);
break;
}
}
if (requestText == null) {
throw new IllegalArgumentException("Could not find request text node");
}
String echo = echoService.echo(requestText.getNodeValue());
Element responseElement = document.createElementNS(NAMESPACE_URI, ECHO_RESPONSE_LOCAL_NAME);
Text responseText = document.createTextNode(echo);
responseElement.appendChild(responseText);
return responseElement;
}
}

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Spring-WS beans -->
<bean id="messageDispatcher" class="org.springframework.ws.soap.SoapMessageDispatcher">
<description>
The MessageDispatcher is responsible for routing messages to endpoints.</description>
<property name="endpointMappings" ref="payloadMapping"/>
<property name="endpointExceptionResolvers" ref="endpointExceptionResolver"/>
</bean>
<bean id="payloadMapping" class="org.springframework.ws.endpoint.mapping.PayloadRootQNameEndpointMapping">
<description>
This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for
an incoming message. Every message is passed to the default endpoint. Additionally, messages are logged
using the logging interceptor.</description>
<property name="defaultEndpoint" ref="echoEndpoint"/>
<property name="interceptors">
<list>
<ref local="validatingInterceptor"/>
<ref local="loggingInterceptor"/>
</list>
</property>
</bean>
<bean id="validatingInterceptor" class="org.springframework.ws.endpoint.interceptor.PayloadValidatingInterceptor">
<description>
This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML
Schema file.</description>
<property name="schema" value="/echo.xsd"/>
<property name="validateRequest" value="true"/>
<property name="validateResponse" value="true"/>
</bean>
<bean id="loggingInterceptor" class="org.springframework.ws.endpoint.interceptor.PayloadLoggingInterceptor">
<description>
This interceptor logs the message payload.</description>
</bean>
<bean id="echoEndpoint" class="org.springframework.ws.samples.echo.ws.EchoEndpoint">
<description>
This endpoint handles echo requests.</description>
<property name="echoService" ref="echoService"/>
</bean>
<bean id="echoWsdl" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<property name="wsdl" value="/echo.wsdl"/>
</bean>
<bean id="endpointExceptionResolver" class="org.springframework.ws.soap.endpoint.SimpleSoapExceptionResolver"/>
<!-- "Business" (POJO) services -->
<bean id="echoService" class="org.springframework.ws.samples.echo.service.impl.EchoServiceImpl"/>
</beans>

View File

@@ -0,0 +1,7 @@
log4j.rootLogger=WARN, stdout
log4j.logger.org.springframework.ws=DEBUG
log4j.logger.org.springframework.xml=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="messageEndpointHandlerAdapter"
class="org.springframework.ws.transport.http.MessageEndpointHandlerAdapter">
<description>
This handler adapter makes sure that Spring's DispatcherServlet supports MessageEndpoint instances as
handlers. It uses a SAAJ to construct SoapMessageContexts (and SoapMessages).</description>
<property name="messageContextFactory">
<bean class="org.springframework.ws.soap.saaj.SaajSoapMessageContextFactory"/>
</property>
</bean>
<bean id="wsdlDefinitionHandlerAdapter" class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter">
<description>
This handler adapter adds support for WsdlDefinitions to Spring's DispatcherServlet. It transforms location
attributes in the original WSDL to reflect the URL of the incoming HTTP request.</description>
<property name="transformLocations" value="true"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<description>
All incoming request are mapped to the messageDispatcher defined in applicationContext-ws.xml</description>
<property name="defaultHandler" ref="messageDispatcher"/>
<property name="mappings">
<props>
<prop key="/services/*">messageDispatcher</prop>
<prop key="echo.wsdl">echoWsdl</prop>
</props>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>
"Echo" WebService</display-name>
<description>Returns a given string(only A-Z and a-z chars allowed). See echo.xsd file.</description>
<!--Location of the Log4J config file, for initialization and refresh checks.
Applied by Log4jConfigListener. -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<!-- Logger for web server specific messages. -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Loads the root application context of this web app at startup.
Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
to access it anywhere in the web application, outside of the framework.
The root context is the parent of all servlet-specific contexts.
This means that its beans are automatically available in these child contexts,
both for getBean(name) calls and (external) bean references. -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Starts the web service servlet. -->
<servlet>
<servlet-name>springws</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<!-- We map all service request to the springws servlet. -->
<servlet-mapping>
<servlet-name>springws</servlet-name>
<url-pattern>/services</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springws</servlet-name>
<url-pattern>*.wsdl</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
</web-app>

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.springframework.org/spring-ws/samples/echo"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/samples/echo">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.springframework.org/spring-ws/samples/echo/schemas"
schemaLocation="echo.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="echoRequest">
<wsdl:part name="echoString" element="tns:echoRequest"/>
</wsdl:message>
<wsdl:message name="echoResponse">
<wsdl:part name="theEcho" element="tns:echoResponse"/>
</wsdl:message>
<wsdl:portType name="TestServicePortType">
<wsdl:operation name="echo">
<wsdl:input message="tns:echoRequest" name="echoRequest"/>
<wsdl:output message="tns:echoResponse" name="echoResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceHttpBinding" type="tns:TestServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="echo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="echoRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="echoResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port binding="tns:TestServiceHttpBinding" name="TestServiceHttpPort">
<wsdlsoap:address location="http://localhost:8080/echo/services"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified"
targetNamespace="http://www.springframework.org/spring-ws/samples/echo"
xmlns:tns="http://www.springframework.org/spring-ws/samples/echo">
<element name="echoRequest">
<simpleType>
<restriction base="string">
<pattern value="([A-Z]|[a-z])+"/>
</restriction>
</simpleType>
</element>
<element name="echoResponse" type="string"/>
</schema>

View File

@@ -0,0 +1,14 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Ingo Siebert">
<title>Spring WS test page</title>
</head>
<body bgcolor="#FFFFFF">
<h1>Spring-WS Echo</h1>
If you see this page, the WAR deployment was successful.
</body>
</html>

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.echo.ws;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.custommonkey.xmlunit.XMLTestCase;
import org.easymock.MockControl;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.springframework.ws.samples.echo.service.EchoService;
public class EchoEndpointTest extends XMLTestCase {
private EchoEndpoint endpoint;
private Document requestDocument;
private Document responseDocument;
private MockControl control;
private EchoService mock;
protected void setUp() throws Exception {
endpoint = new EchoEndpoint();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
requestDocument = documentBuilder.newDocument();
responseDocument = documentBuilder.newDocument();
control = MockControl.createControl(EchoService.class);
mock = (EchoService) control.getMock();
endpoint.setEchoService(mock);
}
public void testInvokeInternal() throws Exception {
Element echoRequest =
requestDocument.createElementNS(EchoEndpoint.NAMESPACE_URI, EchoEndpoint.ECHO_REQUEST_LOCAL_NAME);
String content = "ABC";
Text requestText = requestDocument.createTextNode(content);
echoRequest.appendChild(requestText);
String result = "DEF";
control.expectAndReturn(mock.echo(content), result);
control.replay();
Element echoResponse = endpoint.invokeInternal(echoRequest, responseDocument);
assertEquals("Invalid namespace", EchoEndpoint.NAMESPACE_URI, echoResponse.getNamespaceURI());
assertEquals("Invalid namespace", EchoEndpoint.ECHO_RESPONSE_LOCAL_NAME, echoResponse.getLocalName());
Text responseText = (Text) echoResponse.getChildNodes().item(0);
assertEquals("Invalid content", result, responseText.getNodeValue());
control.verify();
}
}