Search in sources :

Example 51 with Endpoint

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

the class RouteRefPropertyPlaceholderMultipleCamelContextRefsTest method testSpringTwoCamelContextDirectEndpoint.

public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:end-1", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:end-2", MockEndpoint.class);
    mock2.expectedBodiesReceived("Bye World");
    camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
    camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
    mock1.assertIsSatisfied();
    mock2.assertIsSatisfied();
    ac.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 52 with Endpoint

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

the class EndpointReferenceTest method testEndpointConfiguration.

public void testEndpointConfiguration() throws Exception {
    Endpoint endpoint = getMandatoryBean(Endpoint.class, "endpoint1");
    assertEquals("endpoint URI", "direct://start", endpoint.getEndpointUri());
    DummyBean dummyBean = getMandatoryBean(DummyBean.class, "mybean");
    assertNotNull("The bean should have an endpoint injected", dummyBean.getEndpoint());
    assertEquals("endpoint URI", "direct://start", dummyBean.getEndpoint().getEndpointUri());
    log.debug("Found dummy bean: " + dummyBean);
    MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
    resultEndpoint.expectedBodiesReceived(body);
    // now lets send a message
    template.sendBody("direct:start", body);
    resultEndpoint.assertIsSatisfied();
}
Also used : Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DummyBean(org.apache.camel.spring.example.DummyBean)

Example 53 with Endpoint

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

the class EndpointHelperTest method testLookupEndpointRegistryId.

public void testLookupEndpointRegistryId() throws Exception {
    Endpoint foo = context.getEndpoint("ref:foo");
    Endpoint bar = context.getEndpoint("ref:coolbar");
    assertEquals("foo", EndpointHelper.lookupEndpointRegistryId(foo));
    assertEquals("coolbar", EndpointHelper.lookupEndpointRegistryId(bar));
    assertEquals(null, EndpointHelper.lookupEndpointRegistryId(context.getEndpoint("mock:cheese")));
}
Also used : Endpoint(org.apache.camel.Endpoint)

Example 54 with Endpoint

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

the class UndertowComponent method doCreateConsumer.

Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {
    String path = basePath;
    if (uriTemplate != null) {
        // make sure to avoid double slashes
        if (uriTemplate.startsWith("/")) {
            path = path + uriTemplate;
        } else {
            path = path + "/" + uriTemplate;
        }
    }
    path = FileUtil.stripLeadingSeparator(path);
    String scheme = "http";
    String host = "";
    int port = 0;
    RestConfiguration config = configuration;
    if (config == null) {
        config = camelContext.getRestConfiguration("undertow", true);
    }
    if (config.getScheme() != null) {
        scheme = config.getScheme();
    }
    if (config.getHost() != null) {
        host = config.getHost();
    }
    int num = config.getPort();
    if (num > 0) {
        port = num;
    }
    // prefix path with context-path if configured in rest-dsl configuration
    String contextPath = config.getContextPath();
    if (ObjectHelper.isNotEmpty(contextPath)) {
        contextPath = FileUtil.stripTrailingSeparator(contextPath);
        contextPath = FileUtil.stripLeadingSeparator(contextPath);
        if (ObjectHelper.isNotEmpty(contextPath)) {
            path = contextPath + "/" + path;
        }
    }
    // if no explicit hostname set then resolve the hostname
    if (ObjectHelper.isEmpty(host)) {
        if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
            host = "0.0.0.0";
        } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
            host = HostUtils.getLocalHostName();
        } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
            host = HostUtils.getLocalIp();
        }
    }
    Map<String, Object> map = new HashMap<String, Object>();
    // build query string, and append any endpoint configuration properties
    if (config.getComponent() == null || config.getComponent().equals("undertow")) {
        // setup endpoint options
        if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
            map.putAll(config.getEndpointProperties());
        }
    }
    boolean cors = config.isEnableCORS();
    if (cors) {
        // allow HTTP Options as we want to handle CORS in rest-dsl
        map.put("optionsEnabled", "true");
    }
    String query = URISupport.createQueryString(map);
    String url;
    if (api) {
        url = "undertow:%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
    } else {
        url = "undertow:%s://%s:%s/%s?httpMethodRestrict=%s";
    }
    // must use upper case for restrict
    String restrict = verb.toUpperCase(Locale.US);
    if (cors) {
        restrict += ",OPTIONS";
    }
    // get the endpoint
    url = String.format(url, scheme, host, port, path, restrict);
    if (!query.isEmpty()) {
        url = url + "&" + query;
    }
    UndertowEndpoint endpoint = camelContext.getEndpoint(url, UndertowEndpoint.class);
    setProperties(camelContext, endpoint, parameters);
    if (!map.containsKey("undertowHttpBinding")) {
        // use the rest binding, if not using a custom http binding
        endpoint.setUndertowHttpBinding(new RestUndertowHttpBinding());
    }
    // configure consumer properties
    Consumer consumer = endpoint.createConsumer(processor);
    if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
        setProperties(camelContext, consumer, config.getConsumerProperties());
    }
    return consumer;
}
Also used : Consumer(org.apache.camel.Consumer) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RestConfiguration(org.apache.camel.spi.RestConfiguration) Endpoint(org.apache.camel.Endpoint)

Example 55 with Endpoint

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

the class UriConfigurationTest method testHttpProxySetting.

@Test
public void testHttpProxySetting() throws Exception {
    Endpoint endpoint = context.getEndpoint("twitter:search?httpProxyHost=example.com&httpProxyPort=3338&httpProxyUser=test&httpProxyPassword=pwd");
    assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
    TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;
    assertEquals("example.com", twitterEndpoint.getProperties().getHttpProxyHost());
    assertEquals(Integer.valueOf(3338), twitterEndpoint.getProperties().getHttpProxyPort());
    assertEquals("test", twitterEndpoint.getProperties().getHttpProxyUser());
    assertEquals("pwd", twitterEndpoint.getProperties().getHttpProxyPassword());
}
Also used : Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Aggregations

Endpoint (org.apache.camel.Endpoint)615 Test (org.junit.Test)238 Exchange (org.apache.camel.Exchange)209 Producer (org.apache.camel.Producer)139 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)94 CamelContext (org.apache.camel.CamelContext)50 Processor (org.apache.camel.Processor)46 Message (org.apache.camel.Message)44 HashMap (java.util.HashMap)32 Map (java.util.Map)31 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)30 RouteBuilder (org.apache.camel.builder.RouteBuilder)28 Consumer (org.apache.camel.Consumer)27 File (java.io.File)26 ProducerTemplate (org.apache.camel.ProducerTemplate)23 Route (org.apache.camel.Route)21 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 DefaultExchange (org.apache.camel.impl.DefaultExchange)16 ArrayList (java.util.ArrayList)15