From ede249b1fb7d390bdea4818aefec121d72a51c21 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 12 Jun 2007 17:02:50 +0000 Subject: [PATCH] WebServiceMessageCallback can thrown TransformerException --- .../ws/client/core/SourceExtractor.java | 3 ++- .../ws/client/core/WebServiceMessageCallback.java | 6 ++++-- .../ws/client/core/WebServiceMessageExtractor.java | 6 ++++-- .../ws/client/core/WebServiceOperations.java | 10 +++++----- .../ws/client/support/WebServiceAccessor.java | 3 +++ .../transport/http/AbstractHttpSenderConnection.java | 11 +++++++++++ .../ws/transport/http/CommonsHttpConnection.java | 8 ++++---- .../ws/transport/http/HttpUrlConnection.java | 8 ++++---- .../ws/client/core/WebServiceTemplateTest.java | 2 +- 9 files changed, 38 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/client/core/SourceExtractor.java b/core/src/main/java/org/springframework/ws/client/core/SourceExtractor.java index 0b9f50eb..5c0827e6 100644 --- a/core/src/main/java/org/springframework/ws/client/core/SourceExtractor.java +++ b/core/src/main/java/org/springframework/ws/client/core/SourceExtractor.java @@ -18,6 +18,7 @@ package org.springframework.ws.client.core; import java.io.IOException; import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; /** * Callback interface for extracting a result object from a {@link javax.xml.transform.Source} instance. @@ -43,6 +44,6 @@ public interface SourceExtractor { * latter case) * @throws IOException in case of I/O errors */ - Object extractData(Source source) throws IOException; + Object extractData(Source source) throws IOException, TransformerException; } diff --git a/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageCallback.java b/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageCallback.java index dbf06ec3..b9d985c5 100644 --- a/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageCallback.java +++ b/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageCallback.java @@ -17,6 +17,7 @@ package org.springframework.ws.client.core; import java.io.IOException; +import javax.xml.transform.TransformerException; import org.springframework.ws.WebServiceMessage; @@ -34,8 +35,9 @@ public interface WebServiceMessageCallback { * Execute any number of operations on the supplied message. * * @param message the message - * @throws IOException in case of I/O errors + * @throws IOException in case of I/O errors + * @throws TransformerException in case of transformation errors */ - void doWithMessage(WebServiceMessage message) throws IOException; + void doWithMessage(WebServiceMessage message) throws IOException, TransformerException; } diff --git a/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageExtractor.java b/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageExtractor.java index bf297970..319523a6 100644 --- a/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageExtractor.java +++ b/core/src/main/java/org/springframework/ws/client/core/WebServiceMessageExtractor.java @@ -17,6 +17,7 @@ package org.springframework.ws.client.core; import java.io.IOException; +import javax.xml.transform.TransformerException; import org.springframework.ws.WebServiceMessage; @@ -41,8 +42,9 @@ public interface WebServiceMessageExtractor { * @param message the message to extract data from (possibly a SoapMessage) * @return an arbitrary result object, or null if none (the extractor will typically be stateful in the * latter case) - * @throws IOException in case of I/O errors + * @throws IOException in case of I/O errors + * @throws TransformerException in case of transformation errors */ - Object extractData(WebServiceMessage message) throws IOException; + Object extractData(WebServiceMessage message) throws IOException, TransformerException; } 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 ae844b21..74ba9ecd 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 @@ -128,7 +128,7 @@ public interface WebServiceOperations { *

* The given callback allows changing of the request message after the payload has been written to it. *

- * This will only work with a default specified! + * This will only work with a default uri specified! * * @param requestPayload the payload of the request message * @param requestCallback callback to change message, can be null @@ -162,7 +162,7 @@ public interface WebServiceOperations { * Sends a web service message that contains the given payload. Writes the response, if any, to the given * Result. *

- * This will only work with a default specified! + * This will only work with a default uri specified! * * @param requestPayload the payload of the request message * @param responseResult the result to write the response payload to @@ -189,7 +189,7 @@ public interface WebServiceOperations { *

* The given callback allows changing of the request message after the payload has been written to it. *

- * This will only work with a default specified! + * This will only work with a default uri specified! * * @param requestPayload the payload of the request message * @param requestCallback callback to change message, can be null @@ -222,7 +222,7 @@ 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 specified! + * 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 @@ -250,7 +250,7 @@ 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 specified! + * 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 diff --git a/core/src/main/java/org/springframework/ws/client/support/WebServiceAccessor.java b/core/src/main/java/org/springframework/ws/client/support/WebServiceAccessor.java index 3b8faf4c..de49e086 100644 --- a/core/src/main/java/org/springframework/ws/client/support/WebServiceAccessor.java +++ b/core/src/main/java/org/springframework/ws/client/support/WebServiceAccessor.java @@ -101,6 +101,9 @@ public abstract class WebServiceAccessor extends TransformerObjectSupport implem WebServiceMessageSender[] messageSenders = getMessageSenders(); for (int i = 0; i < messageSenders.length; i++) { if (messageSenders[i].supports(uri)) { + if (logger.isDebugEnabled()) { + logger.debug("Opening connection to [" + uri + "] using [" + messageSenders[i] + "]"); + } return messageSenders[i].createConnection(uri); } } diff --git a/core/src/main/java/org/springframework/ws/transport/http/AbstractHttpSenderConnection.java b/core/src/main/java/org/springframework/ws/transport/http/AbstractHttpSenderConnection.java index 58e988b1..bb783155 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/AbstractHttpSenderConnection.java +++ b/core/src/main/java/org/springframework/ws/transport/http/AbstractHttpSenderConnection.java @@ -42,6 +42,14 @@ public abstract class AbstractHttpSenderConnection extends AbstractSenderConnect return getResponseCode() / 100 != 2; } + public final String getErrorMessage() throws IOException { + StringBuffer buffer = new StringBuffer(getResponseMessage()); + buffer.append(" ["); + buffer.append(getResponseCode()); + buffer.append(']'); + return buffer.toString(); + } + /* * Receiving response */ @@ -83,6 +91,9 @@ public abstract class AbstractHttpSenderConnection extends AbstractSenderConnect /** Returns the HTTP status code of the response. */ protected abstract int getResponseCode() throws IOException; + /** Returns the HTTP status message of the response. */ + protected abstract String getResponseMessage() throws IOException; + /** Returns the length of the response. */ protected abstract long getResponseContentLength() throws IOException; diff --git a/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpConnection.java b/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpConnection.java index 2b532045..f9b08741 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpConnection.java +++ b/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpConnection.java @@ -56,10 +56,6 @@ public class CommonsHttpConnection extends AbstractHttpSenderConnection { return postMethod; } - public String getErrorMessage() throws IOException { - return postMethod.getStatusText(); - } - public void close() throws IOException { postMethod.releaseConnection(); } @@ -94,6 +90,10 @@ public class CommonsHttpConnection extends AbstractHttpSenderConnection { return postMethod.getStatusCode(); } + protected String getResponseMessage() throws IOException { + return postMethod.getStatusText(); + } + protected long getResponseContentLength() throws IOException { return postMethod.getResponseContentLength(); } diff --git a/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnection.java b/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnection.java index 83e2e238..56b0f172 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnection.java +++ b/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnection.java @@ -58,10 +58,6 @@ public class HttpUrlConnection extends AbstractHttpSenderConnection { connection.disconnect(); } - public String getErrorMessage() throws IOException { - return connection.getResponseMessage(); - } - /* * Sending request */ @@ -116,6 +112,10 @@ public class HttpUrlConnection extends AbstractHttpSenderConnection { return connection.getResponseCode(); } + protected String getResponseMessage() throws IOException { + return connection.getResponseMessage(); + } + protected InputStream getRawResponseInputStream() throws IOException { if (connection.getResponseCode() / 100 != 2) { return connection.getErrorStream(); 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 cc7e9fc7..1a0251f6 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 @@ -182,7 +182,7 @@ public class WebServiceTemplateTest extends XMLTestCase { connectionControl.expectAndReturn(connectionMock.hasError(), true); connectionControl.expectAndReturn(connectionMock.hasFault(), false); String errorMessage = "errorMessage"; - connectionControl.expectAndReturn(connectionMock.getErrorMessage(), errorMessage, 2); + connectionControl.expectAndReturn(connectionMock.getErrorMessage(), errorMessage); connectionMock.close(); connectionControl.replay();