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 2017/02/07 13:05:27 UTC
[3/3] camel git commit: CAMEL-10797: Create endpoint from uri without
context-path
CAMEL-10797: Create endpoint from uri without context-path
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4bb7dcb6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4bb7dcb6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4bb7dcb6
Branch: refs/heads/master
Commit: 4bb7dcb615c5e3eaf252012eab6df85b0861d57e
Parents: 01204f8
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Feb 7 13:27:05 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Feb 7 13:58:58 2017 +0100
----------------------------------------------------------------------
.../apache/camel/impl/DefaultCamelContext.java | 27 ++++++++++++++++++++
.../org/apache/camel/impl/DefaultComponent.java | 9 ++++++-
.../camel/impl/DefaultCamelContextTest.java | 11 ++++++--
3 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4bb7dcb6/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 67f77ea..707366d 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -628,6 +628,33 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
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: {}", new Object[]{URISupport.sanitizeUri(uri), answer, component});
+ }
+ }
+
+ }
+
if (answer != null) {
addService(answer);
answer = addEndpointToRegistry(uri, answer);
http://git-wip-us.apache.org/repos/asf/camel/blob/4bb7dcb6/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
index a2c18b9..7b5b31e 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
@@ -65,7 +65,14 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
// check URI string to the unsafe URI characters
String encodedUri = preProcessUri(uri);
URI u = new URI(encodedUri);
- String path = URISupport.extractRemainderPath(u, useRawUri());
+ String path;
+ if (u.getScheme() != null) {
+ // if there is a scheme then there is also a path
+ path = URISupport.extractRemainderPath(u, useRawUri());
+ } else {
+ // this uri has no context-path as the leading text is the component name (scheme)
+ path = null;
+ }
Map<String, Object> parameters;
if (useRawUri()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/4bb7dcb6/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
index b0fc1c4..4a8e84b 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
@@ -111,6 +111,13 @@ public class DefaultCamelContextTest extends TestSupport {
}
}
+ public void testGetEndpointNoScheme() throws Exception {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ ctx.disableJMX();
+ Endpoint endpoint = ctx.getEndpoint("log");
+ assertNotNull(endpoint);
+ }
+
public void testGetEndPointByTypeUnknown() {
DefaultCamelContext camelContext = new DefaultCamelContext();
try {
@@ -159,11 +166,11 @@ public class DefaultCamelContextTest extends TestSupport {
}
}
- public void testGetEndpointNoScheme() throws Exception {
+ public void testGetEndpointUnknownComponentNoScheme() throws Exception {
DefaultCamelContext ctx = new DefaultCamelContext();
ctx.disableJMX();
try {
- CamelContextHelper.getMandatoryEndpoint(ctx, "log.foo");
+ CamelContextHelper.getMandatoryEndpoint(ctx, "unknownname");
fail("Should have thrown a NoSuchEndpointException");
} catch (NoSuchEndpointException e) {
// expected