Skip to content

Commit b0b9e56

Browse files
committed
SWS-784 - Add URLPathEndpointMapping Feature
1 parent 38ada5e commit b0b9e56

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

core/src/main/java/org/springframework/ws/server/endpoint/mapping/UriEndpointMapping.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 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.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,29 +26,48 @@
2626
import org.springframework.ws.transport.context.TransportContextHolder;
2727

2828
/**
29-
* Implementation of the <code>EndpointMapping</code> interface to map from the full request URI to endpoint beans.
30-
* Supports both mapping to bean instances and mapping to bean names: the latter is required for prototype handlers.
29+
* Implementation of the {@code EndpointMapping} interface to map from the full request URI or request URI path to
30+
* endpoint beans. Supports both mapping to bean instances and mapping to bean names: the latter is required for
31+
* prototype handlers.
3132
* <p/>
32-
* The <code>endpointMap</code> property is suitable for populating the endpoint map with bean references, e.g. via the
33-
* map element in XML bean definitions.
33+
* When the {@link #setUsePath(boolean) usePath} property is enabled, the mapping will be based on the URI path rather
34+
* than the full URI.
3435
* <p/>
35-
* Mappings to bean names can be set via the <code>mappings</code> property, in a form accepted by the
36-
* <code>java.util.Properties</code> class, like as follows:
36+
* The {@code endpointMap} property is suitable for populating the endpoint map with bean references, e.g. via the map
37+
* element in XML bean definitions.
38+
* <p/>
39+
* Mappings to bean names can be set via the {@code mappings} property, in a form accepted by the {@code
40+
* java.util.Properties} class, like as follows:
3741
* <pre>
3842
* http://example.com:8080/services/bookFlight=bookFlightEndpoint
3943
* jms://exampleQueue=getFlightsEndpoint
4044
* </pre>
41-
* The syntax is URI=ENDPOINT_BEAN_NAME.
45+
* or, when the {@code usePath} property is enabled:
46+
* <pre>
47+
* /services/bookFlight=bookFlightEndpoint
48+
* </pre>
49+
* The syntax is [URI|PATH]=ENDPOINT_BEAN_NAME.
4250
* <p/>
4351
* This endpoint mapping does not read from the request message, and therefore is more suitable for message factories
44-
* which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the
45-
* <code>payloadCaching</code> disabled). However, this endpoint mapping obviously is transport specific.
52+
* which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the {@code
53+
* payloadCaching} disabled). However, this endpoint mapping obviously is transport specific.
4654
*
4755
* @author Arjen Poutsma
4856
* @since 1.5.0
4957
*/
5058
public class UriEndpointMapping extends AbstractMapBasedEndpointMapping {
5159

60+
private boolean usePath = false;
61+
62+
/**
63+
* Indicates whether the path should be used instead of the full URI. Default is {@code false}.
64+
*
65+
* @since 2.1.1
66+
*/
67+
public void setUsePath(boolean usePath) {
68+
this.usePath = usePath;
69+
}
70+
5271
@Override
5372
protected boolean validateLookupKey(String key) {
5473
try {
@@ -66,7 +85,13 @@ protected String getLookupKeyForMessage(MessageContext messageContext) throws Ex
6685
if (transportContext != null) {
6786
WebServiceConnection connection = transportContext.getConnection();
6887
if (connection != null) {
69-
return connection.getUri().toString();
88+
URI connectionUri = connection.getUri();
89+
if (usePath) {
90+
return connectionUri.getPath();
91+
}
92+
else {
93+
return connectionUri.toString();
94+
}
7095
}
7196
}
7297
return null;

core/src/test/java/org/springframework/ws/server/endpoint/mapping/UriEndpointMappingTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 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.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -50,7 +50,7 @@ public void clearContext() {
5050
}
5151

5252
@Test
53-
public void testGetLookupKeyForMessage() throws Exception {
53+
public void getLookupKeyForMessage() throws Exception {
5454
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
5555
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
5656

@@ -64,6 +64,23 @@ public void testGetLookupKeyForMessage() throws Exception {
6464
verify(connectionMock);
6565
}
6666

67+
@Test
68+
public void getLookupKeyForMessagePath() throws Exception {
69+
mapping.setUsePath(true);
70+
71+
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
72+
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
73+
74+
URI uri = new URI("http://example.com/foo/bar");
75+
expect(connectionMock.getUri()).andReturn(uri);
76+
77+
replay(connectionMock);
78+
79+
Assert.assertEquals("Invalid lookup key", "/foo/bar", mapping.getLookupKeyForMessage(context));
80+
81+
verify(connectionMock);
82+
}
83+
6784
@Test
6885
public void testValidateLookupKey() throws Exception {
6986
Assert.assertTrue("URI not valid", mapping.validateLookupKey("http://example.com/services"));

0 commit comments

Comments
 (0)