Skip to content

Commit 8b82a42

Browse files
committed
SWS-398
1 parent 092879a commit 8b82a42

File tree

4 files changed

+129
-6
lines changed

4 files changed

+129
-6
lines changed

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

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.ws.client.WebServiceTransformerException;
4646
import org.springframework.ws.client.WebServiceTransportException;
4747
import org.springframework.ws.client.support.WebServiceAccessor;
48+
import org.springframework.ws.client.support.destination.DestinationProvider;
4849
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
4950
import org.springframework.ws.context.DefaultMessageContext;
5051
import org.springframework.ws.context.MessageContext;
@@ -119,14 +120,14 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService
119120

120121
private FaultMessageResolver faultMessageResolver;
121122

122-
private String defaultUri;
123-
124123
private boolean checkConnectionForError = true;
125124

126125
private boolean checkConnectionForFault = true;
127126

128127
private ClientInterceptor[] interceptors;
129128

129+
private DestinationProvider destinationProvider;
130+
130131
/** Creates a new <code>WebServiceTemplate</code> using default settings. */
131132
public WebServiceTemplate() {
132133
initDefaultStrategies();
@@ -144,11 +145,46 @@ public WebServiceTemplate(WebServiceMessageFactory messageFactory) {
144145

145146
/** Returns the default URI to be used on operations that do not have a URI parameter. */
146147
public String getDefaultUri() {
147-
return defaultUri;
148+
if (destinationProvider != null) {
149+
URI uri = destinationProvider.getUri();
150+
return uri != null ? uri.toString() : null;
151+
}
152+
else {
153+
return null;
154+
}
148155
}
149156

150157
/**
151158
* Set the default URI to be used on operations that do not have a URI parameter.
159+
* <p/>
160+
* Typically, either this property is set, or {@link #setDestinationProvider(DestinationProvider)}, but not both.
161+
*
162+
* @see #marshalSendAndReceive(Object)
163+
* @see #marshalSendAndReceive(Object,WebServiceMessageCallback)
164+
* @see #sendSourceAndReceiveToResult(Source,Result)
165+
* @see #sendSourceAndReceiveToResult(Source,WebServiceMessageCallback,Result)
166+
* @see #sendSourceAndReceive(Source,SourceExtractor)
167+
* @see #sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor)
168+
* @see #sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback)
169+
*/
170+
public void setDefaultUri(final String uri) {
171+
destinationProvider = new DestinationProvider() {
172+
173+
public URI getUri() {
174+
return URI.create(uri);
175+
}
176+
};
177+
}
178+
179+
/** Returns the destination provider used on operations that do not have a URI parameter. */
180+
public DestinationProvider getDestinationProvider() {
181+
return destinationProvider;
182+
}
183+
184+
/**
185+
* Set the destination provider URI to be used on operations that do not have a URI parameter.
186+
* <p/>
187+
* Typically, either this property is set, or {@link #setDefaultUri(String)}, but not both.
152188
*
153189
* @see #marshalSendAndReceive(Object)
154190
* @see #marshalSendAndReceive(Object,WebServiceMessageCallback)
@@ -158,8 +194,8 @@ public String getDefaultUri() {
158194
* @see #sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor)
159195
* @see #sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback)
160196
*/
161-
public void setDefaultUri(String uri) {
162-
defaultUri = uri;
197+
public void setDestinationProvider(DestinationProvider destinationProvider) {
198+
this.destinationProvider = destinationProvider;
163199
}
164200

165201
/** Returns the marshaller for this template. */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2008 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.support.destination;
18+
19+
import java.net.URI;
20+
21+
/**
22+
* Strategy interface for providing a {@link org.springframework.ws.client.core.WebServiceTemplate} destination URI at
23+
* runtime.
24+
* <p/>
25+
* Typically implemented by providers that use WSDL, a UDDI registry, or some other form to determine the destination
26+
* URI.
27+
*
28+
* @author Arjen Poutsma
29+
* @since 1.5.4
30+
*/
31+
public interface DestinationProvider {
32+
33+
/**
34+
* Return the destination URI.
35+
*
36+
* @return the destination URI
37+
*/
38+
URI getUri();
39+
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
Provides the <code>DestinationProvider</code> interface.
4+
</body>
5+
</html>

core/src/test/java/org/springframework/ws/client/core/WebServiceTemplateTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.ws.MockWebServiceMessage;
2828
import org.springframework.ws.MockWebServiceMessageFactory;
2929
import org.springframework.ws.client.WebServiceTransportException;
30+
import org.springframework.ws.client.support.destination.DestinationProvider;
3031
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
3132
import org.springframework.ws.context.DefaultMessageContext;
3233
import org.springframework.ws.context.MessageContext;
@@ -52,8 +53,8 @@ protected void setUp() throws Exception {
5253
template.setMessageFactory(messageFactory);
5354
connectionControl = MockControl.createStrictControl(FaultAwareWebServiceConnection.class);
5455
connectionMock = (FaultAwareWebServiceConnection) connectionControl.getMock();
55-
connectionControl.expectAndDefaultReturn(connectionMock.getUri(), new URI("mock"));
5656
final URI expectedUri = new URI("http://www.springframework.org/spring-ws");
57+
connectionControl.expectAndDefaultReturn(connectionMock.getUri(), expectedUri);
5758
template.setMessageSender(new WebServiceMessageSender() {
5859

5960
public WebServiceConnection createConnection(URI uri) throws IOException {
@@ -505,4 +506,45 @@ public void testInterceptorsInterceptedCreateResponse() throws Exception {
505506
interceptorControl.verify();
506507
}
507508

509+
public void testDestinationResolver() throws Exception {
510+
MockControl providerControl = MockControl.createControl(DestinationProvider.class);
511+
DestinationProvider providerMock = (DestinationProvider) providerControl.getMock();
512+
final URI providerUri = new URI("http://www.springframework.org/spring-ws/destinationProvider");
513+
providerControl.expectAndReturn(providerMock.getUri(), providerUri);
514+
template.setDestinationProvider(providerMock);
515+
providerControl.replay();
516+
517+
template.setMessageSender(new WebServiceMessageSender() {
518+
519+
public WebServiceConnection createConnection(URI uri) throws IOException {
520+
return connectionMock;
521+
}
522+
523+
public boolean supports(URI uri) {
524+
assertEquals("Invalid uri", providerUri, uri);
525+
return true;
526+
}
527+
});
528+
529+
MockControl extractorControl = MockControl.createControl(WebServiceMessageExtractor.class);
530+
WebServiceMessageExtractor extractorMock = (WebServiceMessageExtractor) extractorControl.getMock();
531+
extractorControl.replay();
532+
533+
connectionControl.reset();
534+
connectionControl.expectAndDefaultReturn(connectionMock.getUri(), providerUri);
535+
connectionMock.send(null);
536+
connectionControl.setMatcher(MockControl.ALWAYS_MATCHER);
537+
connectionControl.expectAndReturn(connectionMock.hasError(), false);
538+
connectionControl.expectAndReturn(connectionMock.receive(messageFactory), null);
539+
connectionMock.close();
540+
connectionControl.replay();
541+
542+
Object result = template.sendAndReceive(null, extractorMock);
543+
assertNull("Invalid response", result);
544+
extractorControl.verify();
545+
connectionControl.verify();
546+
providerControl.verify();
547+
}
548+
549+
508550
}

0 commit comments

Comments
 (0)