Search in sources :

Example 91 with Endpoint

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

the class AbstractHttpSpanDecoratorTest method testGetHttpURLFromEndpointUriWithAdditionalScheme.

@Test
public void testGetHttpURLFromEndpointUriWithAdditionalScheme() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("netty-http:" + TEST_URI);
    Mockito.when(exchange.getIn()).thenReturn(message);
    AbstractHttpSpanDecorator decorator = new AbstractHttpSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    assertEquals(TEST_URI, decorator.getHttpURL(exchange, endpoint));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Message(org.apache.camel.Message) Test(org.junit.Test)

Example 92 with Endpoint

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

the class AbstractMessagingSpanDecoratorTest method testOperationName.

@Test
public void testOperationName() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
    SpanDecorator decorator = new AbstractMessagingSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    assertEquals("MyQueue", decorator.getOperationName(null, endpoint));
}
Also used : Endpoint(org.apache.camel.Endpoint) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) Test(org.junit.Test)

Example 93 with Endpoint

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

the class AbstractMessagingSpanDecoratorTest method testPreMessageBusDestination.

@Test
public void testPreMessageBusDestination() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
    SpanDecorator decorator = new AbstractMessagingSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, null, endpoint);
    assertEquals("MyQueue", span.tags().get(Tags.MESSAGE_BUS_DESTINATION.getKey()));
}
Also used : Endpoint(org.apache.camel.Endpoint) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 94 with Endpoint

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

the class CamelJob method lookupQuartzEndpoint.

private QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, String endpointUri, Trigger trigger) throws JobExecutionException {
    String targetTriggerName = trigger.getName();
    String targetTriggerGroup = trigger.getGroup();
    LOG.debug("Looking up existing QuartzEndpoint with trigger {}.{}", targetTriggerName, targetTriggerGroup);
    try {
        // as we prefer to use the existing endpoint from the routes
        for (Route route : camelContext.getRoutes()) {
            Endpoint endpoint = route.getEndpoint();
            if (endpoint instanceof DelegateEndpoint) {
                endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
            }
            if (endpoint instanceof QuartzEndpoint) {
                QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;
                String triggerName = quartzEndpoint.getTrigger().getName();
                String triggerGroup = quartzEndpoint.getTrigger().getGroup();
                LOG.trace("Checking route trigger {}.{}", triggerName, triggerGroup);
                if (triggerName.equals(targetTriggerName) && triggerGroup.equals(targetTriggerGroup)) {
                    return (QuartzEndpoint) endpoint;
                }
            }
        }
    } catch (Exception e) {
        throw new JobExecutionException("Error lookup up existing QuartzEndpoint with trigger: " + trigger, e);
    }
    // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
    if (camelContext.hasEndpoint(endpointUri) != null) {
        return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    } else {
        LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
        return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

Example 95 with Endpoint

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

the class TradeExecutorComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    synchronized (endpoints) {
        Endpoint endpoint = endpoints.get(uri);
        if (endpoint == null) {
            endpoint = new TradeExecutorEndpoint(uri, new TradeExecutor());
            endpoints.put(uri, (TradeExecutorEndpoint) endpoint);
            LOG.info("Created trade executor: " + uri);
        }
        return endpoint;
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint)

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