Repository: camel Updated Branches: refs/heads/master f5098d138 -> 735ca601a
Added uripath endpoint mapping for spring-ws route endpoints Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/321b0dc1 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/321b0dc1 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/321b0dc1 Branch: refs/heads/master Commit: 321b0dc127c1d8fb0b3fa2425184474fab603893 Parents: f5098d1 Author: christophd <deppi...@consol.de> Authored: Thu Apr 16 11:58:24 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Apr 23 13:31:33 2015 +0200 ---------------------------------------------------------------------- .../spring/ws/bean/CamelEndpointMapping.java | 63 ++++++++++++++------ .../spring/ws/type/EndpointMappingType.java | 1 + ...ndpointMappingResponseHandlingRouteTest.java | 60 ++++++++++++++----- .../ws/ConsumerEndpointMappingRouteTest.java | 51 +++++++++++----- ...MappingResponseHandlingRouteTest-context.xml | 8 +++ ...ConsumerEndpointMappingRouteTest-context.xml | 8 +++ 6 files changed, 144 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java index 5e2896f..0bce22c 100644 --- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java +++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java @@ -16,19 +16,6 @@ */ package org.apache.camel.component.spring.ws.bean; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import javax.xml.namespace.QName; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLStreamException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; - -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.spring.ws.type.EndpointMappingKey; import org.apache.camel.component.spring.ws.type.EndpointMappingType; @@ -37,9 +24,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.ws.context.MessageContext; -import org.springframework.ws.server.EndpointInterceptor; -import org.springframework.ws.server.EndpointInvocationChain; -import org.springframework.ws.server.EndpointMapping; +import org.springframework.ws.server.*; import org.springframework.ws.server.endpoint.MessageEndpoint; import org.springframework.ws.server.endpoint.mapping.AbstractEndpointMapping; import org.springframework.ws.server.endpoint.support.PayloadRootUtils; @@ -50,6 +35,18 @@ import org.springframework.ws.transport.WebServiceConnection; import org.springframework.ws.transport.context.TransportContext; import org.springframework.ws.transport.context.TransportContextHolder; import org.springframework.xml.xpath.XPathExpression; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Spring {@link EndpointMapping} for mapping messages to corresponding Camel @@ -84,6 +81,7 @@ import org.springframework.xml.xpath.XPathExpression; public class CamelEndpointMapping extends AbstractEndpointMapping implements InitializingBean, CamelSpringWSEndpointMapping, SoapEndpointMapping { private static final String DOUBLE_QUOTE = "\""; + private static final String URI_PATH_WILDCARD = "*"; private Map<EndpointMappingKey, MessageEndpoint> endpoints = new ConcurrentHashMap<EndpointMappingKey, MessageEndpoint>(); private TransformerFactory transformerFactory; private XmlConverter xmlConverter; @@ -95,7 +93,7 @@ public class CamelEndpointMapping extends AbstractEndpointMapping implements Ini @Override protected Object getEndpointInternal(MessageContext messageContext) throws Exception { for (EndpointMappingKey key : endpoints.keySet()) { - Object messageKey = null; + String messageKey; switch (key.getType()) { case ROOT_QNAME: messageKey = getRootQName(messageContext); @@ -109,6 +107,18 @@ public class CamelEndpointMapping extends AbstractEndpointMapping implements Ini case URI: messageKey = getUri(); break; + case URI_PATH: + messageKey = getUriPath(); + + if (messageKey != null && key.getLookupKey().endsWith(URI_PATH_WILDCARD)) { + String lookupKey = key.getLookupKey().substring(0, key.getLookupKey().length() - 1); + + if (messageKey.startsWith(lookupKey)) { + return endpoints.get(key); + } + } + + break; default: throw new RuntimeCamelException("Invalid mapping type specified. Supported types are: root QName, SOAP action, XPath expression and URI"); } @@ -145,11 +155,28 @@ public class CamelEndpointMapping extends AbstractEndpointMapping implements Ini } private String getUri() throws URISyntaxException { + WebServiceConnection webServiceConnection = getWeServiceConnection(); + if (webServiceConnection != null) { + return webServiceConnection.getUri().toString(); + } + return null; + } + + private String getUriPath() throws URISyntaxException { + WebServiceConnection webServiceConnection = getWeServiceConnection(); + if (webServiceConnection != null) { + return webServiceConnection.getUri().getPath(); + } + + return null; + } + + private WebServiceConnection getWeServiceConnection() { TransportContext transportContext = TransportContextHolder.getTransportContext(); if (transportContext != null) { WebServiceConnection webServiceConnection = transportContext.getConnection(); if (webServiceConnection != null) { - return webServiceConnection.getUri().toString(); + return webServiceConnection; } } return null; http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/type/EndpointMappingType.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/type/EndpointMappingType.java b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/type/EndpointMappingType.java index 301e87d..85fceb1 100644 --- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/type/EndpointMappingType.java +++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/type/EndpointMappingType.java @@ -26,6 +26,7 @@ public enum EndpointMappingType { SOAP_ACTION("soapaction:"), XPATHRESULT("xpathresult:"), URI("uri:"), + URI_PATH("uripath:"), BEANNAME("beanname:"); private String prefix; http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest.java b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest.java index a76f200..b54c342 100644 --- a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest.java +++ b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest.java @@ -16,13 +16,6 @@ */ package org.apache.camel.component.spring.ws; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URI; - -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - import org.apache.camel.component.spring.ws.utils.TestUtil; import org.apache.camel.test.spring.CamelSpringTestSupport; import org.junit.Before; @@ -34,6 +27,13 @@ import org.springframework.ws.soap.addressing.client.ActionCallback; import org.springframework.ws.soap.addressing.version.Addressing10; import org.springframework.ws.soap.client.core.SoapActionCallback; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URI; + public class ConsumerEndpointMappingResponseHandlingRouteTest extends CamelSpringTestSupport { private final String xmlRequestForGoogleStockQuote = "<GetQuote xmlns=\"http://www.webserviceX.NET/\"><symbol>GOOG</symbol></GetQuote>"; @@ -62,20 +62,48 @@ public class ConsumerEndpointMappingResponseHandlingRouteTest extends CamelSprin @Test public void testSoapAction() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); - webServiceTemplate.sendSourceAndReceiveToResult(source, new SoapActionCallback("http://www.webserviceX.NET/GetQuote"), result); + webServiceTemplate.sendSourceAndReceiveToResult(getDefaultRequestSource(), new SoapActionCallback("http://www.webserviceX.NET/GetQuote"), result); assertNotNull(result); TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); } @Test public void testUri() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); - webServiceTemplate.sendSourceAndReceiveToResult("http://localhost/stockquote2", source, result); + webServiceTemplate.sendSourceAndReceiveToResult("http://localhost/stockquote2", getDefaultRequestSource(), result); + assertNotNull(result); + TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); + } + + @Test + public void testUriPath() throws Exception { + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + webServiceTemplate.sendSourceAndReceiveToResult("http://localhost/stockquote3/service", getDefaultRequestSource(), result); + assertNotNull(result); + TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); + + sw = new StringWriter(); + result = new StreamResult(sw); + webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/stockquote3/service", getDefaultRequestSource(), result); + assertNotNull(result); + TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); + } + + @Test + public void testUriPathWildcard() throws Exception { + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + webServiceTemplate.sendSourceAndReceiveToResult("http://localhost/stockquote4/service/test", getDefaultRequestSource(), result); + assertNotNull(result); + TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); + + sw = new StringWriter(); + result = new StreamResult(sw); + webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/stockquote4/services/test", getDefaultRequestSource(), result); assertNotNull(result); TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); } @@ -92,20 +120,18 @@ public class ConsumerEndpointMappingResponseHandlingRouteTest extends CamelSprin @Test public void testAction() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); - webServiceTemplate.sendSourceAndReceiveToResult(source, new ActionCallback("http://www.webserviceX.NET/GetQuote"), result); + webServiceTemplate.sendSourceAndReceiveToResult(getDefaultRequestSource(), new ActionCallback("http://www.webserviceX.NET/GetQuote"), result); assertNotNull(result); TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); } @Test public void testTo() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); - webServiceTemplate.sendSourceAndReceiveToResult(source, new ActionCallback(new URI("http://action-does-not-matter-here"), new Addressing10(), new URI("http://url.to")), + webServiceTemplate.sendSourceAndReceiveToResult(getDefaultRequestSource(), new ActionCallback(new URI("http://action-does-not-matter-here"), new Addressing10(), new URI("http://url.to")), result); assertNotNull(result); TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString()); @@ -115,4 +141,8 @@ public class ConsumerEndpointMappingResponseHandlingRouteTest extends CamelSprin protected AbstractXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext("org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml"); } + + private Source getDefaultRequestSource() { + return new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest.java b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest.java index 89b80a7..e869292 100644 --- a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest.java +++ b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest.java @@ -16,12 +16,6 @@ */ package org.apache.camel.component.spring.ws; -import java.io.IOException; -import java.io.StringReader; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.stream.StreamSource; - import org.apache.camel.EndpointInject; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.spring.CamelSpringTestSupport; @@ -34,6 +28,12 @@ import org.springframework.ws.client.core.SourceExtractor; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.soap.client.core.SoapActionCallback; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.stream.StreamSource; +import java.io.IOException; +import java.io.StringReader; + public class ConsumerEndpointMappingRouteTest extends CamelSpringTestSupport { private static final SourceExtractor<Object> NOOP_SOURCE_EXTRACTOR = new SourceExtractor<Object>() { @@ -55,6 +55,9 @@ public class ConsumerEndpointMappingRouteTest extends CamelSpringTestSupport { @EndpointInject(uri = "mock:testUri") private MockEndpoint resultEndpointUri; + @EndpointInject(uri = "mock:testUriPath") + private MockEndpoint resultEndpointUriPath; + @EndpointInject(uri = "mock:testXPath") private MockEndpoint resultEndpointXPath; @@ -76,16 +79,14 @@ public class ConsumerEndpointMappingRouteTest extends CamelSpringTestSupport { @Test public void testSoapAction() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); - webServiceTemplate.sendSourceAndReceive(source, new SoapActionCallback("http://www.stockquotes.edu/GetQuote"), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive(getDefaultXmlRequestSource(), new SoapActionCallback("http://www.stockquotes.edu/GetQuote"), NOOP_SOURCE_EXTRACTOR); resultEndpointSoapAction.expectedMinimumMessageCount(1); resultEndpointSoapAction.assertIsSatisfied(); } @Test(expected = WebServiceIOException.class) public void testWrongSoapAction() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); - webServiceTemplate.sendSourceAndReceive(source, new SoapActionCallback("http://this-is-a-wrong-soap-action"), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive(getDefaultXmlRequestSource(), new SoapActionCallback("http://this-is-a-wrong-soap-action"), NOOP_SOURCE_EXTRACTOR); resultEndpointSoapAction.assertIsNotSatisfied(); } @@ -99,16 +100,34 @@ public class ConsumerEndpointMappingRouteTest extends CamelSpringTestSupport { @Test public void testUri() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); - webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote2", source, NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote2", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); resultEndpointUri.expectedMinimumMessageCount(1); resultEndpointUri.assertIsSatisfied(); } + @Test + public void testUriPath() throws Exception { + webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote3/service", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost:8080/stockquote3/service", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + resultEndpointUriPath.expectedMessageCount(2); + resultEndpointUriPath.assertIsSatisfied(); + } + + @Test + public void testUriPathWildcard() throws Exception { + webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote4/service", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost:8080/stockquote4/service", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote4/service/", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost:8080/stockquote4/service/", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost/stockquote4/service/test", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://0.0.0.0:11234/stockquote4/service/test", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); + resultEndpointUriPath.expectedMessageCount(6); + resultEndpointUriPath.assertIsSatisfied(); + } + @Test(expected = WebServiceIOException.class) public void testWrongUri() throws Exception { - StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); - webServiceTemplate.sendSourceAndReceive("http://localhost/wrong", source, NOOP_SOURCE_EXTRACTOR); + webServiceTemplate.sendSourceAndReceive("http://localhost/wrong", getDefaultXmlRequestSource(), NOOP_SOURCE_EXTRACTOR); resultEndpointUri.assertIsNotSatisfied(); } @@ -117,4 +136,8 @@ public class ConsumerEndpointMappingRouteTest extends CamelSpringTestSupport { return new ClassPathXmlApplicationContext( new String[]{"org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml"}); } + + private Source getDefaultXmlRequestSource() { + return new StreamSource(new StringReader(xmlRequestForGoogleStockQuoteNoNamespace)); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml index 2d36659..291685d 100644 --- a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml +++ b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingResponseHandlingRouteTest-context.xml @@ -39,6 +39,14 @@ <to uri="responseProcessor"/> </route> <route> + <from uri="spring-ws:uripath:/stockquote3/service?endpointMapping=#endpointMapping"/> + <to uri="responseProcessor"/> + </route> + <route> + <from uri="spring-ws:uripath:/stockquote4/service*?endpointMapping=#endpointMapping"/> + <to uri="responseProcessor"/> + </route> + <route> <from uri="spring-ws:xpathresult:GRABME?expression=//GetQuote&endpointMapping=#endpointMapping"/> <to uri="responseProcessor"/> </route> http://git-wip-us.apache.org/repos/asf/camel/blob/321b0dc1/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml index 9da327d..4abc198 100644 --- a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml +++ b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerEndpointMappingRouteTest-context.xml @@ -42,6 +42,14 @@ <to uri="mock:testUri"/> </route> <route> + <from uri="spring-ws:uripath:/stockquote3/service?endpointMapping=#endpointMapping"/> + <to uri="mock:testUriPath"/> + </route> + <route> + <from uri="spring-ws:uripath:/stockquote4/service*?endpointMapping=#endpointMapping"/> + <to uri="mock:testUriPath"/> + </route> + <route> <from uri="spring-ws:xpathresult:GRABME?expression=//GetQuote&endpointMapping=#endpointMapping"/> <to uri="mock:testXPath"/> </route>