Skip to content

Commit 5381c16

Browse files
committed
Fixed #SWS-86: Stream closed before response read with WebServiceTemplate + Axis SAAJ Soap Messages
1 parent 81258c9 commit 5381c16

17 files changed

+748
-286
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2007 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.client.core;
18+
19+
import java.io.IOException;
20+
import javax.xml.transform.Source;
21+
22+
/**
23+
* Callback interface for extracting a result object from a {@link javax.xml.transform.Source} instance.
24+
* <p/>
25+
* Used for output object creation in {@link WebServiceTemplate}. Alternatively, output sources can also be returned to
26+
* client code as-is. In case of a source as execution result, you will almost always want to implement a
27+
* <code>SourceExtractor</code>, to be able to read the message content in a managed fashion, with the connection still
28+
* open while reading the message.
29+
* <p/>
30+
* Implementations of this interface perform the actual work of extracting results, but don't need to worry about
31+
* exception handling, or resource handling.
32+
*
33+
* @author Arjen Poutsma
34+
* @see org.springframework.ws.client.core.WebServiceTemplate
35+
*/
36+
public interface SourceExtractor {
37+
38+
/**
39+
* Process the data in the given <code>Source</code>, creating a corresponding result object.
40+
*
41+
* @param source the message payload to extract data from
42+
* @return an arbitrary result object, or <code>null</code> if none (the extractor will typically be stateful in the
43+
* latter case)
44+
* @throws IOException in case of I/O errors
45+
*/
46+
Object extractData(Source source) throws IOException;
47+
48+
}

core/src/main/java/org/springframework/ws/client/core/WebServiceMessageCallback.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@
2828
*/
2929
public interface WebServiceMessageCallback {
3030

31+
/**
32+
* Gets called by <code>WebServiceTemplate.sendAndReceice</code> with a <code>WebServiceMessage</code>.
33+
*
34+
* @param message the message
35+
* @throws IOException in case of I/O errors
36+
*/
3137
void doInMessage(WebServiceMessage message) throws IOException;
3238
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2007 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.client.core;
18+
19+
import java.io.IOException;
20+
21+
import org.springframework.ws.WebServiceMessage;
22+
23+
/**
24+
* Callback interface for extracting a result object from a {@link WebServiceMessage} instance.
25+
* <p/>
26+
* Used for output object creation in {@link WebServiceTemplate}. Alternatively, output messages can also be returned to
27+
* client code as-is. In case of a message as execution result, you will almost always want to implement a
28+
* <code>WebServiceMessageExtractor</code>, to be able to read the message in a managed fashion, with the connection
29+
* still open while reading the message.
30+
* <p/>
31+
* Implementations of this interface perform the actual work of extracting results, but don't need to worry about
32+
* exception handling, or resource handling.
33+
*
34+
* @author Arjen Poutsma
35+
*/
36+
public interface WebServiceMessageExtractor {
37+
38+
/**
39+
* Process the data in the given <code>WebServiceMessage</code>, creating a corresponding result object.
40+
*
41+
* @param message the message to extract data from (possibly a <code>SoapMessage</code>)
42+
* @return an arbitrary result object, or <code>null</code> if none (the extractor will typically be stateful in the
43+
* latter case)
44+
* @throws IOException in case of I/O errors
45+
*/
46+
Object extractData(WebServiceMessage message) throws IOException;
47+
48+
}

core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import javax.xml.transform.Result;
2121
import javax.xml.transform.Source;
2222

23-
import org.springframework.ws.WebServiceMessage;
24-
2523
/**
2624
* Specifies a basic set of Web service operations. Implemented by {@link WebServiceTemplate}. Not often used directly,
2725
* but a useful option to enhance testability, as it can easily be mocked or stubbed.
@@ -32,77 +30,100 @@
3230
public interface WebServiceOperations {
3331

3432
/**
35-
* Sends a web service message that contains the given payload. Returns the payload of the response message, if
36-
* any.
33+
* Sends a web service message that contains the given payload, marshalled by the configured
34+
* <code>Marshaller</code>. Returns the unmarshalled payload of the response message, if any.
3735
*
38-
* @param requestPayload the payload of the request message
39-
* @return the payload of the response message, or <code>null</code> if no response is given
36+
* @param requestPayload the object to marshal into the request message payload
37+
* @return the unmarshalled payload of the response message, or <code>null</code> if no response is given
38+
* @throws IOException in case of I/O errors
39+
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
40+
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
4041
*/
41-
Source sendAndReceive(Source requestPayload) throws IOException;
42+
Object marshalSendAndReceive(Object requestPayload) throws IOException;
4243

4344
/**
44-
* Sends a web service message that contains the given payload. Returns the payload of the response message, if any.
45-
* The given callback allows changing of the request message after the payload has been written to it.
45+
* Sends a web service message that contains the given payload, marshalled by the configured
46+
* <code>Marshaller</code>. Returns the unmarshalled payload of the response message, if any. The given callback
47+
* allows changing of the request message after the payload has been marshalled to it.
4648
*
47-
* @param requestPayload the payload of the request message
49+
* @param requestPayload the object to marshal into the request message payload
4850
* @param requestCallback callback to change message, can be <code>null</code>
49-
* @return the payload of the response message, or <code>null</code> if no response is given
51+
* @return the unmarshalled payload of the response message, or <code>null</code> if no response is given
52+
* @throws IOException in case of I/O errors
53+
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
54+
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
55+
*/
56+
Object marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback requestCallback) throws IOException;
57+
58+
/**
59+
* Sends a web service message that contains the given payload, reading the result with a
60+
* <code>SourceExtractor</code>.
61+
*
62+
* @param requestPayload the payload of the request message
63+
* @param responseExtractor object that will extract results
64+
* @return an arbitrary result object, as returned by the <code>SourceExtractor</code>
65+
*/
66+
Object sendAndReceive(Source requestPayload, SourceExtractor responseExtractor) throws IOException;
67+
68+
/**
69+
* Sends a web service message that contains the given payload, reading the result with a
70+
* <code>SourceExtractor</code>.
71+
* <p/>
72+
* The given callback allows changing of the request message after the payload has been written to it.
73+
*
74+
* @param requestPayload the payload of the request message
75+
* @param requestCallback callback to change message, can be <code>null</code>
76+
* @param responseExtractor object that will extract results
77+
* @return an arbitrary result object, as returned by the <code>SourceExtractor</code>
5078
*/
51-
Source sendAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback) throws IOException;
79+
Object sendAndReceive(Source requestPayload,
80+
WebServiceMessageCallback requestCallback,
81+
SourceExtractor responseExtractor) throws IOException;
5282

