Search in sources :

Example 36 with Consumer

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

the class WebsocketEndpointConfigurationTest method testSetServletThreadPool.

@Test
public void testSetServletThreadPool() throws Exception {
    port = AvailablePortFinder.getNextAvailable(16332);
    String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000";
    WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
    WebsocketComponent component = websocketEndpoint.getComponent();
    QueuedThreadPool qtp = new QueuedThreadPool(20, 1);
    component.setThreadPool(qtp);
    Consumer consumer = websocketEndpoint.createConsumer(processor);
    component.connect((WebsocketProducerConsumer) consumer);
    assertNotNull(consumer);
    assertEquals(WebsocketConsumer.class, consumer.getClass());
    // just check the servlet initial parameters
    ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
    ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
    String buffersize = context.getInitParameter("bufferSize");
    assertEquals("Got a wrong buffersize", "25000", buffersize);
    String maxIdleTime = context.getInitParameter("maxIdleTime");
    assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
    WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
    int factoryBufferSize = factory.getPolicy().getInputBufferSize();
    assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
    long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
    assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
}
Also used : WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Consumer(org.apache.camel.Consumer) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ConnectorRef(org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Example 37 with Consumer

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

the class WebsocketEndpointConfigurationTest method testSetServletInitalparameters.

@Test
public void testSetServletInitalparameters() throws Exception {
    port = AvailablePortFinder.getNextAvailable(16330);
    String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000&maxTextMessageSize=500&maxBinaryMessageSize=550";
    WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
    WebsocketComponent component = websocketEndpoint.getComponent();
    component.setMinThreads(1);
    component.setMaxThreads(20);
    Consumer consumer = websocketEndpoint.createConsumer(processor);
    component.connect((WebsocketProducerConsumer) consumer);
    assertNotNull(consumer);
    assertEquals(WebsocketConsumer.class, consumer.getClass());
    // just check the servlet initial parameters
    ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
    ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
    String buffersize = context.getInitParameter("bufferSize");
    assertEquals("Got a wrong buffersize", "25000", buffersize);
    String maxIdleTime = context.getInitParameter("maxIdleTime");
    assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
    String maxTextMessageSize = context.getInitParameter("maxTextMessageSize");
    assertEquals("Got a wrong maxTextMessageSize", "500", maxTextMessageSize);
    String maxBinaryMessageSize = context.getInitParameter("maxBinaryMessageSize");
    assertEquals("Got a wrong maxBinaryMessageSize", "550", maxBinaryMessageSize);
    WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
    int factoryBufferSize = factory.getPolicy().getInputBufferSize();
    assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
    long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
    assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
    int factoryMaxTextMessageSize = factory.getPolicy().getMaxTextMessageSize();
    assertEquals("Got a wrong maxTextMessageSize", 500, factoryMaxTextMessageSize);
    int factoryMaxBinaryMessageSize = factory.getPolicy().getMaxBinaryMessageSize();
    assertEquals("Got a wrong maxBinaryMessageSize", 550, factoryMaxBinaryMessageSize);
}
Also used : WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Consumer(org.apache.camel.Consumer) ConnectorRef(org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Example 38 with Consumer

use of org.apache.camel.Consumer in project ddf by codice.

the class CatalogEndpoint method createConsumer.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor)
     */
public Consumer createConsumer(Processor processor) {
    LOGGER.debug("INSIDE createConsumer");
    // Camel Consumers map to <from> route nodes.
    Consumer consumer = null;
    // e.g., <from uri="catalog:inputtransformer?mimeType=text/xml&amp;id=xml" />
    if (contextPath.equals(INPUT_TRANSFORMER)) {
        consumer = new InputTransformerConsumer(this, processor);
    } else if (contextPath.equals(QUERYRESPONSE_TRANSFORMER)) {
        consumer = new QueryResponseTransformerConsumer(this, processor);
    } else {
        LOGGER.debug("Unable to create consumer for context path [{}]", contextPath);
        throw new IllegalArgumentException("Unable to create consumer for context path [" + contextPath + "]");
    }
    return consumer;
}
Also used : QueryResponseTransformerConsumer(ddf.camel.component.catalog.queryresponsetransformer.QueryResponseTransformerConsumer) Consumer(org.apache.camel.Consumer) InputTransformerConsumer(ddf.camel.component.catalog.inputtransformer.InputTransformerConsumer) QueryResponseTransformerConsumer(ddf.camel.component.catalog.queryresponsetransformer.QueryResponseTransformerConsumer) InputTransformerConsumer(ddf.camel.component.catalog.inputtransformer.InputTransformerConsumer)

Example 39 with Consumer

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

the class StreamFileTest method testFile.

@Test
public void testFile() throws Exception {
    context.start();
    try {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello");
        // can not use route builder as we need to have the file created in the setup before route builder starts
        Endpoint endpoint = context.getEndpoint("stream:file?fileName=target/stream/streamfile.txt&delay=100");
        Consumer consumer = endpoint.createConsumer(new Processor() {

            public void process(Exchange exchange) throws Exception {
                template.send("mock:result", exchange);
            }
        });
        consumer.start();
        assertMockEndpointsSatisfied();
        consumer.stop();
    } finally {
        fos.close();
    }
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Consumer(org.apache.camel.Consumer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 40 with Consumer

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

the class WebsocketEndpointConfigurationTest method testSetServletNoMinThreadsNoMaxThreadsNoThreadPool.

@Test
public void testSetServletNoMinThreadsNoMaxThreadsNoThreadPool() throws Exception {
    port = AvailablePortFinder.getNextAvailable(16331);
    String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000";
    WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
    WebsocketComponent component = websocketEndpoint.getComponent();
    Consumer consumer = websocketEndpoint.createConsumer(processor);
    component.connect((WebsocketProducerConsumer) consumer);
    assertNotNull(consumer);
    assertEquals(WebsocketConsumer.class, consumer.getClass());
    // just check the servlet initial parameters
    ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
    ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
    String buffersize = context.getInitParameter("bufferSize");
    assertEquals("Got a wrong buffersize", "25000", buffersize);
    String maxIdleTime = context.getInitParameter("maxIdleTime");
    assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
    WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
    int factoryBufferSize = factory.getPolicy().getInputBufferSize();
    assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
    long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
    assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
}
Also used : WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Consumer(org.apache.camel.Consumer) ConnectorRef(org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Aggregations

Consumer (org.apache.camel.Consumer)76 Endpoint (org.apache.camel.Endpoint)27 Processor (org.apache.camel.Processor)19 Exchange (org.apache.camel.Exchange)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)10 RestConfiguration (org.apache.camel.spi.RestConfiguration)10 Producer (org.apache.camel.Producer)7 PollingConsumer (org.apache.camel.PollingConsumer)6 File (java.io.File)5 PollingConsumerPollStrategy (org.apache.camel.spi.PollingConsumerPollStrategy)5 FileNotFoundException (java.io.FileNotFoundException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 SuspendableService (org.apache.camel.SuspendableService)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelContext (org.apache.camel.CamelContext)3 Component (org.apache.camel.Component)3 NoSuchBeanException (org.apache.camel.NoSuchBeanException)3 Route (org.apache.camel.Route)3