Reworked echo sample to use maven for clients

This commit is contained in:
Arjen Poutsma
2010-02-26 09:11:12 +00:00
parent 9a608b4ba3
commit b931fc0b18
17 changed files with 41 additions and 98 deletions

View File

@@ -87,11 +87,13 @@ public class EchoClient {
SOAPBodyElement echoResponseElement = (SOAPBodyElement) message
.getSOAPBody().getChildElements(echoResponseName).next();
String echoValue = echoResponseElement.getTextContent();
System.out.println();
System.out.println("Echo Response [" + echoValue + "]");
System.out.println();
}
public static void main(String[] args) throws Exception {
String url = "http://localhost:8080/echo/services";
String url = "http://localhost:8080/echo-server/services";
if (args.length > 0) {
url = args[0];
}

View File

@@ -38,7 +38,9 @@ public class EchoClient extends WebServiceGatewaySupport {
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
System.out.println();
System.out.println(result);
System.out.println();
}
public static void main(String[] args) throws IOException {

View File

@@ -1,9 +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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="echoClient" class="org.springframework.ws.samples.echo.client.sws.EchoClient">
<property name="defaultUri" value="http://localhost:8080/echo/services"/>
<property name="defaultUri" value="http://localhost:8080/echo-server/services"/>
<property name="request" value="classpath:org/springframework/ws/samples/echo/client/sws/echoRequest.xml"/>
</bean>

View File

@@ -1,14 +1,14 @@
<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>
<artifactId>echo</artifactId>
<groupId>org.springframework.ws</groupId>
<version>2.0.0-M1-SNAPSHOT</version>
<relativePath>../samples/pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>echo</artifactId>
<artifactId>echo-server</artifactId>
<packaging>war</packaging>
<name>Spring WS Echo Sample</name>
<name>Spring WS Echo Sample - Server</name>
<description>A minimal Spring-WS sample that uses W3C DOM to echo back an incoming string.</description>
<profiles>
<profile>
@@ -21,41 +21,18 @@
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<stylesheetfile>${basedir}/../../src/main/javadoc/javadoc.css</stylesheetfile>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<!-- Spring-WS dependencies -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<version>1.2_Java1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -64,6 +64,7 @@ public class EchoEndpoint extends AbstractDomPayloadEndpoint {
* @param document a DOM document to be used for constructing <code>Node</code>s
* @return the response element
*/
@Override
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");

View File

@@ -19,15 +19,18 @@ 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.springframework.ws.samples.echo.service.EchoService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.springframework.ws.samples.echo.service.EchoService;
import static org.easymock.EasyMock.*;
public class EchoEndpointTest extends XMLTestCase {
public class EchoEndpointTest {
private EchoEndpoint endpoint;
@@ -35,23 +38,21 @@ public class EchoEndpointTest extends XMLTestCase {
private Document responseDocument;
private MockControl control;
private EchoService mock;
@Override
protected void setUp() throws Exception {
@Before
public 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();
mock = createMock(EchoService.class);
endpoint.setEchoService(mock);
}
@Test
public void testInvokeInternal() throws Exception {
Element echoRequest =
requestDocument.createElementNS(EchoEndpoint.NAMESPACE_URI, EchoEndpoint.ECHO_REQUEST_LOCAL_NAME);
@@ -59,14 +60,17 @@ public class EchoEndpointTest extends XMLTestCase {
Text requestText = requestDocument.createTextNode(content);
echoRequest.appendChild(requestText);
String result = "DEF";
control.expectAndReturn(mock.echo(content), result);
control.replay();
expect(mock.echo(content)).andReturn(result);
replay(mock);
Element echoResponse = endpoint.invokeInternal(echoRequest, responseDocument);
assertEquals("Invalid namespace", EchoEndpoint.NAMESPACE_URI, echoResponse.getNamespaceURI());
assertEquals("Invalid namespace", EchoEndpoint.ECHO_RESPONSE_LOCAL_NAME, echoResponse.getLocalName());
Assert.assertEquals("Invalid namespace", EchoEndpoint.NAMESPACE_URI, echoResponse.getNamespaceURI());
Assert.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();
Assert.assertEquals("Invalid content", result, responseText.getNodeValue());
verify(mock);
}
}

View File

@@ -18,50 +18,6 @@
<module>stockquote</module>
<module>airline</module>
</modules>
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Repository</name>
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
</repository>
</repositories>
<profiles>
<profile>
<id>jdk15</id>
<activation>
<jdk>!1.6</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
<version>2.1</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>
<plugin>
@@ -78,7 +34,7 @@
</plugins>
</build>
<dependencies>
<!-- Loggin dependencies -->
<!-- Logging dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>

View File

@@ -10,6 +10,7 @@ Sample table of contents
* stock - Shows how to use WS-Addressing and the Java 6 HTTP Server
* tutorial - Contains the code from the Spring-WS tutorial
Most of these samples can be run by using the Jetty Web container. Simply issue
the "mvn jetty:run" command in one of the sample directories. Alternatively,
you can build deployable war archives using "mvn package".
Except the tutorial, all of these samples consist of a separate 'server' and 'client' project.
The server projects can be run using the "mvn jetty:run" command, or by using "mvn package" and deploying the resulting
war archives to a Web Container.
The client projects are typically command-line projects, and can by started by issuing the 'mvn exec:java' command.