From 9669622f75f0599451c4c6e1390f25274f1bd39e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 13 Jun 2007 00:35:18 +0000 Subject: [PATCH] SWS-134 --- .../ws/client/core/WebServiceOperations.java | 160 ++++++++++-------- .../ws/client/core/WebServiceTemplate.java | 87 +++++----- .../soap/client/core/SoapActionCallback.java | 2 +- .../WebServiceTemplateIntegrationTest.java | 14 +- .../client/core/WebServiceTemplateTest.java | 12 +- pom.xml | 12 +- src/changes/changes.xml | 2 + 7 files changed, 162 insertions(+), 127 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java b/core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java index 74ba9ecd..e76d842c 100644 --- a/core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java +++ b/core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java @@ -31,6 +31,66 @@ import org.springframework.ws.client.WebServiceClientException; */ public interface WebServiceOperations { + /** + * Sends a web service message that can be manipulated with the given callback, reading the result with a + * WebServiceMessageExtractor. + *

+ * This will only work with a default uri specified! + * + * @param requestCallback the requestCallback to be used for manipulating the request message + * @param responseExtractor object that will extract results + * @return an arbitrary result object, as returned by the WebServiceMessageExtractor + * @throws WebServiceClientException if there is a problem sending or receiving the message + */ + Object sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor responseExtractor) + throws WebServiceClientException; + + /** + * Sends a web service message that can be manipulated with the given callback, reading the result with a + * WebServiceMessageExtractor. + * + * @param uri the URI to send the message to + * @param requestCallback the requestCallback to be used for manipulating the request message + * @param responseExtractor object that will extract results + * @return an arbitrary result object, as returned by the WebServiceMessageExtractor + * @throws WebServiceClientException if there is a problem sending or receiving the message + */ + Object sendAndReceive(String uri, + WebServiceMessageCallback requestCallback, + WebServiceMessageExtractor responseExtractor) throws WebServiceClientException; + + /** + * Sends a web service message that can be manipulated with the given request callback, handling the response with a + * response callback. + *

+ * This will only work with a default uri specified! + * + * @param requestCallback the callback to be used for manipulating the request message + * @param responseCallback the callback to be used for manipulating the response message + * @return true if a response was received; false otherwise + * @throws WebServiceClientException if there is a problem sending or receiving the message + */ + boolean sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback) + throws WebServiceClientException; + + /** + * Sends a web service message that can be manipulated with the given request callback, handling the response with a + * response callback. + * + * @param uri the URI to send the message to + * @param requestCallback the callback to be used for manipulating the request message + * @param responseCallback the callback to be used for manipulating the response message + * @return true if a response was received; false otherwise + * @throws WebServiceClientException if there is a problem sending or receiving the message + */ + boolean sendAndReceive(String uri, + WebServiceMessageCallback requestCallback, + WebServiceMessageCallback responseCallback) throws WebServiceClientException; + + //----------------------------------------------------------------------------------------------------------------- + // Convenience methods for sending and receiving marshalled messages + //----------------------------------------------------------------------------------------------------------------- + /** * Sends a web service message that contains the given payload, marshalled by the configured * Marshaller. Returns the unmarshalled payload of the response message, if any. @@ -96,6 +156,10 @@ public interface WebServiceOperations { Object marshalSendAndReceive(String uri, Object requestPayload, WebServiceMessageCallback requestCallback) throws XmlMappingException, WebServiceClientException; + //----------------------------------------------------------------------------------------------------------------- + // Convenience methods for sending Sources + //----------------------------------------------------------------------------------------------------------------- + /** * Sends a web service message that contains the given payload, reading the result with a * SourceExtractor. @@ -107,7 +171,8 @@ public interface WebServiceOperations { * @return an arbitrary result object, as returned by the SourceExtractor * @throws WebServiceClientException if there is a problem sending or receiving the message */ - Object sendAndReceive(Source requestPayload, SourceExtractor responseExtractor) throws WebServiceClientException; + Object sendSourceAndReceive(Source requestPayload, SourceExtractor responseExtractor) + throws WebServiceClientException; /** * Sends a web service message that contains the given payload, reading the result with a @@ -119,7 +184,7 @@ public interface WebServiceOperations { * @return an arbitrary result object, as returned by the SourceExtractor * @throws WebServiceClientException if there is a problem sending or receiving the message */ - Object sendAndReceive(String uri, Source requestPayload, SourceExtractor responseExtractor) + Object sendSourceAndReceive(String uri, Source requestPayload, SourceExtractor responseExtractor) throws WebServiceClientException; /** @@ -136,9 +201,9 @@ public interface WebServiceOperations { * @return an arbitrary result object, as returned by the SourceExtractor * @throws WebServiceClientException if there is a problem sending or receiving the message */ - Object sendAndReceive(Source requestPayload, - WebServiceMessageCallback requestCallback, - SourceExtractor responseExtractor) throws WebServiceClientException; + Object sendSourceAndReceive(Source requestPayload, + WebServiceMessageCallback requestCallback, + SourceExtractor responseExtractor) throws WebServiceClientException; /** * Sends a web service message that contains the given payload, reading the result with a @@ -153,10 +218,14 @@ public interface WebServiceOperations { * @return an arbitrary result object, as returned by the SourceExtractor * @throws WebServiceClientException if there is a problem sending or receiving the message */ - Object sendAndReceive(String uri, - Source requestPayload, - WebServiceMessageCallback requestCallback, - SourceExtractor responseExtractor) throws WebServiceClientException; + Object sendSourceAndReceive(String uri, + Source requestPayload, + WebServiceMessageCallback requestCallback, + SourceExtractor responseExtractor) throws WebServiceClientException; + + //----------------------------------------------------------------------------------------------------------------- + // Convenience methods for sending Sources and receiving to Results + //----------------------------------------------------------------------------------------------------------------- /** * Sends a web service message that contains the given payload. Writes the response, if any, to the given @@ -169,7 +238,7 @@ public interface WebServiceOperations { * @return true if a response was received; false otherwise * @throws WebServiceClientException if there is a problem sending or receiving the message */ - boolean sendAndReceive(Source requestPayload, Result responseResult) throws WebServiceClientException; + boolean sendSourceAndReceiveToResult(Source requestPayload, Result responseResult) throws WebServiceClientException; /** * Sends a web service message that contains the given payload. Writes the response, if any, to the given @@ -181,7 +250,8 @@ public interface WebServiceOperations { * @return true if a response was received; false otherwise * @throws WebServiceClientException if there is a problem sending or receiving the message */ - boolean sendAndReceive(String uri, Source requestPayload, Result responseResult) throws WebServiceClientException; + boolean sendSourceAndReceiveToResult(String uri, Source requestPayload, Result responseResult) + throws WebServiceClientException; /** * Sends a web service message that contains the given payload. Writes the response, if any, to the given @@ -197,8 +267,9 @@ public interface WebServiceOperations { * @return true if a response was received; false otherwise * @throws WebServiceClientException if there is a problem sending or receiving the message */ - boolean sendAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback, Result responseResult) - throws WebServiceClientException; + boolean sendSourceAndReceiveToResult(Source requestPayload, + WebServiceMessageCallback requestCallback, + Result responseResult) throws WebServiceClientException; /** * Sends a web service message that contains the given payload. Writes the response, if any, to the given @@ -213,64 +284,9 @@ public interface WebServiceOperations { * @return true if a response was received; false otherwise * @throws WebServiceClientException if there is a problem sending or receiving the message */ - boolean sendAndReceive(String uri, - Source requestPayload, - WebServiceMessageCallback requestCallback, - Result responseResult) throws WebServiceClientException; + boolean sendSourceAndReceiveToResult(String uri, + Source requestPayload, + WebServiceMessageCallback requestCallback, + Result responseResult) throws WebServiceClientException; - /** - * Sends a web service message that can be manipulated with the given callback, reading the result with a - * WebServiceMessageExtractor. - *

