SWS-784 - Add URLPathEndpointMapping Feature
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -26,29 +26,48 @@ import org.springframework.ws.transport.context.TransportContext;
|
||||
import org.springframework.ws.transport.context.TransportContextHolder;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>EndpointMapping</code> interface to map from the full request URI to endpoint beans.
|
||||
* Supports both mapping to bean instances and mapping to bean names: the latter is required for prototype handlers.
|
||||
* Implementation of the {@code EndpointMapping} interface to map from the full request URI or request URI path to
|
||||
* endpoint beans. Supports both mapping to bean instances and mapping to bean names: the latter is required for
|
||||
* prototype handlers.
|
||||
* <p/>
|
||||
* The <code>endpointMap</code> property is suitable for populating the endpoint map with bean references, e.g. via the
|
||||
* map element in XML bean definitions.
|
||||
* When the {@link #setUsePath(boolean) usePath} property is enabled, the mapping will be based on the URI path rather
|
||||
* than the full URI.
|
||||
* <p/>
|
||||
* Mappings to bean names can be set via the <code>mappings</code> property, in a form accepted by the
|
||||
* <code>java.util.Properties</code> class, like as follows:
|
||||
* The {@code endpointMap} property is suitable for populating the endpoint map with bean references, e.g. via the map
|
||||
* element in XML bean definitions.
|
||||
* <p/>
|
||||
* Mappings to bean names can be set via the {@code mappings} property, in a form accepted by the {@code
|
||||
* java.util.Properties} class, like as follows:
|
||||
* <pre>
|
||||
* http://example.com:8080/services/bookFlight=bookFlightEndpoint
|
||||
* jms://exampleQueue=getFlightsEndpoint
|
||||
* </pre>
|
||||
* The syntax is URI=ENDPOINT_BEAN_NAME.
|
||||
* or, when the {@code usePath} property is enabled:
|
||||
* <pre>
|
||||
* /services/bookFlight=bookFlightEndpoint
|
||||
* </pre>
|
||||
* The syntax is [URI|PATH]=ENDPOINT_BEAN_NAME.
|
||||
* <p/>
|
||||
* This endpoint mapping does not read from the request message, and therefore is more suitable for message factories
|
||||
* which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the
|
||||
* <code>payloadCaching</code> disabled). However, this endpoint mapping obviously is transport specific.
|
||||
* which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the {@code
|
||||
* payloadCaching} disabled). However, this endpoint mapping obviously is transport specific.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class UriEndpointMapping extends AbstractMapBasedEndpointMapping {
|
||||
|
||||
private boolean usePath = false;
|
||||
|
||||
/**
|
||||
* Indicates whether the path should be used instead of the full URI. Default is {@code false}.
|
||||
*
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public void setUsePath(boolean usePath) {
|
||||
this.usePath = usePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateLookupKey(String key) {
|
||||
try {
|
||||
@@ -66,7 +85,13 @@ public class UriEndpointMapping extends AbstractMapBasedEndpointMapping {
|
||||
if (transportContext != null) {
|
||||
WebServiceConnection connection = transportContext.getConnection();
|
||||
if (connection != null) {
|
||||
return connection.getUri().toString();
|
||||
URI connectionUri = connection.getUri();
|
||||
if (usePath) {
|
||||
return connectionUri.getPath();
|
||||
}
|
||||
else {
|
||||
return connectionUri.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -50,7 +50,7 @@ public class UriEndpointMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
public void getLookupKeyForMessage() throws Exception {
|
||||
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
|
||||
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
|
||||
|
||||
@@ -64,6 +64,23 @@ public class UriEndpointMappingTest {
|
||||
verify(connectionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLookupKeyForMessagePath() throws Exception {
|
||||
mapping.setUsePath(true);
|
||||
|
||||
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
|
||||
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
|
||||
|
||||
URI uri = new URI("http://example.com/foo/bar");
|
||||
expect(connectionMock.getUri()).andReturn(uri);
|
||||
|
||||
replay(connectionMock);
|
||||
|
||||
Assert.assertEquals("Invalid lookup key", "/foo/bar", mapping.getLookupKeyForMessage(context));
|
||||
|
||||
verify(connectionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateLookupKey() throws Exception {
|
||||
Assert.assertTrue("URI not valid", mapping.validateLookupKey("http://example.com/services"));
|
||||
|
||||
Reference in New Issue
Block a user