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());
}
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());
}
}
}
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);
}
}
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()));
}
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());
}
Aggregations