diff --git a/samples/echo/server/pom.xml b/samples/echo/server/pom.xml
index 9d136c3a..96be6e44 100644
--- a/samples/echo/server/pom.xml
+++ b/samples/echo/server/pom.xml
@@ -12,7 +12,7 @@
A minimal Spring-WS sample that uses W3C DOM to echo back an incoming string.
- jdk14-jdk15
+ jdk15
!1.6
diff --git a/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/ws/EchoEndpoint.java b/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/ws/EchoEndpoint.java
index 781fe8e5..5f612747 100755
--- a/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/ws/EchoEndpoint.java
+++ b/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/ws/EchoEndpoint.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 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.
@@ -16,9 +16,18 @@
package org.springframework.ws.samples.echo.ws;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.ws.samples.echo.service.EchoService;
-import org.springframework.ws.server.endpoint.AbstractDomPayloadEndpoint;
+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 org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -31,7 +40,8 @@ import org.w3c.dom.Text;
* @author Ingo Siebert
* @author Arjen Poutsma
*/
-public class EchoEndpoint extends AbstractDomPayloadEndpoint {
+@Endpoint
+public class EchoEndpoint {
/**
* Namespace of both request and response.
@@ -48,26 +58,28 @@ public class EchoEndpoint extends AbstractDomPayloadEndpoint {
*/
public static final String ECHO_RESPONSE_LOCAL_NAME = "echoResponse";
- private EchoService echoService;
+ private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- /**
- * Sets the "business service" to delegate to.
- */
- public void setEchoService(EchoService echoService) {
+ private final EchoService echoService;
+
+ @Autowired
+ public EchoEndpoint(EchoService echoService) {
this.echoService = echoService;
}
+
/**
* Reads the given requestElement, 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 Nodes
* @return the response element
*/
- @Override
- protected Element invokeInternal(Element requestElement, Document document) throws Exception {
+ @PayloadRoot(localPart = ECHO_REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
+ @ResponsePayload
+ public Element handleEchoRequest(@RequestPayload Element requestElement) throws ParserConfigurationException {
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++) {
@@ -81,6 +93,9 @@ public class EchoEndpoint extends AbstractDomPayloadEndpoint {
}
String echo = echoService.echo(requestText.getNodeValue());
+
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.newDocument();
Element responseElement = document.createElementNS(NAMESPACE_URI, ECHO_RESPONSE_LOCAL_NAME);
Text responseText = document.createTextNode(echo);
responseElement.appendChild(responseText);
diff --git a/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml b/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml
index 08094f84..4c4cb168 100755
--- a/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml
+++ b/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml
@@ -7,13 +7,12 @@
detected by Spring-WS, similar to the way Controllers are picked up in Spring Web MVC.
-
+
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.
-
@@ -33,6 +32,8 @@
+
+
This interceptor logs the message payload.
@@ -43,7 +44,7 @@
This endpoint handles echo requests.
-
+
diff --git a/samples/echo/server/src/test/java/org/springframework/ws/samples/echo/ws/EchoEndpointTest.java b/samples/echo/server/src/test/java/org/springframework/ws/samples/echo/ws/EchoEndpointTest.java
index afadfd87..6ce3af3b 100644
--- a/samples/echo/server/src/test/java/org/springframework/ws/samples/echo/ws/EchoEndpointTest.java
+++ b/samples/echo/server/src/test/java/org/springframework/ws/samples/echo/ws/EchoEndpointTest.java
@@ -42,14 +42,13 @@ public class EchoEndpointTest {
@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();
mock = createMock(EchoService.class);
- endpoint.setEchoService(mock);
+ endpoint = new EchoEndpoint(mock);
}
@Test
@@ -64,7 +63,7 @@ public class EchoEndpointTest {
replay(mock);
- Element echoResponse = endpoint.invokeInternal(echoRequest, responseDocument);
+ Element echoResponse = endpoint.handleEchoRequest(echoRequest);
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);