Skip to content

Commit 66b0e49

Browse files
committed
Made WebServiceMessageFactory generic
SWS-631 - ResponseCallback -> ResponseCreator
1 parent bc2976a commit 66b0e49

20 files changed

+155
-118
lines changed

core/src/main/java/org/springframework/ws/WebServiceMessageFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,14 +29,14 @@
2929
* @see org.springframework.ws.WebServiceMessage
3030
* @since 1.0.0
3131
*/
32-
public interface WebServiceMessageFactory {
32+
public interface WebServiceMessageFactory<T extends WebServiceMessage> {
3333

3434
/**
3535
* Creates a new, empty <code>WebServiceMessage</code>.
3636
*
3737
* @return the empty message
3838
*/
39-
WebServiceMessage createWebServiceMessage();
39+
T createWebServiceMessage();
4040

4141
/**
4242
* Reads a {@link WebServiceMessage} from the given input stream.
@@ -48,6 +48,6 @@ public interface WebServiceMessageFactory {
4848
* @return the created message
4949
* @throws java.io.IOException if an I/O exception occurs
5050
*/
51-
WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException;
51+
T createWebServiceMessage(InputStream inputStream) throws IOException;
5252

5353
}

core/src/main/java/org/springframework/ws/pox/dom/DomPoxMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
3737
* @see org.springframework.ws.pox.dom.DomPoxMessage
3838
* @since 1.0.0
3939
*/
40-
public class DomPoxMessageFactory extends TransformerObjectSupport implements WebServiceMessageFactory {
40+
public class DomPoxMessageFactory extends TransformerObjectSupport implements WebServiceMessageFactory<DomPoxMessage> {
4141

4242
/** The default content type for the POX messages. */
4343
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.ws.soap;
1818

19-
import java.io.IOException;
20-
import java.io.InputStream;
21-
2219
import org.springframework.ws.WebServiceMessageFactory;
2320

2421
/**
@@ -30,7 +27,7 @@
3027
* @author Arjen Poutsma
3128
* @since 1.0.0
3229
*/
33-
public interface SoapMessageFactory extends WebServiceMessageFactory {
30+
public interface SoapMessageFactory<T extends SoapMessage> extends WebServiceMessageFactory<T> {
3431

3532
/**
3633
* Sets the SOAP Version used by this factory.
@@ -41,24 +38,4 @@ public interface SoapMessageFactory extends WebServiceMessageFactory {
4138
*/
4239
void setSoapVersion(SoapVersion version);
4340

44-
/**
45-
* Creates a new, empty <code>SoapMessage</code>.
46-
*
47-
* @return the empty message
48-
*/
49-
SoapMessage createWebServiceMessage();
50-
51-
/**
52-
* Reads a {@link SoapMessage} from the given input stream.
53-
* <p/>
54-
* If the given stream is an instance of {@link org.springframework.ws.transport.TransportInputStream
55-
* TransportInputStream}, the headers will be read from the request.
56-
*
57-
* @param inputStream the input stream to read the message from
58-
* @return the created message
59-
* @throws java.io.IOException if an I/O exception occurs
60-
*/
61-
SoapMessage createWebServiceMessage(InputStream inputStream) throws IOException;
62-
63-
6441
}

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@
7979
* @since 1.0.0
8080
*/
8181
@SuppressWarnings("Since15")
82-
public class AxiomSoapMessageFactory implements SoapMessageFactory, InitializingBean {
82+
public class AxiomSoapMessageFactory implements SoapMessageFactory<AxiomSoapMessage>, InitializingBean {
8383

8484
private static final String CHARSET_PARAMETER = "charset";
8585

core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@
5555
* @see org.springframework.ws.soap.saaj.SaajSoapMessage
5656
* @since 1.0.0
5757
*/
58-
public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingBean {
58+
public class SaajSoapMessageFactory implements SoapMessageFactory<SaajSoapMessage>, InitializingBean {
5959

6060
private static final Log logger = LogFactory.getLog(SaajSoapMessageFactory.class);
6161

core/src/test/java/org/springframework/ws/MockWebServiceMessageFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,13 @@
2121
import javax.xml.transform.TransformerException;
2222
import javax.xml.transform.stream.StreamSource;
2323

24-
public class MockWebServiceMessageFactory implements WebServiceMessageFactory {
24+
public class MockWebServiceMessageFactory implements WebServiceMessageFactory<MockWebServiceMessage> {
2525

26-
public WebServiceMessage createWebServiceMessage() {
26+
public MockWebServiceMessage createWebServiceMessage() {
2727
return new MockWebServiceMessage();
2828
}
2929

30-
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
30+
public MockWebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
3131
try {
3232
return new MockWebServiceMessage(new StreamSource(inputStream));
3333
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2005-2010 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.mock.client;
18+
19+
import java.io.IOException;
20+
import java.net.URI;
21+
22+
import org.springframework.ws.WebServiceMessage;
23+
import org.springframework.ws.WebServiceMessageFactory;
24+
import org.springframework.xml.transform.TransformerObjectSupport;
25+
26+
/**
27+
* Abstract base class for the {@link ResponseCreator} interface.
28+
* <p/>
29+
* Creates a response using the given {@link WebServiceMessageFactory}, and passes it on to {@link #doWithResponse(URI,
30+
* WebServiceMessage, WebServiceMessage)}.
31+
*
32+
* @author Arjen Poutsma
33+
* @since 2.0
34+
*/
35+
abstract class AbstractResponseCreator<T extends WebServiceMessage> extends TransformerObjectSupport
36+
implements ResponseCreator<T> {
37+
38+
public final T createResponse(URI uri, T request, WebServiceMessageFactory<T> messageFactory) throws IOException {
39+
T response = messageFactory.createWebServiceMessage();
40+
doWithResponse(uri, request, response);
41+
return response;
42+
}
43+
44+
/**
45+
* Execute any number of operations on the supplied response, given the request and URI.
46+
*
47+
* @param uri the URI
48+
* @param request the request message
49+
* @param response the response message
50+
* @throws IOException in case of I/O errors
51+
*/
52+
protected abstract void doWithResponse(URI uri, T request, T response) throws IOException;
53+
54+
}

test/src/main/java/org/springframework/ws/mock/client/ErrorResponseCallback.java renamed to test/src/main/java/org/springframework/ws/mock/client/ErrorResponseCreator.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@
2020
import java.net.URI;
2121

2222
import org.springframework.ws.WebServiceMessage;
23+
import org.springframework.ws.WebServiceMessageFactory;
2324

2425
/**
25-
* Implementation of {@link ResponseCallback} that holds an error message.
26+
* Implementation of {@link ResponseCreator} that holds an error message.
2627
*
2728
* @author Arjen Poutsma
2829
* @author Lukas Krecan
2930
* @since 2.0
3031
*/
31-
class ErrorResponseCallback implements ResponseCallback {
32+
class ErrorResponseCreator implements ResponseCreator<WebServiceMessage> {
3233

3334
private final String errorMessage;
3435

35-
ErrorResponseCallback(String errorMessage) {
36+
ErrorResponseCreator(String errorMessage) {
3637
this.errorMessage = errorMessage;
3738
}
3839

39-
public void doWithResponse(URI uri, WebServiceMessage response, WebServiceMessage request) throws IOException {
40+
public WebServiceMessage createResponse(URI uri,
41+
WebServiceMessage request,
42+
WebServiceMessageFactory<WebServiceMessage> factory) throws IOException {
4043
// Do nothing
44+
return null;
4145
}
4246

4347
String getErrorMessage() {

test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java renamed to test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCreator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,30 @@
2020
import java.net.URI;
2121

2222
import org.springframework.ws.WebServiceMessage;
23+
import org.springframework.ws.WebServiceMessageFactory;
2324

2425
/**
25-
* Implementation of {@link ResponseCallback} that responds by throwing either an {@link IOException} or a {@link
26+
* Implementation of {@link ResponseCreator} that responds by throwing either an {@link IOException} or a {@link
2627
* RuntimeException}.
2728
*
2829
* @author Arjen Poutsma
2930
* @since 2.0
3031
*/
31-
class ExceptionResponseCallback implements ResponseCallback {
32+
class ExceptionResponseCreator implements ResponseCreator<WebServiceMessage> {
3233

3334
private final Exception exception;
3435

35-
ExceptionResponseCallback(IOException exception) {
36+
ExceptionResponseCreator(IOException exception) {
3637
this.exception = exception;
3738
}
3839

39-
ExceptionResponseCallback(RuntimeException exception) {
40+
ExceptionResponseCreator(RuntimeException exception) {
4041
this.exception = exception;
4142
}
4243

43-
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
44+
public WebServiceMessage createResponse(URI uri,
45+
WebServiceMessage request,
46+
WebServiceMessageFactory<WebServiceMessage> factory) throws IOException {
4447
if (exception instanceof IOException) {
4548
throw (IOException) exception;
4649
}

test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
4444

4545
private WebServiceMessage request;
4646

47-
private ResponseCallback responseCallback;
47+
private ResponseCreator responseCreator;
4848

4949
void addRequestMatcher(RequestMatcher requestMatcher) {
5050
Assert.notNull(requestMatcher, "'requestMatcher' must not be null");
@@ -67,13 +67,14 @@ public ResponseActions andExpect(RequestMatcher requestMatcher) {
6767
return this;
6868
}
6969

70-
public void andRespond(ResponseCallback responseCallback) {
71-
Assert.notNull(responseCallback, "'responseCallback' must not be null");
72-
this.responseCallback = responseCallback;
70+
public void andRespond(ResponseCreator responseCreator) {
71+
Assert.notNull(responseCreator, "'responseCreator' must not be null");
72+
this.responseCreator = responseCreator;
7373
}
7474

7575
// FaultAwareWebServiceConnection implementation
7676

77+
@SuppressWarnings("unchecked")
7778
public void send(WebServiceMessage message) throws IOException {
7879
if (!requestMatchers.isEmpty()) {
7980
for (RequestMatcher requestMatcher : requestMatchers) {
@@ -86,11 +87,10 @@ public void send(WebServiceMessage message) throws IOException {
8687
this.request = message;
8788
}
8889

90+
@SuppressWarnings("unchecked")
8991
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
90-
if (responseCallback != null) {
91-
WebServiceMessage response = messageFactory.createWebServiceMessage();
92-
responseCallback.doWithResponse(uri, request, response);
93-
return response;
92+
if (responseCreator != null) {
93+
return responseCreator.createResponse(uri, request, messageFactory);
9494
}
9595
else {
9696
return null;
@@ -102,20 +102,20 @@ public URI getUri() {
102102
}
103103

104104
public boolean hasError() throws IOException {
105-
return responseCallback instanceof ErrorResponseCallback;
105+
return responseCreator instanceof ErrorResponseCreator;
106106
}
107107

108108
public String getErrorMessage() throws IOException {
109-
if (responseCallback instanceof ErrorResponseCallback) {
110-
return ((ErrorResponseCallback) responseCallback).getErrorMessage();
109+
if (responseCreator instanceof ErrorResponseCreator) {
110+
return ((ErrorResponseCreator) responseCreator).getErrorMessage();
111111
}
112112
else {
113113
return null;
114114
}
115115
}
116116

117117
public boolean hasFault() throws IOException {
118-
return responseCallback instanceof SoapFaultResponseCallback;
118+
return responseCreator instanceof SoapFaultResponseCallback;
119119
}
120120

121121
public void setFault(boolean fault) throws IOException {
@@ -125,7 +125,7 @@ public void setFault(boolean fault) throws IOException {
125125
public void close() throws IOException {
126126
requestMatchers.clear();
127127
request = null;
128-
responseCallback = null;
128+
responseCreator = null;
129129
uri = null;
130130
if (lastConnection) {
131131
MockWebServiceMessageSenderHolder.clear();

0 commit comments

Comments
 (0)