diff --git a/core/src/main/java/org/springframework/ws/transport/AbstractReceiverConnection.java b/core/src/main/java/org/springframework/ws/transport/AbstractReceiverConnection.java
index 75736128..5fc95faa 100644
--- a/core/src/main/java/org/springframework/ws/transport/AbstractReceiverConnection.java
+++ b/core/src/main/java/org/springframework/ws/transport/AbstractReceiverConnection.java
@@ -47,17 +47,6 @@ public abstract class AbstractReceiverConnection extends AbstractWebServiceConne
return responseOutputStream;
}
- public final void close() throws IOException {
- try {
- if (requestInputStream != null) {
- requestInputStream.close();
- }
- }
- finally {
- onClose();
- }
- }
-
/**
* Template method invoked from {@link #close()}. Default implementation is empty.
*
@@ -108,11 +97,6 @@ public abstract class AbstractReceiverConnection extends AbstractWebServiceConne
return getRequestHeaders(name);
}
- public void close() throws IOException {
- // defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
- }
-
-
}
/** Implementation of TransportOutputStream for sending-side connections. */
diff --git a/core/src/main/java/org/springframework/ws/transport/AbstractSenderConnection.java b/core/src/main/java/org/springframework/ws/transport/AbstractSenderConnection.java
index 76ef7fb8..be34b59f 100644
--- a/core/src/main/java/org/springframework/ws/transport/AbstractSenderConnection.java
+++ b/core/src/main/java/org/springframework/ws/transport/AbstractSenderConnection.java
@@ -52,17 +52,6 @@ public abstract class AbstractSenderConnection extends AbstractWebServiceConnect
}
}
- public final void close() throws IOException {
- try {
- if (responseInputStream != null) {
- responseInputStream.close();
- }
- }
- finally {
- onClose();
- }
- }
-
/**
* Template method invoked from {@link #close()}. Default implementation is empty.
*
@@ -128,10 +117,6 @@ public abstract class AbstractSenderConnection extends AbstractWebServiceConnect
return getResponseHeaders(name);
}
- public void close() throws IOException {
- // defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
- }
-
}
}
diff --git a/core/src/main/java/org/springframework/ws/transport/AbstractWebServiceConnection.java b/core/src/main/java/org/springframework/ws/transport/AbstractWebServiceConnection.java
index af5c133e..8f8934df 100644
--- a/core/src/main/java/org/springframework/ws/transport/AbstractWebServiceConnection.java
+++ b/core/src/main/java/org/springframework/ws/transport/AbstractWebServiceConnection.java
@@ -29,45 +29,21 @@ import org.springframework.ws.WebServiceMessageFactory;
*/
public abstract class AbstractWebServiceConnection implements WebServiceConnection {
+ private TransportInputStream tis;
+
+ private TransportOutputStream tos;
+
public final void send(WebServiceMessage message) throws IOException {
onSendBeforeWrite(message);
- TransportOutputStream tos = createTransportOutputStream();
- try {
- message.writeTo(tos);
- tos.flush();
- }
- finally {
- tos.close();
+ tos = createTransportOutputStream();
+ if (tos == null) {
+ return;
}
+ message.writeTo(tos);
+ tos.flush();
onSendAfterWrite(message);
}
- public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
- onReceiveBeforeRead();
- TransportInputStream tis = createTransportInputStream();
- if (tis == null) {
- return null;
- }
- WebServiceMessage message = null;
- try {
- message = messageFactory.createWebServiceMessage(tis);
- }
- finally {
- tis.close();
- }
- onReceiveAfterRead(message);
- return message;
- }
-
- /**
- * Returns a TransportOutputStream for the given message. Called from {@link
- * #send(WebServiceMessage)}.
- *
- * @return the output stream
- * @throws IOException when an I/O exception occurs
- */
- protected abstract TransportOutputStream createTransportOutputStream() throws IOException;
-
/**
* Called before the given message has been written to the TransportOutputStream. Called from {@link
* #send(WebServiceMessage)}.
@@ -80,6 +56,15 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
}
+ /**
+ * Returns a TransportOutputStream for the given message. Called from {@link
+ * #send(WebServiceMessage)}.
+ *
+ * @return the output stream
+ * @throws IOException when an I/O exception occurs
+ */
+ protected abstract TransportOutputStream createTransportOutputStream() throws IOException;
+
/**
* Called after the given message has been written to the TransportOutputStream. Called from {@link
* #send(WebServiceMessage)}.
@@ -92,13 +77,16 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
}
- /**
- * Returns a TransportInputStream. Called from {@link #receive(WebServiceMessageFactory)}.
- *
- * @return the input stream, or null if no response can be read
- * @throws IOException when an I/O exception occurs
- */
- protected abstract TransportInputStream createTransportInputStream() throws IOException;
+ public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
+ onReceiveBeforeRead();
+ tis = createTransportInputStream();
+ if (tis == null) {
+ return null;
+ }
+ WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
+ onReceiveAfterRead(message);
+ return message;
+ }
/**
* Called before a message has been read from the TransportInputStream. Called from {@link
@@ -111,6 +99,14 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
protected void onReceiveBeforeRead() throws IOException {
}
+ /**
+ * Returns a TransportInputStream. Called from {@link #receive(WebServiceMessageFactory)}.
+ *
+ * @return the input stream, or null if no response can be read
+ * @throws IOException when an I/O exception occurs
+ */
+ protected abstract TransportInputStream createTransportInputStream() throws IOException;
+
/**
* Called when the given message has been read from the TransportInputStream. Called from {@link
* #receive(WebServiceMessageFactory)}.
@@ -123,4 +119,36 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
protected void onReceiveAfterRead(WebServiceMessage message) throws IOException {
}
+ public final void close() throws IOException {
+ IOException ioex = null;
+ if (tis != null) {
+ try {
+ tis.close();
+ }
+ catch (IOException ex) {
+ ioex = ex;
+ }
+ }
+ if (tos != null) {
+ try {
+ tos.close();
+ }
+ catch (IOException ex) {
+ ioex = ex;
+ }
+ }
+ onClose();
+ if (ioex != null) {
+ throw ioex;
+ }
+ }
+
+ /**
+ * Template method invoked from {@link #close()}. Default implementation is empty.
+ *
+ * @throws IOException if an I/O error occurs when closing this connection
+ */
+ protected void onClose() 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 58fe1a79..3648efae 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
@@ -77,7 +77,8 @@ public class CommonsHttpConnection extends AbstractHttpSenderConnection {
throw new URISyntaxException("", ex.getMessage());
}
}
-/*
+
+ /*
* Sending request
*/