Skip to content

Commit 921e1ea

Browse files
committed
SWS-333
1 parent f3077e3 commit 921e1ea

File tree

4 files changed

+67
-69
lines changed

4 files changed

+67
-69
lines changed

core/src/main/java/org/springframework/ws/transport/AbstractReceiverConnection.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ protected final TransportOutputStream createTransportOutputStream() throws IOExc
4747
return responseOutputStream;
4848
}
4949

50-
public final void close() throws IOException {
51-
try {
52-
if (requestInputStream != null) {
53-
requestInputStream.close();
54-
}
55-
}
56-
finally {
57-
onClose();
58-
}
59-
}
60-
6150
/**
6251
* Template method invoked from {@link #close()}. Default implementation is empty.
6352
*
@@ -108,11 +97,6 @@ public Iterator getHeaders(String name) throws IOException {
10897
return getRequestHeaders(name);
10998
}
11099

111-
public void close() throws IOException {
112-
// defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
113-
}
114-
115-
116100
}
117101

118102
/** Implementation of <code>TransportOutputStream</code> for sending-side connections. */

core/src/main/java/org/springframework/ws/transport/AbstractSenderConnection.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ protected final TransportInputStream createTransportInputStream() throws IOExcep
5252
}
5353
}
5454

55-
public final void close() throws IOException {
56-
try {
57-
if (responseInputStream != null) {
58-
responseInputStream.close();
59-
}
60-
}
61-
finally {
62-
onClose();
63-
}
64-
}
65-
6655
/**
6756
* Template method invoked from {@link #close()}. Default implementation is empty.
6857
*
@@ -128,10 +117,6 @@ public Iterator getHeaders(String name) throws IOException {
128117
return getResponseHeaders(name);
129118
}
130119

131-
public void close() throws IOException {
132-
// defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
133-
}
134-
135120
}
136121

137122
}

core/src/main/java/org/springframework/ws/transport/AbstractWebServiceConnection.java

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,31 @@
2929
*/
3030
public abstract class AbstractWebServiceConnection implements WebServiceConnection {
3131

32+
private TransportInputStream tis;
33+
34+
private TransportOutputStream tos;
35+
3236
public final void send(WebServiceMessage message) throws IOException {
3337
onSendBeforeWrite(message);
34-
TransportOutputStream tos = createTransportOutputStream();
35-
try {
36-
message.writeTo(tos);
37-
tos.flush();
38-
}
39-
finally {
40-
tos.close();
38+
tos = createTransportOutputStream();
39+
if (tos == null) {
40+
return;
4141
}
42+
message.writeTo(tos);
43+
tos.flush();
4244
onSendAfterWrite(message);
4345
}
4446

45-
public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
46-
onReceiveBeforeRead();
47-
TransportInputStream tis = createTransportInputStream();
48-
if (tis == null) {
49-
return null;
50-
}
51-
WebServiceMessage message = null;
52-
try {
53-
message = messageFactory.createWebServiceMessage(tis);
54-
}
55-
finally {
56-
tis.close();
57-
}
58-
onReceiveAfterRead(message);
59-
return message;
47+
/**
48+
* Called before the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
49+
* #send(WebServiceMessage)}.
50+
* <p/>
51+
* Default implementation does nothing.
52+
*
53+
* @param message the message
54+
* @throws IOException when an I/O exception occurs
55+
*/
56+
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
6057
}
6158

6259
/**
@@ -69,27 +66,37 @@ public final WebServiceMessage receive(WebServiceMessageFactory messageFactory)
6966
protected abstract TransportOutputStream createTransportOutputStream() throws IOException;
7067

7168
/**
72-
* Called before the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
69+
* Called after the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
7370
* #send(WebServiceMessage)}.
7471
* <p/>
7572
* Default implementation does nothing.
7673
*
7774
* @param message the message
7875
* @throws IOException when an I/O exception occurs
7976
*/
80-
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
77+
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
78+
}
79+
80+
public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
81+
onReceiveBeforeRead();
82+
tis = createTransportInputStream();
83+
if (tis == null) {
84+
return null;
85+
}
86+
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
87+
onReceiveAfterRead(message);
88+
return message;
8189
}
8290

8391
/**
84-
* Called after the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
85-
* #send(WebServiceMessage)}.
92+
* Called before a message has been read from the <code>TransportInputStream</code>. Called from {@link
93+
* #receive(WebServiceMessageFactory)}.
8694
* <p/>
8795
* Default implementation does nothing.
8896
*
89-
* @param message the message
9097
* @throws IOException when an I/O exception occurs
9198
*/
92-
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
99+
protected void onReceiveBeforeRead() throws IOException {
93100
}
94101

95102
/**
@@ -101,26 +108,47 @@ protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
101108
protected abstract TransportInputStream createTransportInputStream() throws IOException;
102109

103110
/**
104-
* Called before a message has been read from the <code>TransportInputStream</code>. Called from {@link
111+
* Called when the given message has been read from the <code>TransportInputStream</code>. Called from {@link
105112
* #receive(WebServiceMessageFactory)}.
106113
* <p/>
107114
* Default implementation does nothing.
108115
*
116+
* @param message the message
109117
* @throws IOException when an I/O exception occurs
110118
*/
111-
protected void onReceiveBeforeRead() throws IOException {
119+
protected void onReceiveAfterRead(WebServiceMessage message) throws IOException {
120+
}
121+
122+
public final void close() throws IOException {
123+
IOException ioex = null;
124+
if (tis != null) {
125+
try {
126+
tis.close();
127+
}
128+
catch (IOException ex) {
129+
ioex = ex;
130+
}
131+
}
132+
if (tos != null) {
133+
try {
134+
tos.close();
135+
}
136+
catch (IOException ex) {
137+
ioex = ex;
138+
}
139+
}
140+
onClose();
141+
if (ioex != null) {
142+
throw ioex;
143+
}
112144
}
113145

114146
/**
115-
* Called when the given message has been read from the <code>TransportInputStream</code>. Called from {@link
116-
* #receive(WebServiceMessageFactory)}.
117-
* <p/>
118-
* Default implementation does nothing.
147+
* Template method invoked from {@link #close()}. Default implementation is empty.
119148
*
120-
* @param message the message
121-
* @throws IOException when an I/O exception occurs
149+
* @throws IOException if an I/O error occurs when closing this connection
122150
*/
123-
protected void onReceiveAfterRead(WebServiceMessage message) throws IOException {
151+
protected void onClose() throws IOException {
124152
}
125153

126154
}

core/src/main/java/org/springframework/ws/transport/http/CommonsHttpConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public URI getUri() throws URISyntaxException {
7777
throw new URISyntaxException("", ex.getMessage());
7878
}
7979
}
80-
/*
80+
81+
/*
8182
* Sending request
8283
*/
8384

0 commit comments

Comments
 (0)