Search in sources :

Example 96 with Endpoint

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

the class QuickfixjComponentTest method createEndpointBeforeComponentStart.

@Test
public void createEndpointBeforeComponentStart() throws Exception {
    setUpComponent();
    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
    writeSettings(settings, true);
    // Should use cached QFJ engine
    Endpoint e1 = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    assertThat(component.getProvisionalEngines().size(), is(1));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue()));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isInitialized(), is(true));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false));
    assertThat(component.getEngines().size(), is(0));
    assertThat(((QuickfixjEndpoint) e1).getSessionID(), is(nullValue()));
    writeSettings(settings, false);
    // Should use cached QFJ engine
    Endpoint e2 = component.createEndpoint(getEndpointUri(settingsFile2.getName(), null));
    assertThat(component.getProvisionalEngines().size(), is(2));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue()));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isInitialized(), is(true));
    assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false));
    assertThat(component.getEngines().size(), is(0));
    assertThat(((QuickfixjEndpoint) e2).getSessionID(), is(nullValue()));
    // will start the component
    camelContext.start();
    assertThat(component.getProvisionalEngines().size(), is(0));
    assertThat(component.getEngines().size(), is(2));
    assertThat(component.getEngines().get(settingsFile.getName()).isInitialized(), is(true));
    assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(true));
    // Move these too an endpoint testcase if one exists
    assertThat(e1.isSingleton(), is(true));
    assertThat(((MultipleConsumersSupport) e1).isMultipleConsumersSupported(), is(true));
    assertThat(e2.isSingleton(), is(true));
    assertThat(((MultipleConsumersSupport) e2).isMultipleConsumersSupported(), is(true));
}
Also used : Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 97 with Endpoint

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

the class QuickfixjComponentTest method messagePublication.

@Test
public void messagePublication() throws Exception {
    setUpComponent();
    // Create settings file with both acceptor and initiator
    SessionSettings settings = new SessionSettings();
    settings.setString(Acceptor.SETTING_SOCKET_ACCEPT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setString(Initiator.SETTING_SOCKET_CONNECT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
    SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "ACCEPTOR", "INITIATOR");
    settings.setString(acceptorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(acceptorSessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
    setSessionID(settings, acceptorSessionID);
    SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "INITIATOR", "ACCEPTOR");
    settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(initiatorSessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
    settings.setLong(initiatorSessionID, Initiator.SETTING_RECONNECT_INTERVAL, 1);
    setSessionID(settings, initiatorSessionID);
    writeSettings(settings, true);
    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    // Start the component and wait for the FIX sessions to be logged on
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch messageLatch = new CountDownLatch(2);
    Consumer consumer = endpoint.createConsumer(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionLogon) {
                logonLatch.countDown();
            } else if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
                messageLatch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);
    // will start the component
    camelContext.start();
    assertTrue("Session not created", logonLatch.await(5000, TimeUnit.MILLISECONDS));
    Endpoint producerEndpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), acceptorSessionID));
    Producer producer = producerEndpoint.createProducer();
    // FIX message to send
    Email email = new Email(new EmailThreadID("ID"), new EmailType(EmailType.NEW), new Subject("Test"));
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);
    // Produce with no session ID specified, session ID must be in message
    Producer producer2 = endpoint.createProducer();
    email.getHeader().setString(SenderCompID.FIELD, acceptorSessionID.getSenderCompID());
    email.getHeader().setString(TargetCompID.FIELD, acceptorSessionID.getTargetCompID());
    producer2.process(exchange);
    assertTrue("Messages not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
}
Also used : Processor(org.apache.camel.Processor) Email(quickfix.fix44.Email) EmailType(quickfix.field.EmailType) EmailThreadID(quickfix.field.EmailThreadID) CountDownLatch(java.util.concurrent.CountDownLatch) SessionSettings(quickfix.SessionSettings) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Subject(quickfix.field.Subject) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) Producer(org.apache.camel.Producer) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 98 with Endpoint

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

the class QuickfixjComponentTest method componentStop.

@Test
public void componentStop() throws Exception {
    setUpComponent();
    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
    writeSettings();
    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    final CountDownLatch latch = new CountDownLatch(1);
    Consumer consumer = endpoint.createConsumer(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionCreated) {
                latch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);
    // Endpoint automatically starts the consumer
    assertThat(((StatefulService) consumer).isStarted(), is(true));
    // will start the component
    camelContext.start();
    assertTrue("Session not created", latch.await(5000, TimeUnit.MILLISECONDS));
    component.stop();
    assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(false));
    // it should still be initialized (ready to start again)
    assertThat(component.getEngines().get(settingsFile.getName()).isInitialized(), is(true));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 99 with Endpoint

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

the class RmiRouteTest method testPojoRoutes.

@Test
public void testPojoRoutes() throws Exception {
    if (classPathHasSpaces()) {
        return;
    }
    // Boot up a local RMI registry
    LocateRegistry.createRegistry(getPort());
    // START SNIPPET: register
    JndiContext context = new JndiContext();
    context.bind("bye", new SayService("Good Bye!"));
    CamelContext camelContext = new DefaultCamelContext(context);
    // END SNIPPET: register
    camelContext.addRoutes(getRouteBuilder(camelContext));
    camelContext.start();
    // START SNIPPET: invoke
    Endpoint endpoint = camelContext.getEndpoint("direct:hello");
    ISay proxy = ProxyHelper.createProxy(endpoint, false, ISay.class);
    String rc = proxy.say();
    assertEquals("Good Bye!", rc);
    // END SNIPPET: invoke
    camelContext.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Endpoint(org.apache.camel.Endpoint) JndiContext(org.apache.camel.util.jndi.JndiContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 100 with Endpoint

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

the class SaxonXsltEndpointConfigurationTest method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    Configuration configuration = context.getRegistry().lookupByNameAndType("saxon-configuration", Configuration.class);
    Map<String, Object> properties = context.getRegistry().lookupByNameAndType("saxon-properties", Map.class);
    XsltComponent component = context.getComponent("xslt", XsltComponent.class);
    XsltEndpoint endpoint = null;
    assertNotNull(configuration);
    assertNotNull(properties);
    for (Endpoint ep : context.getEndpoints()) {
        if (ep instanceof XsltEndpoint) {
            endpoint = (XsltEndpoint) ep;
            break;
        }
    }
    assertNotNull(component);
    assertNotNull(endpoint);
    assertNull(component.getSaxonConfiguration());
    assertTrue(component.getSaxonConfigurationProperties().isEmpty());
    assertNotNull(endpoint.getSaxonConfiguration());
    assertNotNull(endpoint.getSaxonConfigurationProperties());
    assertEquals(configuration, endpoint.getSaxonConfiguration());
    assertEquals(properties, endpoint.getSaxonConfigurationProperties());
}
Also used : Configuration(net.sf.saxon.Configuration) 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