use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.
the class LogCustomFormatterTest method testCustomFormatterInRegistryUnknownOption.
@Test
public void testCustomFormatterInRegistryUnknownOption() throws Exception {
context.stop();
exchangeFormatter = new TestExchangeFormatter();
JndiRegistry registry = getRegistryAsJndi();
registry.bind("logFormatter", exchangeFormatter);
assertEquals("", exchangeFormatter.getPrefix());
context.start();
// unknown parameter
try {
String endpointUri2 = "log:" + LogCustomFormatterTest.class.getCanonicalName() + "?prefix=foo&bar=no";
template.requestBody(endpointUri2, "Hello World");
fail("Should have thrown exception");
} catch (Exception e) {
ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
assertTrue(cause.getMessage().endsWith("Unknown parameters=[{bar=no}]"));
}
}
use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.
the class DefaultCamelContext method getEndpoint.
public Endpoint getEndpoint(String uri) {
ObjectHelper.notEmpty(uri, "uri");
log.trace("Getting endpoint with uri: {}", uri);
// in case path has property placeholders then try to let property component resolve those
try {
uri = resolvePropertyPlaceholders(uri);
} catch (Exception e) {
throw new ResolveEndpointFailedException(uri, e);
}
final String rawUri = uri;
// normalize uri so we can do endpoint hits with minor mistakes and parameters is not in the same order
uri = normalizeEndpointUri(uri);
log.trace("Getting endpoint with raw uri: {}, normalized uri: {}", rawUri, uri);
Endpoint answer;
String scheme = null;
EndpointKey key = getEndpointKey(uri);
answer = endpoints.get(key);
if (answer == null) {
try {
// Use the URI prefix to find the component.
String[] splitURI = ObjectHelper.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);
}
if (answer != null && log.isDebugEnabled()) {
log.debug("{} converted to endpoint: {} by component: {}", new Object[] { URISupport.sanitizeUri(uri), answer, component });
}
}
}
if (answer == null) {
// no component then try in registry and elsewhere
answer = createEndpoint(uri);
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);
}
} 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);
}
return answer;
}
use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.
the class PropertiesComponentTest method testPropertiesComponentInvalidKey.
public void testPropertiesComponentInvalidKey() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("properties:{{foo.unknown}}");
}
});
try {
context.start();
fail("Should throw exception");
} catch (FailedToCreateRouteException e) {
ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
assertEquals("Property with key [foo.unknown] not found in properties from text: {{foo.unknown}}", iae.getMessage());
}
}
use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.
the class PropertiesComponentTest method testPropertiesComponentPropertyPrefixFallbackDefaultNotFound.
public void testPropertiesComponentPropertyPrefixFallbackDefaultNotFound() throws Exception {
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
pc.setPropertyPrefix("cool.");
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("properties:doesnotexist");
}
});
try {
context.start();
fail("Should throw exception");
} catch (FailedToCreateRouteException e) {
ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
assertEquals("Property with key [cool.doesnotexist] (and original key [doesnotexist]) not found in properties from text: {{doesnotexist}}", iae.getMessage());
}
}
use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.
the class MinaEncodingTest method testInvalidEncoding.
@Test
public void testInvalidEncoding() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&encoding=XXX&sync=false";
try {
context.addRoutes(new RouteBuilder() {
public void configure() {
from(uri).to("mock:result");
}
});
fail("Should have thrown a ResolveEndpointFailedException due invalid encoding parameter");
} catch (FailedToCreateRouteException e) {
ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
assertTrue(cause.getCause() instanceof IllegalArgumentException);
assertEquals("The encoding: XXX is not supported", cause.getCause().getMessage());
}
}
Aggregations