5383
/**
5484
* Sends a web service message that contains the given payload. Writes the response, if any, to the given
5585
* <code>Result</code>.
5686
*
5787
* @param requestPayload the payload of the request message
5888
* @param responseResult the result to write the response payload to
59-
* @return <code>true</code> if a response was received; <code>false</code> otherwise
89+
* @throws IOException in case of I/O errors
6090
*/
61-
boolean sendAndReceive(Source requestPayload, Result responseResult) throws IOException;
91+
void sendAndReceive(Source requestPayload, Result responseResult) throws IOException;
6292

6393
/**
6494
* Sends a web service message that contains the given payload. Writes the response, if any, to the given
65-
* <code>Result</code>. The given callback allows changing of the request message after the payload has been written
66-
* to it.
95+
* <code>Result</code>.
96+
* <p/>
97+
* The given callback allows changing of the request message after the payload has been written to it.
6798
*
6899
* @param requestPayload the payload of the request message
69100
* @param requestCallback callback to change message, can be <code>null</code>
70101
* @param responseResult the result to write the response payload to
71-
* @return <code>true</code> if a response was received; <code>false</code> otherwise
102+
* @throws IOException in case of I/O errors
72103
*/
73-
boolean sendAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback, Result responseResult)
104+
void sendAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback, Result responseResult)
74105
throws IOException;
75106

76107
/**
77-
* Sends a web service message that contains the given payload, marshalled by the configured
78-
* <code>Marshaller</code>. Returns the unmarshalled payload of the response message, if any.
79-
*
80-
* @param requestPayload the object to marshal into the request message payload
81-
* @return the unmarshalled payload of the response message, or <code>null</code> if no response is given
82-
* @see org.springframework.ws.client.core.WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
83-
* @see org.springframework.ws.client.core.WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
84-
*/
85-
Object marshalSendAndReceive(Object requestPayload) throws IOException;
86-
87-
/**
88-
* Sends a web service message that contains the given payload, marshalled by the configured
89-
* <code>Marshaller</code>. Returns the unmarshalled payload of the response message, if any. The given callback
90-
* allows changing of the request message after the payload has been marshalled to it.
108+
* Sends a web service message that can be manipulated with the given callback, reading the result with a
109+
* <code>WebServiceMessageExtractor</code>.
91110
*
92-
* @param requestPayload the object to marshal into the request message payload
93-
* @param requestCallback callback to change message, can be <code>null</code>
94-
* @return the unmarshalled payload of the response message, or <code>null</code> if no response is given
95-
* @see org.springframework.ws.client.core.WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
96-
* @see org.springframework.ws.client.core.WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
111+
* @param requestCallback the requestCallback to be used for manipulating the request message
112+
* @param responseExtractor object that will extract results
113+
* @return an arbitrary result object, as returned by the <code>WebServiceMessageExtractor</code>
114+
* @throws IOException in case of I/O errors
97115
*/
98-
Object marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback requestCallback) throws IOException;
116+
Object sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor responseExtractor)
117+
throws IOException;
99118

100119
/**
101-
* Sends a web service message that can be manipulated with the given callback. Returns the response message, if
102-
* any.
120+
* Sends a web service message that can be manipulated with the given callback, reading the result with a
121+
* <code>WebServiceMessageExtractor</code>.
103122
*
104-
* @param requestCallback the requestCallback to be used for manipulating the request message
105-
* @return the response message, or <code>null</code> if no response is given
123+
* @param requestCallback the callback to be used for manipulating the request message
124+
* @param responseCallback the callback to be used for manipulating the response message
125+
* @throws IOException in case of I/O errors
106126
*/
107-
WebServiceMessage sendAndReceive(WebServiceMessageCallback requestCallback) throws IOException;
127+
void sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback)
128+
throws IOException;
108129
}

0 commit comments

Comments
 (0)