Search in sources :

Example 56 with Endpoint

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

the class UriConfigurationTest method testPageSetting.

@Test
public void testPageSetting() throws Exception {
    Endpoint endpoint = context.getEndpoint("twitter:search?count=50&numberOfPages=2");
    assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
    TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;
    assertEquals(new Integer(50), twitterEndpoint.getProperties().getCount());
    assertEquals(new Integer(2), twitterEndpoint.getProperties().getNumberOfPages());
}
Also used : Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 57 with Endpoint

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

the class TrapTest method testSendReceiveTraps.

@Test
public void testSendReceiveTraps() throws Exception {
    // Create a trap PDU
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);
    OID oid = new OID("1.2.3.4.5");
    trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
    // put your uptime here
    trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));
    //Add Payload
    Variable var = new OctetString("some string");
    trap.add(new VariableBinding(oid, var));
    // Send it
    LOG.info("Sending pdu " + trap);
    Endpoint endpoint = context.getEndpoint("direct:snmptrap");
    Exchange exchange = endpoint.createExchange();
    exchange.getIn().setBody(trap);
    Producer producer = endpoint.createProducer();
    producer.process(exchange);
    synchronized (this) {
        Thread.sleep(1000);
    }
    // If all goes right it should come here
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.assertIsSatisfied();
    List<Exchange> exchanges = mock.getExchanges();
    SnmpMessage msg = (SnmpMessage) exchanges.get(0).getIn();
    PDU receivedTrap = msg.getSnmpMessage();
    Assert.assertEquals(trap, receivedTrap);
    if (LOG.isInfoEnabled()) {
        LOG.info("Received SNMP TRAP:");
        Vector<? extends VariableBinding> variableBindings = receivedTrap.getVariableBindings();
        for (VariableBinding vb : variableBindings) {
            LOG.info("  " + vb.toString());
        }
    }
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) Variable(org.snmp4j.smi.Variable) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TimeTicks(org.snmp4j.smi.TimeTicks) OID(org.snmp4j.smi.OID) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) VariableBinding(org.snmp4j.smi.VariableBinding) Test(org.junit.Test)

Example 58 with Endpoint

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

the class CamelProxyFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    if (endpoint == null) {
        if (ObjectHelper.isNotEmpty(camelContextId)) {
            camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
        }
        if (camelContext == null) {
            throw new IllegalArgumentException("camelContext or camelContextId must be specified");
        }
        if (getServiceUrl() == null && getServiceRef() == null) {
            throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
        }
        // lookup endpoint or we have the url for it
        if (getServiceRef() != null) {
            endpoint = camelContext.getRegistry().lookupByNameAndType(getServiceRef(), Endpoint.class);
        } else {
            endpoint = camelContext.getEndpoint(getServiceUrl());
        }
        if (endpoint == null) {
            throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl());
        }
    }
    // binding is enabled by default
    boolean bind = getBinding() != null ? getBinding() : true;
    try {
        // need to start endpoint before we create producer
        ServiceHelper.startService(endpoint);
        producer = endpoint.createProducer();
        // add and start producer
        camelContext.addService(producer, true, true);
        serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, getServiceInterface());
    } catch (Exception e) {
        throw new FailedToCreateProducerException(endpoint, e);
    }
}
Also used : FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) Endpoint(org.apache.camel.Endpoint) BeansException(org.springframework.beans.BeansException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException)

Example 59 with Endpoint

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

the class ConsumerExceptionPropagationRouteTest method testValidUri.

@Ignore("For now getEndpointUri does not return the initial uri. Info like the endpoint scheme is lost")
@Test
public void testValidUri() throws Exception {
    String deprecate = "spring-ws:rootqname:{http://www.webserviceX.NET/}GetQuote?endpointMapping=#endpointMapping";
    String sanitized = "spring-ws:rootqname:(http://www.webserviceX.NET/)GetQuote?endpointMapping=#endpointMapping";
    Endpoint endpoint = context.getComponent("spring-ws").createEndpoint(deprecate);
    assertEquals(sanitized, endpoint.getEndpointUri());
    assertNotNull(new URI(endpoint.getEndpointUri()));
}
Also used : Endpoint(org.apache.camel.Endpoint) URI(java.net.URI) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 60 with Endpoint

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

the class CustomExchangeFormatterTest method testExchangeFormattersConfiguredProperly.

public void testExchangeFormattersConfiguredProperly() throws Exception {
    TestExchangeFormatter aaa = null;
    TestExchangeFormatter bbb = null;
    for (Endpoint ep : context.getEndpoints()) {
        if (!(ep instanceof LogEndpoint)) {
            continue;
        }
        LogEndpoint log = (LogEndpoint) ep;
        aaa = "aaa".equals(log.getLoggerName()) ? (TestExchangeFormatter) log.getLocalFormatter() : aaa;
        bbb = "bbb".equals(log.getLoggerName()) ? (TestExchangeFormatter) log.getLocalFormatter() : bbb;
    }
    assertNotNull(aaa);
    assertNotNull(bbb);
    assertNotSame(aaa, bbb);
    assertEquals("aaa", aaa.getTestProperty());
    assertEquals("bbb", bbb.getTestProperty());
}
Also used : Endpoint(org.apache.camel.Endpoint)

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