You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/06 14:02:23 UTC
[camel] 01/02: CAMEL-14668: camel-core - Optimize getEndpoint on
camel context
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit b7f447e3fc524bd3cec74e2cf08447324e6797aa
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 6 13:46:11 2020 +0100
CAMEL-14668: camel-core - Optimize getEndpoint on camel context
---
.../camel/spring/bind/ProcessorAsEndpointTest.java | 4 +-
.../SpringCamelContextStartingFailedEventTest.java | 4 +-
.../aop/SpringAopClassLevelCamelBeanTest.xml | 2 +-
.../apache/camel/spring/bind/beanAsEndpoint.xml | 2 +-
.../camel/impl/engine/AbstractCamelContext.java | 157 ++++++++-------------
.../impl/RouteWithMistypedComponentNameTest.java | 9 +-
.../impl/engine/CamelPostProcessorHelperTest.java | 5 +-
.../camel/impl/engine/DefaultCamelContextTest.java | 12 +-
.../camel/issues/SetHeaderInDoCatchIssueTest.java | 4 +-
.../RecipientListIgnoreInvalidEndpointsTest.java | 4 +-
.../interceptor/AdviceWithReplaceFromTest.java | 4 +-
.../RoutingSlipIgnoreInvalidEndpointsTest.java | 4 +-
.../org/apache/camel/support/ExchangeHelper.java | 10 +-
.../java/org/apache/camel/util/StringHelper.java | 11 +-
14 files changed, 86 insertions(+), 146 deletions(-)
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
index 6bdf3d6..cd337e3 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
@@ -33,7 +33,7 @@ public class ProcessorAsEndpointTest extends SpringTestSupport {
public void testSendingToProcessorEndpoint() throws Exception {
ProcessorStub processor = getMandatoryBean(ProcessorStub.class, "myProcessor");
- template.sendBody("myProcessor", body);
+ template.sendBody("bean:myProcessor", body);
List<Exchange> list = processor.getExchanges();
assertEquals("Received exchange list: " + list, 1, list.size());
@@ -44,8 +44,6 @@ public class ProcessorAsEndpointTest extends SpringTestSupport {
@Test
public void testSendingToNonExistentEndpoint() throws Exception {
String uri = "unknownEndpoint";
- Endpoint endpoint = context.getEndpoint(uri);
- assertNull("Should not have found an endpoint! Was: " + endpoint, endpoint);
try {
template.sendBody(uri, body);
fail("We should have failed as this is a bad endpoint URI");
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringCamelContextStartingFailedEventTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringCamelContextStartingFailedEventTest.java
index 30a3f72..0f75da5 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringCamelContextStartingFailedEventTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringCamelContextStartingFailedEventTest.java
@@ -17,7 +17,7 @@
package org.apache.camel.spring.management;
import org.apache.camel.FailedToCreateRouteException;
-import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.spring.SpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -37,7 +37,7 @@ public class SpringCamelContextStartingFailedEventTest extends SpringTestSupport
fail("Should thrown an exception");
} catch (Exception e) {
FailedToCreateRouteException ftcre = assertIsInstanceOf(FailedToCreateRouteException.class, e);
- assertIsInstanceOf(ResolveEndpointFailedException.class, ftcre.getCause());
+ assertIsInstanceOf(NoSuchEndpointException.class, ftcre.getCause());
// expected
}
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/aop/SpringAopClassLevelCamelBeanTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/aop/SpringAopClassLevelCamelBeanTest.xml
index d29aaf7..5bd31b2 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/aop/SpringAopClassLevelCamelBeanTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/aop/SpringAopClassLevelCamelBeanTest.xml
@@ -48,7 +48,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
- <to uri="myBean"/>
+ <to uri="bean:myBean"/>
<to uri="mock:result"/>
</route>
</camelContext>
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml
index a12c44d..fff1c05 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/bind/beanAsEndpoint.xml
@@ -28,7 +28,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
- <to uri="myBean"/>
+ <to uri="bean:myBean"/>
<to uri="mock:results"/>
</route>
</camelContext>
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index ed9bba3..459b6a9 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -813,7 +813,7 @@ public abstract class AbstractCamelContext extends ServiceSupport
LOG.trace("Getting endpoint with raw uri: {}, normalized uri: {}", rawUri, uri);
- String scheme = null;
+ String scheme;
Endpoint answer = null;
if (!prototype) {
// use optimized method to get the endpoint uri
@@ -823,27 +823,32 @@ public abstract class AbstractCamelContext extends ServiceSupport
}
if (answer == null) {
try {
- // Use the URI prefix to find the component.
- String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
- if (splitURI[1] != null) {
- scheme = splitURI[0];
- LOG.trace("Endpoint uri: {} is from component with name: {}", uri, scheme);
- Component component = getComponent(scheme);
-
- // Ask the component to resolve the endpoint.
- if (component != null) {
- LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
-
- // Have the component create the endpoint if it can.
- if (component.useRawUri()) {
- answer = component.createEndpoint(rawUri);
- } else {
- answer = component.createEndpoint(uri);
- }
+ scheme = StringHelper.before(uri, ":");
+ if (scheme == null) {
+ // it may refer to a logical endpoint
+ answer = getRegistry().lookupByNameAndType(uri, Endpoint.class);
+ if (answer != null) {
+ return answer;
+ } else {
+ throw new NoSuchEndpointException(uri);
+ }
+ }
+ LOG.trace("Endpoint uri: {} is from component with name: {}", uri, scheme);
+ Component component = getComponent(scheme);
- if (answer != null && LOG.isDebugEnabled()) {
- LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
- }
+ // Ask the component to resolve the endpoint.
+ if (component != null) {
+ LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
+
+ // Have the component create the endpoint if it can.
+ if (component.useRawUri()) {
+ answer = component.createEndpoint(rawUri);
+ } else {
+ answer = component.createEndpoint(uri);
+ }
+
+ if (answer != null && LOG.isDebugEnabled()) {
+ LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
}
}
@@ -853,34 +858,6 @@ public abstract class AbstractCamelContext extends ServiceSupport
LOG.trace("No component to create endpoint from uri: {} fallback lookup in registry -> {}", uri, answer);
}
- if (answer == null && splitURI[1] == null) {
- // the uri has no context-path which is rare and it was not
- // referring to an endpoint in the registry
- // so try to see if it can be created by a component
-
- int pos = uri.indexOf('?');
- String componentName = pos > 0 ? uri.substring(0, pos) : uri;
-
- Component component = getComponent(componentName);
-
- // Ask the component to resolve the endpoint.
- if (component != null) {
- LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
-
- // Have the component create the endpoint if it can.
- if (component.useRawUri()) {
- answer = component.createEndpoint(rawUri);
- } else {
- answer = component.createEndpoint(uri);
- }
-
- if (answer != null && LOG.isDebugEnabled()) {
- LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
- }
- }
-
- }
-
if (answer != null) {
if (!prototype) {
addService(answer);
@@ -895,14 +872,17 @@ public abstract class AbstractCamelContext extends ServiceSupport
}
}
}
+ } catch (NoSuchEndpointException e) {
+ // throw as-is
+ throw e;
} catch (Exception e) {
throw new ResolveEndpointFailedException(uri, e);
}
}
// unknown scheme
- if (answer == null && scheme != null) {
- throw new ResolveEndpointFailedException(uri, "No component found with scheme: " + scheme);
+ if (answer == null) {
+ throw new NoSuchEndpointException(uri);
}
return answer;
@@ -940,27 +920,32 @@ public abstract class AbstractCamelContext extends ServiceSupport
answer = endpoints.get(key);
if (answer == null) {
try {
- // Use the URI prefix to find the component.
- String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
- if (splitURI[1] != null) {
- scheme = splitURI[0];
- LOG.trace("Endpoint uri: {} is from component with name: {}", uri, scheme);
- Component component = getComponent(scheme);
-
- // Ask the component to resolve the endpoint.
- if (component != null) {
- LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
-
- // Have the component create the endpoint if it can.
- if (component.useRawUri()) {
- answer = component.createEndpoint(rawUri, parameters);
- } else {
- answer = component.createEndpoint(uri, parameters);
- }
+ scheme = StringHelper.before(uri, ":");
+ if (scheme == null) {
+ // it may refer to a logical endpoint
+ answer = getRegistry().lookupByNameAndType(uri, Endpoint.class);
+ if (answer != null) {
+ return answer;
+ } else {
+ throw new NoSuchEndpointException(uri);
+ }
+ }
+ LOG.trace("Endpoint uri: {} is from component with name: {}", uri, scheme);
+ Component component = getComponent(scheme);
- if (answer != null && LOG.isDebugEnabled()) {
- LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
- }
+ // Ask the component to resolve the endpoint.
+ if (component != null) {
+ LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
+
+ // Have the component create the endpoint if it can.
+ if (component.useRawUri()) {
+ answer = component.createEndpoint(rawUri, parameters);
+ } else {
+ answer = component.createEndpoint(uri, parameters);
+ }
+
+ if (answer != null && LOG.isDebugEnabled()) {
+ LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
}
}
@@ -970,34 +955,6 @@ public abstract class AbstractCamelContext extends ServiceSupport
LOG.trace("No component to create endpoint from uri: {} fallback lookup in registry -> {}", uri, answer);
}
- if (answer == null && splitURI[1] == null) {
- // the uri has no context-path which is rare and it was not
- // referring to an endpoint in the registry
- // so try to see if it can be created by a component
-
- int pos = uri.indexOf('?');
- String componentName = pos > 0 ? uri.substring(0, pos) : uri;
-
- Component component = getComponent(componentName);
-
- // Ask the component to resolve the endpoint.
- if (component != null) {
- LOG.trace("Creating endpoint from uri: {} using component: {}", uri, component);
-
- // Have the component create the endpoint if it can.
- if (component.useRawUri()) {
- answer = component.createEndpoint(rawUri, parameters);
- } else {
- answer = component.createEndpoint(uri, parameters);
- }
-
- if (answer != null && LOG.isDebugEnabled()) {
- LOG.debug("{} converted to endpoint: {} by component: {}", URISupport.sanitizeUri(uri), answer, component);
- }
- }
-
- }
-
if (answer != null) {
addService(answer);
answer = addEndpointToRegistry(uri, answer);
@@ -1008,7 +965,7 @@ public abstract class AbstractCamelContext extends ServiceSupport
}
// unknown scheme
- if (answer == null && scheme != null) {
+ if (answer == null) {
throw new ResolveEndpointFailedException(uri, "No component found with scheme: " + scheme);
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/RouteWithMistypedComponentNameTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RouteWithMistypedComponentNameTest.java
index 022b106..5ee0ddb 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/RouteWithMistypedComponentNameTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/RouteWithMistypedComponentNameTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.impl;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.TestSupport;
import org.apache.camel.builder.RouteBuilder;
@@ -41,8 +42,8 @@ public class RouteWithMistypedComponentNameTest extends TestSupport {
endpoint("mistyped:hello");
}
});
- fail("Should have thrown a ResolveEndpointFailedException");
- } catch (ResolveEndpointFailedException e) {
+ fail("Should have thrown a NoSuchEndpointException");
+ } catch (NoSuchEndpointException e) {
// expected
}
}
@@ -60,8 +61,8 @@ public class RouteWithMistypedComponentNameTest extends TestSupport {
endpoint("mistyped:hello", Endpoint.class);
}
});
- fail("Should have thrown a ResolveEndpointFailedException");
- } catch (ResolveEndpointFailedException e) {
+ fail("Should have thrown a NoSuchEndpointException");
+ } catch (NoSuchEndpointException e) {
// expected
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java
index bda5027..4ee2a62 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java
@@ -30,6 +30,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.NoSuchBeanException;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Produce;
import org.apache.camel.Producer;
@@ -343,8 +344,8 @@ public class CamelPostProcessorHelperTest extends ContextTestSupport {
try {
helper.getInjectionValue(type, endpointInject.value(), endpointInject.property(), propertyName, bean, "foo");
fail("Should throw exception");
- } catch (ResolveEndpointFailedException e) {
- assertEquals("Failed to resolve endpoint: xxx://foo due to: No component found with scheme: xxx", e.getMessage());
+ } catch (NoSuchEndpointException e) {
+ // expected
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultCamelContextTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultCamelContextTest.java
index 01a29db..076310a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultCamelContextTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultCamelContextTest.java
@@ -127,14 +127,6 @@ public class DefaultCamelContextTest extends TestSupport {
}
@Test
- public void testGetEndpointNoScheme() throws Exception {
- DefaultCamelContext ctx = new DefaultCamelContext();
- ctx.disableJMX();
- Endpoint endpoint = ctx.getEndpoint("log");
- assertNotNull(endpoint);
- }
-
- @Test
public void testGetEndPointByTypeUnknown() {
DefaultCamelContext camelContext = new DefaultCamelContext();
try {
@@ -181,8 +173,8 @@ public class DefaultCamelContextTest extends TestSupport {
try {
ctx.getEndpoint("xxx:foo");
fail("Should have thrown a ResolveEndpointFailedException");
- } catch (ResolveEndpointFailedException e) {
- assertTrue(e.getMessage().contains("No component found with scheme: xxx"));
+ } catch (NoSuchEndpointException e) {
+ assertTrue(e.getMessage().contains("No endpoint could be found for: xxx:"));
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/SetHeaderInDoCatchIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/SetHeaderInDoCatchIssueTest.java
index 3b39521..d55d0fb 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/SetHeaderInDoCatchIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/SetHeaderInDoCatchIssueTest.java
@@ -98,9 +98,9 @@ public class SetHeaderInDoCatchIssueTest extends ContextTestSupport {
public void configure() throws Exception {
context.setTracing(true);
- from("direct:start").doTry().to("A").setHeader("CamelJmsDestinationName", constant("queue:outQueue")).inOut("B").setHeader("Status", constant("CamsResponse"))
+ from("direct:start").doTry().to("bean:A").setHeader("CamelJmsDestinationName", constant("queue:outQueue")).inOut("bean:B").setHeader("Status", constant("CamsResponse"))
.doCatch(ExchangeTimedOutException.class).setHeader("Status", constant("TimeOut")).doCatch(Exception.class).setHeader("Status", constant("ExceptionGeneral"))
- .end().to("C").transform(body());
+ .end().to("bean:C").transform(body());
}
};
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/RecipientListIgnoreInvalidEndpointsTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/RecipientListIgnoreInvalidEndpointsTest.java
index 73cdbe2..2efaedc 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/RecipientListIgnoreInvalidEndpointsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/RecipientListIgnoreInvalidEndpointsTest.java
@@ -17,7 +17,7 @@
package org.apache.camel.processor;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
@@ -49,7 +49,7 @@ public class RecipientListIgnoreInvalidEndpointsTest extends ContextTestSupport
template.requestBody("direct:startB", "Hello World", String.class);
fail("Expect the exception here.");
} catch (Exception ex) {
- assertTrue("Get a wrong cause of the exception", ex.getCause() instanceof ResolveEndpointFailedException);
+ assertTrue("Get a wrong cause of the exception", ex.getCause() instanceof NoSuchEndpointException);
}
assertMockEndpointsSatisfied();
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java
index 9e44e0c..f707800 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java
@@ -19,7 +19,7 @@ package org.apache.camel.processor.interceptor;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.FailedToCreateRouteException;
-import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.reifier.RouteReifier;
@@ -79,7 +79,7 @@ public class AdviceWithReplaceFromTest extends ContextTestSupport {
});
fail("Should have thrown exception");
} catch (FailedToCreateRouteException e) {
- assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ assertIsInstanceOf(NoSuchEndpointException.class, e.getCause());
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
index f41f7ba..00866b3 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
@@ -17,7 +17,7 @@
package org.apache.camel.processor.routingslip;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
@@ -46,7 +46,7 @@ public class RoutingSlipIgnoreInvalidEndpointsTest extends ContextTestSupport {
template.sendBodyAndHeader("direct:b", "Hello", "myHeader", "direct:start,fail:endpoint,mock:result");
fail("Expect the exception here.");
} catch (Exception ex) {
- assertTrue("Get a wrong cause of the exception", ex.getCause() instanceof ResolveEndpointFailedException);
+ assertTrue("Get a wrong cause of the exception", ex.getCause() instanceof NoSuchEndpointException);
}
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index 80a6f08..40a7ea4 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -892,15 +892,7 @@ public final class ExchangeHelper {
* @return the component scheme (name), or <tt>null</tt> if not possible to resolve
*/
public static String resolveScheme(String uri) {
- String scheme = null;
- if (uri != null) {
- // Use the URI prefix to find the component.
- String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
- if (splitURI[1] != null) {
- scheme = splitURI[0];
- }
- }
- return scheme;
+ return StringHelper.before(uri, ":");
}
@SuppressWarnings("unchecked")
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 7bdc36b..fd6fe35 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -466,10 +466,11 @@ public final class StringHelper {
* @return the text after the token, or <tt>null</tt> if text does not contain the token
*/
public static String after(String text, String after) {
- if (!text.contains(after)) {
+ int pos = text.indexOf(after);
+ if (pos == -1) {
return null;
}
- return text.substring(text.indexOf(after) + after.length());
+ return text.substring(pos + after.length());
}
/**
@@ -498,10 +499,8 @@ public final class StringHelper {
* contain the token
*/
public static String before(String text, String before) {
- if (!text.contains(before)) {
- return null;
- }
- return text.substring(0, text.indexOf(before));
+ int pos = text.indexOf(before);
+ return pos == -1 ? null : text.substring(0, pos);
}
/**