Search in sources :

Example 6 with Exchange

use of org.apache.camel.Exchange 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 7 with Exchange

use of org.apache.camel.Exchange 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 8 with Exchange

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

the class LuceneIndexAndQueryProducerTest method testLuceneWildcardQueryProducer.

@Test
public void testLuceneWildcardQueryProducer() throws Exception {
    MockEndpoint mockSearchEndpoint = getMockEndpoint("mock:searchResult");
    context.stop();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").setHeader("QUERY", constant("Grouc?? Marx")).to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").to("direct:next");
            from("direct:next").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    Hits hits = exchange.getIn().getBody(Hits.class);
                    printResults(hits);
                }

                private void printResults(Hits hits) {
                    LOG.debug("Number of hits: " + hits.getNumberOfHits());
                    for (int i = 0; i < hits.getNumberOfHits(); i++) {
                        LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
                        LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
                        LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
                    }
                }
            }).to("mock:searchResult");
        }
    });
    context.start();
    LOG.debug("------------Beginning  LuceneQueryProducer Wildcard Test---------------");
    sendQuery();
    mockSearchEndpoint.assertIsSatisfied();
    LOG.debug("------------Completed LuceneQueryProducer Wildcard Test---------------");
    context.stop();
}
Also used : Exchange(org.apache.camel.Exchange) Hits(org.apache.camel.processor.lucene.support.Hits) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 9 with Exchange

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

the class LdapRouteTest method testLdapRoutePreserveHeaderAndAttachments.

@Test
public void testLdapRoutePreserveHeaderAndAttachments() throws Exception {
    camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system"));
    camel.start();
    final DataHandler dataHandler = new DataHandler("test", "text");
    Exchange out = template.request("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("(!(ou=test1))");
            exchange.getIn().setHeader("ldapTest", "Camel");
            exchange.getIn().addAttachment("ldapAttachment", dataHandler);
        }
    });
    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));
    assertEquals("Camel", out.getOut().getHeader("ldapTest"));
    assertSame(dataHandler, out.getOut().getAttachment("ldapAttachment"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) SearchResult(javax.naming.directory.SearchResult) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Example 10 with Exchange

use of org.apache.camel.Exchange 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)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78