Search in sources :

Example 21 with ResolveEndpointFailedException

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}]"));
    }
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) Test(org.junit.Test)

Example 22 with ResolveEndpointFailedException

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;
}
Also used : ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) Endpoint(org.apache.camel.Endpoint) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Component(org.apache.camel.Component) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) Endpoint(org.apache.camel.Endpoint)

Example 23 with ResolveEndpointFailedException

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());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException)

Example 24 with ResolveEndpointFailedException

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());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException)

Example 25 with ResolveEndpointFailedException

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());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Aggregations

ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)25 RouteBuilder (org.apache.camel.builder.RouteBuilder)12 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)9 Endpoint (org.apache.camel.Endpoint)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 CamelContext (org.apache.camel.CamelContext)3 Component (org.apache.camel.Component)3 URI (java.net.URI)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 HttpBinding (org.apache.camel.http.common.HttpBinding)2 HttpRestHeaderFilterStrategy (org.apache.camel.http.common.HttpRestHeaderFilterStrategy)2 UrlRewrite (org.apache.camel.http.common.UrlRewrite)2 HeaderFilterStrategy (org.apache.camel.spi.HeaderFilterStrategy)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1