Search in sources :

Example 81 with Producer

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

the class DefaultProducerCacheTest method testCacheStopExpired.

public void testCacheStopExpired() throws Exception {
    ProducerCache cache = new ProducerCache(this, context, 5);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    for (int i = 0; i < 8; i++) {
        Endpoint e = new MyEndpoint(true, i);
        Producer p = cache.acquireProducer(e);
        cache.releaseProducer(e, p);
    }
    // the eviction is async so force cleanup
    cache.cleanUp();
    assertEquals("Size should be 5", 5, cache.size());
    // the eviction listener is async so sleep a bit
    Thread.sleep(1000);
    // should have stopped the 3 evicted
    assertEquals(3, stopCounter.get());
    cache.stop();
    // should have stopped all 8
    assertEquals(8, stopCounter.get());
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Endpoint(org.apache.camel.Endpoint)

Example 82 with Producer

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

the class CMISQueryProducerTest method getResultCountFromHeader.

@Test
public void getResultCountFromHeader() throws Exception {
    Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
    Producer producer = endpoint.createProducer();
    Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
    producer.process(exchange);
    @SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
    assertEquals(2, documents.size());
    assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Map(java.util.Map) Test(org.junit.Test)

Example 83 with Producer

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

the class CMISQueryProducerTest method limitNumberOfResultsWithReadSizeHeader.

@Test
public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
    Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
    Producer producer = endpoint.createProducer();
    Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
    exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
    producer.process(exchange);
    @SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
    assertEquals(1, documents.size());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Map(java.util.Map) Test(org.junit.Test)

Example 84 with Producer

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

the class CMISQueryProducerTest method retrieveAlsoDocumentContent.

@Test
public void retrieveAlsoDocumentContent() throws Exception {
    Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
    Producer producer = endpoint.createProducer();
    Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
    exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
    producer.process(exchange);
    @SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
    InputStream content = (InputStream) documents.get(0).get("CamelCMISContent");
    assertEquals("This is the first Camel test content.", readFromStream(content));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) InputStream(java.io.InputStream) Map(java.util.Map) Test(org.junit.Test)

Example 85 with Producer

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

the class MailAttachmentDuplicateNamesTest method testSendAndRecieveMailWithAttachmentsWithDuplicateNames.

@Test
public void testSendAndRecieveMailWithAttachmentsWithDuplicateNames() throws Exception {
    // clear mailbox
    Mailbox.clearAll();
    // START SNIPPET: e1
    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://james@mymailserver.com?password=secret");
    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);
    // END SNIPPET: e1
    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();
    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));
    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());
    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);
    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Message(org.apache.camel.Message) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Aggregations

Producer (org.apache.camel.Producer)198 Endpoint (org.apache.camel.Endpoint)140 Exchange (org.apache.camel.Exchange)138 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)69 Processor (org.apache.camel.Processor)34 RouteBuilder (org.apache.camel.builder.RouteBuilder)23 Message (org.apache.camel.Message)21 CountDownLatch (java.util.concurrent.CountDownLatch)16 File (java.io.File)12 CamelContext (org.apache.camel.CamelContext)12 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 DefaultExchange (org.apache.camel.impl.DefaultExchange)9 Mockito.anyLong (org.mockito.Mockito.anyLong)9 Consumer (org.apache.camel.Consumer)8 FileDataSource (javax.activation.FileDataSource)7 AsyncProcessor (org.apache.camel.AsyncProcessor)7 DataHandler (javax.activation.DataHandler)6 Field (java.lang.reflect.Field)5 ExchangePattern (org.apache.camel.ExchangePattern)5