- * This will only work with a default uri specified! - * - * @param requestCallback the requestCallback to be used for manipulating the request message - * @param responseExtractor object that will extract results - * @return an arbitrary result object, as returned by the WebServiceMessageExtractor - * @throws WebServiceClientException if there is a problem sending or receiving the message - */ - Object sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor responseExtractor) - throws WebServiceClientException; - - /** - * Sends a web service message that can be manipulated with the given callback, reading the result with a - * WebServiceMessageExtractor. - * - * @param uri the URI to send the message to - * @param requestCallback the requestCallback to be used for manipulating the request message - * @param responseExtractor object that will extract results - * @return an arbitrary result object, as returned by the WebServiceMessageExtractor - * @throws WebServiceClientException if there is a problem sending or receiving the message - */ - Object sendAndReceive(String uri, - WebServiceMessageCallback requestCallback, - WebServiceMessageExtractor responseExtractor) throws WebServiceClientException; - - /** - * Sends a web service message that can be manipulated with the given callback, reading the result with a - * WebServiceMessageExtractor. - *

- * This will only work with a default uri specified! - * - * @param requestCallback the callback to be used for manipulating the request message - * @param responseCallback the callback to be used for manipulating the response message - * @return true if a response was received; false otherwise - * @throws WebServiceClientException if there is a problem sending or receiving the message - */ - boolean sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback) - throws WebServiceClientException; - - /** - * Sends a web service message that can be manipulated with the given callback, reading the result with a - * WebServiceMessageExtractor. - * - * @param uri the URI to send the message to - * @param requestCallback the callback to be used for manipulating the request message - * @param responseCallback the callback to be used for manipulating the response message - * @return true if a response was received; false otherwise - * @throws WebServiceClientException if there is a problem sending or receiving the message - */ - boolean sendAndReceive(String uri, - WebServiceMessageCallback requestCallback, - WebServiceMessageCallback responseCallback) throws WebServiceClientException; } diff --git a/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java b/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java index a49f6b08..af12bb71 100644 --- a/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java +++ b/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java @@ -64,24 +64,35 @@ import org.springframework.ws.transport.support.DefaultStrategiesHelper; * FaultMessageResolver} can be defined with with {@link #setFaultMessageResolver(FaultMessageResolver) * faultMessageResolver} property. If this property is set to null, no fault resolving is performed. *

- * This template uses the following algorithm for sending and receiving.

  1. Call to {@link - * #createConnection(String) createConnection()}.
  2. Call to {@link WebServiceMessageFactory#createWebServiceMessage() - * createWebServiceMessage()} on the registered message factory to create a request message.
  3. Invoke {@link - * WebServiceMessageCallback#doWithMessage(WebServiceMessage) doWithMessage()} on the request callback, if any. This - * step stores content in the request message, based on Source, marshalling, etc.
  4. Call {@link - * WebServiceConnection#send(WebServiceMessage) send()} on the connection.
  5. Call {@link - * #hasError(WebServiceConnection,WebServiceMessage) hasError()} to check if the connection has an error. For an HTTP - * transport, a status code other than 2xx indicates an error. However, since a status code of 500 can also - * indicate a SOAP fault, the template verifies whether the error is not a fault.
  6. Invoke - * {@link WebServiceConnection#receive(WebServiceMessageFactory) receive} on the connection to read the response - * message, if any.
  7. - *
  8. Call to {@link WebServiceConnection#close() close} on the connection.
+ * This template uses the following algorithm for sending and receiving. + *
    + *
  1. Call to {@link #createConnection(String) createConnection()}.
  2. + *
  3. Call to {@link WebServiceMessageFactory#createWebServiceMessage() createWebServiceMessage()} on the registered + * message factory to create a request message.
  4. + *
  5. Invoke {@link WebServiceMessageCallback#doWithMessage(WebServiceMessage) doWithMessage()} on the request + * callback, if any. This step stores content in the request message, based on Source, marshalling, + * etc.
  6. + *
  7. Call {@link WebServiceConnection#send(WebServiceMessage) send()} on the connection.
  8. + *
  9. Call {@link #hasError(WebServiceConnection, WebServiceMessage) hasError()} to check if the connection has an + * error. For an HTTP transport, a status code other than 2xx indicates an error. However, since a + * status code of 500 can also indicate a SOAP fault, the template verifies whether the error is not a fault.
  10. + * + *
  11. Invoke {@link WebServiceConnection#receive(WebServiceMessageFactory) receive} on the connection to read the + * response message, if any.
  12. + * + *
  13. Call to {@link WebServiceConnection#close() close} on the connection.
  14. + *
* * @author Arjen Poutsma */ @@ -123,10 +134,10 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService * * @see #marshalSendAndReceive(Object) * @see #marshalSendAndReceive(Object,WebServiceMessageCallback) - * @see #sendAndReceive(Source,Result) - * @see #sendAndReceive(Source,WebServiceMessageCallback,Result) - * @see #sendAndReceive(Source,SourceExtractor) - * @see #sendAndReceive(Source,WebServiceMessageCallback,SourceExtractor) + * @see #sendSourceAndReceiveToResult(Source,Result) + * @see #sendSourceAndReceiveToResult(Source,WebServiceMessageCallback,Result) + * @see #sendSourceAndReceive(Source,SourceExtractor) + * @see #sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor) * @see #sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback) */ public void setDefaultUri(String uri) { @@ -271,21 +282,21 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService * Result-handling methods */ - public boolean sendAndReceive(Source requestPayload, Result responseResult) { - return sendAndReceive(requestPayload, null, responseResult); + public boolean sendSourceAndReceiveToResult(Source requestPayload, Result responseResult) { + return sendSourceAndReceiveToResult(requestPayload, null, responseResult); } - public boolean sendAndReceive(String uri, Source requestPayload, Result responseResult) { - return sendAndReceive(uri, requestPayload, null, responseResult); + public boolean sendSourceAndReceiveToResult(String uri, Source requestPayload, Result responseResult) { + return sendSourceAndReceiveToResult(uri, requestPayload, null, responseResult); } - public boolean sendAndReceive(Source requestPayload, + public boolean sendSourceAndReceiveToResult(Source requestPayload, WebServiceMessageCallback requestCallback, final Result responseResult) { - return sendAndReceive(getDefaultUri(), requestPayload, requestCallback, responseResult); + return sendSourceAndReceiveToResult(getDefaultUri(), requestPayload, requestCallback, responseResult); } - public boolean sendAndReceive(String uri, + public boolean sendSourceAndReceiveToResult(String uri, Source requestPayload, WebServiceMessageCallback requestCallback, final Result responseResult) { @@ -310,21 +321,21 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService * Source-handling methods */ - public Object sendAndReceive(final Source requestPayload, final SourceExtractor responseExtractor) { - return sendAndReceive(requestPayload, null, responseExtractor); + public Object sendSourceAndReceive(final Source requestPayload, final SourceExtractor responseExtractor) { + return sendSourceAndReceive(requestPayload, null, responseExtractor); } - public Object sendAndReceive(String uri, final Source requestPayload, final SourceExtractor responseExtractor) { - return sendAndReceive(uri, requestPayload, null, responseExtractor); + public Object sendSourceAndReceive(String uri, final Source requestPayload, final SourceExtractor responseExtractor) { + return sendSourceAndReceive(uri, requestPayload, null, responseExtractor); } - public Object sendAndReceive(final Source requestPayload, + public Object sendSourceAndReceive(final Source requestPayload, final WebServiceMessageCallback requestCallback, final SourceExtractor responseExtractor) { - return sendAndReceive(getDefaultUri(), requestPayload, requestCallback, responseExtractor); + return sendSourceAndReceive(getDefaultUri(), requestPayload, requestCallback, responseExtractor); } - public Object sendAndReceive(String uri, + public Object sendSourceAndReceive(String uri, final Source requestPayload, final WebServiceMessageCallback requestCallback, final SourceExtractor responseExtractor) { @@ -354,8 +365,8 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService } /* - * WebServiceMessage-handling methods - */ + * WebServiceMessage-handling methods + */ public boolean sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback) { diff --git a/core/src/main/java/org/springframework/ws/soap/client/core/SoapActionCallback.java b/core/src/main/java/org/springframework/ws/soap/client/core/SoapActionCallback.java index dc054e1c..9abc88b5 100644 --- a/core/src/main/java/org/springframework/ws/soap/client/core/SoapActionCallback.java +++ b/core/src/main/java/org/springframework/ws/soap/client/core/SoapActionCallback.java @@ -29,7 +29,7 @@ import org.springframework.ws.soap.SoapMessage; *
  * WebServiceTemplate template = new WebServiceTemplate(messageFactory);
  * Result result = new DOMResult();
- * template.sendAndReceive(
+ * template.sendSourceAndReceiveToResult(
  *     new StringSource("<content xmlns=\"http://tempuri.org\"/>"),
  *     new SoapActionCallback("http://tempuri.org/SOAPAction"),
  *     result);
diff --git a/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateIntegrationTest.java b/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateIntegrationTest.java
index f65f7d73..dbbb36e4 100644
--- a/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateIntegrationTest.java
+++ b/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateIntegrationTest.java
@@ -88,10 +88,10 @@ public class WebServiceTemplateIntegrationTest extends XMLTestCase {
         template.setMessageSender(new CommonsHttpMessageSender());
         String content = "";
         StringResult result = new StringResult();
-        template.sendAndReceive("http://localhost:8888/pox", new StringSource(content), result);
+        template.sendSourceAndReceiveToResult("http://localhost:8888/pox", new StringSource(content), result);
         assertXMLEqual(content, result.toString());
         try {
-            template.sendAndReceive("http://localhost:8888/errors/notfound", new StringSource(content),
+            template.sendSourceAndReceiveToResult("http://localhost:8888/errors/notfound", new StringSource(content),
                     new StringResult());
             fail("WebServiceTransportException expected");
         }
@@ -99,7 +99,7 @@ public class WebServiceTemplateIntegrationTest extends XMLTestCase {
             //expected
         }
         try {
-            template.sendAndReceive("http://localhost:8888/errors/server", new StringSource(content), result);
+            template.sendSourceAndReceiveToResult("http://localhost:8888/errors/server", new StringSource(content), result);
             fail("WebServiceTransportException expected");
         }
         catch (WebServiceTransportException ex) {
@@ -117,13 +117,13 @@ public class WebServiceTemplateIntegrationTest extends XMLTestCase {
         template.setMessageSender(new CommonsHttpMessageSender());
         String content = "";
         StringResult result = new StringResult();
-        template.sendAndReceive("http://localhost:8888/soap/echo", new StringSource(content), result);
+        template.sendSourceAndReceiveToResult("http://localhost:8888/soap/echo", new StringSource(content), result);
         assertXMLEqual(content, result.toString());
-        boolean b = template.sendAndReceive("http://localhost:8888/soap/noResponse", new StringSource(content),
+        boolean b = template.sendSourceAndReceiveToResult("http://localhost:8888/soap/noResponse", new StringSource(content),
                 new StringResult());
         assertFalse("Invalid result", b);
         try {
-            template.sendAndReceive("http://localhost:8888/errors/notfound", new StringSource(content),
+            template.sendSourceAndReceiveToResult("http://localhost:8888/errors/notfound", new StringSource(content),
                     new StringResult());
             fail("WebServiceTransportException expected");
         }
@@ -131,7 +131,7 @@ public class WebServiceTemplateIntegrationTest extends XMLTestCase {
             //expected
         }
         try {
-            template.sendAndReceive("http://localhost:8888/soap/fault", new StringSource(content), result);
+            template.sendSourceAndReceiveToResult("http://localhost:8888/soap/fault", new StringSource(content), result);
             fail("SoapFaultClientException expected");
         }
         catch (SoapFaultClientException ex) {
diff --git a/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateTest.java b/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateTest.java
index 1a0251f6..d923c363 100644
--- a/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateTest.java
+++ b/core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateTest.java
@@ -217,7 +217,7 @@ public class WebServiceTemplateTest extends XMLTestCase {
         connectionMock.close();
         connectionControl.replay();
 
-        Object result = template.sendAndReceive(new StringSource(""), extractorMock);
+        Object result = template.sendSourceAndReceive(new StringSource(""), extractorMock);
         assertEquals("Invalid response", extracted, result);
 
         extractorControl.verify();
@@ -236,7 +236,7 @@ public class WebServiceTemplateTest extends XMLTestCase {
         connectionMock.close();
         connectionControl.replay();
 
-        Object result = template.sendAndReceive(new StringSource(""), extractorMock);
+        Object result = template.sendSourceAndReceive(new StringSource(""), extractorMock);
         assertNull("Invalid response", result);
 
         extractorControl.verify();
@@ -254,7 +254,7 @@ public class WebServiceTemplateTest extends XMLTestCase {
         connectionControl.replay();
 
         StringResult result = new StringResult();
-        boolean b = template.sendAndReceive(new StringSource(""), result);
+        boolean b = template.sendSourceAndReceiveToResult(new StringSource(""), result);
         assertTrue("Invalid result", b);
 
         connectionControl.verify();
@@ -270,7 +270,7 @@ public class WebServiceTemplateTest extends XMLTestCase {
         connectionControl.replay();
 
         StringResult result = new StringResult();
-        boolean b = template.sendAndReceive(new StringSource(""), result);
+        boolean b = template.sendSourceAndReceiveToResult(new StringSource(""), result);
         assertFalse("Invalid result", b);
 
         connectionControl.verify();
@@ -381,8 +381,6 @@ public class WebServiceTemplateTest extends XMLTestCase {
         callbackControl.verify();
         extractorControl.verify();
         connectionControl.verify();
-
     }
 
-
-}
\ No newline at end of file
+}
diff --git a/pom.xml b/pom.xml
index 036de70b..38af4296 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
 
-
     4.0.0
     org.springframework.ws
@@ -256,7 +257,8 @@
                             
                         
                         
+                              tofile="target/site/reference/pdf/spring-ws-reference.pdf"
+                              failonerror="false"/>
                     
                 
             
@@ -303,6 +305,7 @@
                             org.springframework.xml*
                         
                     
+                    ${basedir}/src/main/javadoc
                     org.springframework.ws.samples
                     
                         http://java.sun.com/j2se/1.4.2/docs/api
@@ -371,6 +374,11 @@
                 spring-ws-security
                 ${project.version}
             
+            
+                org.springframework.ws
+                spring-ws-mock
+                ${project.version}
+            
             
                 org.springframework.ws
                 spring-ws-samples
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 97c7ec62..c5396b75 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -6,6 +6,8 @@
     
     
         
+            Reduce the number of overloaded methods on the
+            WebServiceTemplate class to aid comprehension.
             Allow specifying names of message factory and message
                 receiver in MessageDispatcherServlet