CAMEL-9027: camel-sjms - Should allow destination name with colon in the name, such as when using jndi.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/54617495 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/54617495 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/54617495 Branch: refs/heads/master Commit: 54617495eea11af40dcbb244003d2c59efc360ce Parents: f187999 Author: Claus Ibsen <[email protected]> Authored: Wed Jul 29 10:34:11 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Wed Jul 29 10:34:11 2015 +0200 ---------------------------------------------------------------------- .../camel/component/sjms/SjmsComponent.java | 35 -------------------- .../camel/component/sjms/SjmsEndpoint.java | 2 +- .../sjms/jms/DestinationNameParser.java | 8 ++++- .../sjms/SjmsEndpointNameOverrideTest.java | 7 +--- .../camel/component/sjms/SjmsEndpointTest.java | 16 +++++---- 5 files changed, 18 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/54617495/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsComponent.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsComponent.java index 2503162..3433ec9 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsComponent.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsComponent.java @@ -18,7 +18,6 @@ package org.apache.camel.component.sjms; import java.util.Map; import java.util.concurrent.ExecutorService; - import javax.jms.ConnectionFactory; import org.apache.camel.CamelException; @@ -33,7 +32,6 @@ import org.apache.camel.component.sjms.taskmanager.TimedTaskManager; import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.HeaderFilterStrategyAware; -import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +58,6 @@ public class SjmsComponent extends UriEndpointComponent implements HeaderFilterS @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { validateMepAndReplyTo(parameters); - uri = normalizeUri(uri); SjmsEndpoint endpoint = new SjmsEndpoint(uri, this, remaining); setProperties(endpoint, parameters); if (endpoint.isTransacted()) { @@ -76,38 +73,6 @@ public class SjmsComponent extends UriEndpointComponent implements HeaderFilterS } /** - * Helper method used to detect the type of endpoint and add the "queue" - * protocol if it is a default endpoint URI. - * - * @param uri The value passed into our call to create an endpoint - * @return String - * @throws Exception - */ - private static String normalizeUri(String uri) throws Exception { - String tempUri = uri; - String endpointName = tempUri.substring(0, tempUri.indexOf(":")); - tempUri = tempUri.substring(endpointName.length()); - if (tempUri.startsWith("://")) { - tempUri = tempUri.substring(3); - } - String protocol = null; - if (tempUri.indexOf(":") > 0) { - protocol = tempUri.substring(0, tempUri.indexOf(":")); - } - if (ObjectHelper.isEmpty(protocol)) { - protocol = "queue"; - } else if (protocol != null && (protocol.equals("queue") || protocol.equals("topic"))) { - tempUri = tempUri.substring(protocol.length() + 1); - } else { - throw new Exception("Unsupported Protocol: " + protocol); - } - - String path = tempUri; - uri = endpointName + "://" + protocol + ":" + path; - return uri; - } - - /** * Helper method used to verify that when there is a namedReplyTo value we * are using the InOut MEP. If namedReplyTo is defined and the MEP is InOnly * the endpoint won't be expecting a reply so throw an error to alert the http://git-wip-us.apache.org/repos/asf/camel/blob/54617495/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java index 6ffa513..c7ed9ac 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java @@ -99,7 +99,7 @@ public class SjmsEndpoint extends DefaultEndpoint implements MultipleConsumersSu public SjmsEndpoint(String uri, Component component, String remaining) { super(uri, component); DestinationNameParser parser = new DestinationNameParser(); - topic = parser.isTopic(remaining); + this.topic = parser.isTopic(remaining); this.destinationName = parser.getShortName(remaining); } http://git-wip-us.apache.org/repos/asf/camel/blob/54617495/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/DestinationNameParser.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/DestinationNameParser.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/DestinationNameParser.java index ddc213d..41eab2d 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/DestinationNameParser.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/DestinationNameParser.java @@ -32,6 +32,12 @@ public class DestinationNameParser { if (destinationName == null) { throw new IllegalArgumentException("destinationName is null"); } - return destinationName.substring(destinationName.lastIndexOf(":") + 1); + if (destinationName.startsWith("queue:")) { + return destinationName.substring(6); + } else if (destinationName.startsWith("topic:")) { + return destinationName.substring(6); + } else { + return destinationName; + } } } http://git-wip-us.apache.org/repos/asf/camel/blob/54617495/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointNameOverrideTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointNameOverrideTest.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointNameOverrideTest.java index d0c777c..17d67cb 100644 --- a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointNameOverrideTest.java +++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointNameOverrideTest.java @@ -40,15 +40,10 @@ public class SjmsEndpointNameOverrideTest extends CamelTestSupport { assertNotNull(endpoint); assertTrue(endpoint instanceof SjmsEndpoint); SjmsEndpoint sjms = (SjmsEndpoint)endpoint; - assertEquals(sjms.getEndpointUri(), BEAN_NAME + "://queue:test"); + assertEquals(sjms.getEndpointUri(), BEAN_NAME + "://test"); assertEquals(sjms.createExchange().getPattern(), ExchangePattern.InOnly); } - @Test(expected = ResolveEndpointFailedException.class) - public void testUnsupportedProtocol() throws Exception { - context.getEndpoint("sjms:bad-queue:test"); - } - @Test public void testQueueEndpoint() throws Exception { Endpoint sjms = context.getEndpoint(BEAN_NAME + ":queue:test"); http://git-wip-us.apache.org/repos/asf/camel/blob/54617495/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointTest.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointTest.java index a406da3..3281c83 100644 --- a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointTest.java +++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/SjmsEndpointTest.java @@ -22,7 +22,6 @@ import org.apache.camel.Endpoint; import org.apache.camel.ExchangePattern; import org.apache.camel.ResolveEndpointFailedException; import org.apache.camel.test.junit4.CamelTestSupport; - import org.junit.Test; public class SjmsEndpointTest extends CamelTestSupport { @@ -38,15 +37,10 @@ public class SjmsEndpointTest extends CamelTestSupport { assertNotNull(endpoint); assertTrue(endpoint instanceof SjmsEndpoint); SjmsEndpoint sjms = (SjmsEndpoint)endpoint; - assertEquals(sjms.getEndpointUri(), "sjms://queue:test"); + assertEquals(sjms.getEndpointUri(), "sjms://test"); assertEquals(sjms.createExchange().getPattern(), ExchangePattern.InOnly); } - @Test(expected = ResolveEndpointFailedException.class) - public void testUnsupportedProtocol() throws Exception { - context.getEndpoint("sjms:bad-queue:test"); - } - @Test public void testQueueEndpoint() throws Exception { Endpoint sjms = context.getEndpoint("sjms:queue:test"); @@ -56,6 +50,14 @@ public class SjmsEndpointTest extends CamelTestSupport { } @Test + public void testJndiStyleEndpointName() throws Exception { + SjmsEndpoint sjms = context.getEndpoint("sjms:/jms/test/hov.t1.dev:topic", SjmsEndpoint.class); + assertNotNull(sjms); + assertFalse(sjms.isTopic()); + assertEquals("/jms/test/hov.t1.dev:topic", sjms.getDestinationName()); + } + + @Test public void testSetTransacted() throws Exception { Endpoint endpoint = context.getEndpoint("sjms:queue:test?transacted=true"); assertNotNull(endpoint);
