Search in sources :

Example 71 with Endpoint

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

the class SpringJmsClientServerTest method testCamelEndpointInvocation.

@Test
public void testCamelEndpointInvocation() throws Exception {
    // get the endpoint from the camel context
    Endpoint endpoint = context.getEndpoint("jms:queue:numbers");
    // create the exchange used for the communication
    // we use the in out pattern for a synchronized exchange where we expect a response
    Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
    // set the input on the in body
    // must you correct type to match the expected type of an Integer object
    exchange.getIn().setBody(11);
    // to send the exchange we need an producer to do it for us
    Producer producer = endpoint.createProducer();
    // start the producer so it can operate
    producer.start();
    // let the producer process the exchange where it does all the work in this one line of code
    producer.process(exchange);
    // get the response from the out body and cast it to an integer
    int response = exchange.getOut().getBody(Integer.class);
    assertEquals("Get a wrong response.", 33, response);
    // stop the producer after usage
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 72 with Endpoint

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

the class AbstractLocalCamelController method getEndpoints.

public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception {
    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
    if (camelContextName != null) {
        CamelContext context = this.getLocalCamelContext(camelContextName);
        if (context != null) {
            List<Endpoint> endpoints = new ArrayList<Endpoint>(context.getEndpoints());
            // sort routes
            Collections.sort(endpoints, new Comparator<Endpoint>() {

                @Override
                public int compare(Endpoint o1, Endpoint o2) {
                    return o1.getEndpointKey().compareTo(o2.getEndpointKey());
                }
            });
            for (Endpoint endpoint : endpoints) {
                Map<String, String> row = new LinkedHashMap<String, String>();
                row.put("camelContextName", context.getName());
                row.put("uri", endpoint.getEndpointUri());
                row.put("state", getEndpointState(endpoint));
                answer.add(row);
            }
        }
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 73 with Endpoint

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

the class MongoDbReadPreferenceOptionTest method createMongoDbEndpoint.

private MongoDbEndpoint createMongoDbEndpoint(String uri) throws Exception {
    Endpoint endpoint = context().getComponent("mongodb").createEndpoint(uri);
    endpoint.start();
    return (MongoDbEndpoint) endpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint)

Example 74 with Endpoint

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

the class MQTTConfigurationTest method testBasicConfiguration.

@Test
public void testBasicConfiguration() throws Exception {
    Endpoint endpoint = context.getEndpoint("mqtt:todo?byDefaultRetain=true&qualityOfService=exactlyOnce&publishTopicName=" + TEST_TOPIC + "&subscribeTopicName=" + TEST_TOPIC + "&host=" + MQTTTestSupport.getHostForMQTTEndpoint());
    assertTrue("Endpoint not a MQTTEndpoint: " + endpoint, endpoint instanceof MQTTEndpoint);
    MQTTEndpoint mqttEndpoint = (MQTTEndpoint) endpoint;
    assertEquals(mqttEndpoint.getConfiguration().getQoS(), QoS.EXACTLY_ONCE);
    assertEquals(mqttEndpoint.getConfiguration().getPublishTopicName(), TEST_TOPIC);
    assertEquals(mqttEndpoint.getConfiguration().getSubscribeTopicName(), TEST_TOPIC);
    assertTrue(mqttEndpoint.getConfiguration().isByDefaultRetain());
}
Also used : Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 75 with Endpoint

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

the class AbstractSpanDecoratorTest method testStripSchemeNoOptions.

@Test
public void testStripSchemeNoOptions() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("direct:hello");
    assertEquals("hello", AbstractSpanDecorator.stripSchemeAndOptions(endpoint));
}
Also used : 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