Search in sources :

Example 1 with Endpoint

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

the class LdapRouteTest method testLdapRouteWithPaging.

@Test
public void testLdapRouteWithPaging() throws Exception {
    camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system&pageSize=5"));
    camel.start();
    Endpoint endpoint = camel.getEndpoint("direct:start");
    Exchange exchange = endpoint.createExchange();
    // then we set the LDAP filter on the in body
    exchange.getIn().setBody("(objectClass=*)");
    // now we send the exchange to the endpoint, and receives the response from Camel
    Exchange out = template.send(endpoint, exchange);
    Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
    assertEquals(16, searchResults.size());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) SearchResult(javax.naming.directory.SearchResult) Test(org.junit.Test)

Example 2 with Endpoint

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

the class LdapRouteTest method testLdapRouteStandard.

@Test
public void testLdapRouteStandard() throws Exception {
    camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system"));
    camel.start();
    // START SNIPPET: invoke
    Endpoint endpoint = camel.getEndpoint("direct:start");
    Exchange exchange = endpoint.createExchange();
    // then we set the LDAP filter on the in body
    exchange.getIn().setBody("(!(ou=test1))");
    // now we send the exchange to the endpoint, and receives the response from Camel
    Exchange out = template.send(endpoint, exchange);
    Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
    assertFalse(contains("uid=test1,ou=test,ou=system", searchResults));
    assertTrue(contains("uid=test2,ou=test,ou=system", searchResults));
    assertTrue(contains("uid=testNoOU,ou=test,ou=system", searchResults));
    assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
// START SNIPPET: invoke
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) SearchResult(javax.naming.directory.SearchResult) Test(org.junit.Test)

Example 3 with Endpoint

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

the class LdapRouteTest method testLdapRouteReturnedAttributes.

@Test
public void testLdapRouteReturnedAttributes() throws Exception {
    // LDAP servers behave differently when it comes to what attributes are returned
    // by default (Apache Directory server returns all attributes by default)
    // Using the returnedAttributes parameter this behavior can be controlled
    camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system&returnedAttributes=uid,cn"));
    camel.start();
    Endpoint endpoint = camel.getEndpoint("direct:start");
    Exchange exchange = endpoint.createExchange();
    // then we set the LDAP filter on the in body
    exchange.getIn().setBody("(uid=tcruise)");
    // now we send the exchange to the endpoint, and receives the response from Camel
    Exchange out = template.send(endpoint, exchange);
    Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
    assertEquals(1, searchResults.size());
    assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
    Attributes theOneResultAtts = searchResults.iterator().next().getAttributes();
    assertEquals("tcruise", theOneResultAtts.get("uid").get());
    assertEquals("Tom Cruise", theOneResultAtts.get("cn").get());
    // make sure this att is NOT returned anymore 
    assertNull(theOneResultAtts.get("sn"));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) Test(org.junit.Test)

Example 4 with Endpoint

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

the class LumberjackComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // Extract host and port
    String host;
    int port;
    int separatorIndex = remaining.indexOf(':');
    if (separatorIndex >= 0) {
        host = remaining.substring(0, separatorIndex);
        port = Integer.parseInt(remaining.substring(separatorIndex + 1));
    } else {
        host = remaining;
        port = DEFAULT_PORT;
    }
    // Create the endpoint
    Endpoint answer = new LumberjackEndpoint(uri, this, host, port);
    setProperties(answer, parameters);
    return answer;
}
Also used : Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint)

Example 5 with Endpoint

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

the class InvalidConfigurationTest method testSMTPCanNotBeUsedForConsumingMails.

@Test
public void testSMTPCanNotBeUsedForConsumingMails() throws Exception {
    Endpoint endpoint = context.getEndpoint("smtp://localhost?username=james");
    PollingConsumer consumer = endpoint.createPollingConsumer();
    try {
        consumer.start();
        fail("Should have thrown NoSuchProviderException as stmp protocol cannot be used for consuming mails");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Aggregations

Endpoint (org.apache.camel.Endpoint)616 Test (org.junit.Test)239 Exchange (org.apache.camel.Exchange)210 Producer (org.apache.camel.Producer)139 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)95 CamelContext (org.apache.camel.CamelContext)50 Processor (org.apache.camel.Processor)46 Message (org.apache.camel.Message)44 HashMap (java.util.HashMap)33 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)24 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