Search in sources :

Example 1 with ResolveEndpointFailedException

use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.

the class JettyHttpEndpoint method createJettyHttpClient.

protected HttpClient createJettyHttpClient() throws Exception {
    // create a new client
    // thread pool min/max from endpoint take precedence over from component
    Integer min = httpClientMinThreads != null ? httpClientMinThreads : getComponent().getHttpClientMinThreads();
    Integer max = httpClientMaxThreads != null ? httpClientMaxThreads : getComponent().getHttpClientMaxThreads();
    HttpClient httpClient = getComponent().createHttpClient(this, min, max, sslContextParameters);
    // set optional http client parameters
    if (httpClientParameters != null) {
        // copy parameters as we need to re-use them again if creating a new producer later
        Map<String, Object> params = new HashMap<String, Object>(httpClientParameters);
        // Can not be set on httpClient for jetty 9
        params.remove("timeout");
        IntrospectionSupport.setProperties(httpClient, params);
        // validate we could set all parameters
        if (params.size() > 0) {
            throw new ResolveEndpointFailedException(getEndpointUri(), "There are " + params.size() + " parameters that couldn't be set on the endpoint." + " Check the uri if the parameters are spelt correctly and that they are properties of the endpoint." + " Unknown parameters=[" + params + "]");
        }
    }
    return httpClient;
}
Also used : ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) HashMap(java.util.HashMap) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 2 with ResolveEndpointFailedException

use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.

the class PropertiesComponentTest method testPropertiesComponentPropertySuffixFallbackFalse.

public void testPropertiesComponentPropertySuffixFallbackFalse() throws Exception {
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    pc.setPropertySuffix(".end");
    pc.setFallbackToUnaugmentedProperty(false);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("properties:cool.end");
        }
    });
    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.end.end] not found in properties from text: {{cool.end}}", 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 3 with ResolveEndpointFailedException

use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.

the class PropertiesComponentTest method testPropertiesComponentCircularReference.

public void testPropertiesComponentCircularReference() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("properties:cool.a");
        }
    });
    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("Circular reference detected with key [cool.a] from text: {{cool.a}}", 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 4 with ResolveEndpointFailedException

use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.

the class PropertiesComponentTest method testPropertiesComponentPropertyPrefixFallbackFalse.

public void testPropertiesComponentPropertyPrefixFallbackFalse() throws Exception {
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    pc.setPropertyPrefix("cool.");
    pc.setFallbackToUnaugmentedProperty(false);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("properties:cool.end");
            from("direct:foo").to("properties:mock:{{result}}");
        }
    });
    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.cool.end] not found in properties from text: {{cool.end}}", 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 5 with ResolveEndpointFailedException

use of org.apache.camel.ResolveEndpointFailedException in project camel by apache.

the class ComponentConfigurationTest method testCreateNewDefaultComponentEndpoint.

@Test
public void testCreateNewDefaultComponentEndpoint() throws Exception {
    Component component = context.getComponent("cheese");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the base URI properties
    configuration.setBaseUri("something");
    // lets try set and get a valid parameter
    configuration.setParameter("foo", "xyz");
    configuration.setParameter("bar", 5);
    NonUriEndpoint endpoint = TestSupport.assertIsInstanceOf(NonUriEndpoint.class, configuration.createEndpoint());
    assertEquals("foo", "xyz", endpoint.getFoo());
    assertEquals("bar", 5, endpoint.getBar());
    LOG.info("Created endpoint " + endpoint + " on URI " + endpoint.getEndpointUri());
    // lets try configure a parameter
    configuration.setEndpointParameter(endpoint, "bar", 6);
    assertEquals("bar", 6, endpoint.getBar());
    // lets try configure an invalid parameter
    try {
        configuration.setEndpointParameter(endpoint, "doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
    ComponentConfiguration badConfiguration = component.createComponentConfiguration();
    badConfiguration.setBaseUri(configuration.getBaseUri());
    badConfiguration.setParameters(configuration.getParameters());
    // lets try set an invalid parameter on a configuration
    // there is no way to validate on non UriEndpoint unless the endpoint
    // creates its own configuration object so this always works...
    badConfiguration.setParameter("doesNotExist", 1000);
    // however it fails if we now try create an
    try {
        badConfiguration.createEndpoint();
        fail("Should have got ResolveEndpointFailedException thrown!");
    } catch (ResolveEndpointFailedException e) {
        LOG.info("Got expected exception: " + e);
    }
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) 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