use of org.apache.camel.Producer in project camel by apache.
the class NettyTransferExchangeOptionTest method sendExchange.
private Exchange sendExchange(boolean setException) throws Exception {
Endpoint endpoint = context.getEndpoint("netty:tcp://localhost:{{port}}?transferExchange=true");
Exchange exchange = endpoint.createExchange();
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", "feta");
exchange.setProperty("ham", "old");
exchange.setProperty("setException", setException);
Producer producer = endpoint.createProducer();
producer.start();
// ensure to stop producer after usage
try {
producer.process(exchange);
} finally {
producer.stop();
}
return exchange;
}
use of org.apache.camel.Producer in project camel by apache.
the class NettyTransferExchangeOptionTest method sendExchange.
private Exchange sendExchange(boolean setException) throws Exception {
Endpoint endpoint = context.getEndpoint("netty4:tcp://localhost:{{port}}?transferExchange=true");
Exchange exchange = endpoint.createExchange();
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", "feta");
exchange.setProperty("ham", "old");
exchange.setProperty("setException", setException);
Producer producer = endpoint.createProducer();
producer.start();
// ensure to stop producer after usage
try {
producer.process(exchange);
} finally {
producer.stop();
}
return exchange;
}
use of org.apache.camel.Producer in project camel by apache.
the class RestSwaggerEndpointTest method shouldCreateProducers.
@Test
public void shouldCreateProducers() throws Exception {
final CamelContext camelContext = mock(CamelContext.class);
when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver());
final Endpoint endpointDelegate = mock(Endpoint.class);
when(camelContext.getEndpoint("rest:GET:/v2:/pet/{petId}")).thenReturn(endpointDelegate);
final Producer delegateProducer = mock(Producer.class);
when(endpointDelegate.createProducer()).thenReturn(delegateProducer);
final RestSwaggerComponent component = new RestSwaggerComponent(camelContext);
component.setHost("http://petstore.swagger.io");
final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:getPetById", "getPetById", component);
final Producer producer = endpoint.createProducer();
assertThat(producer).isSameAs(delegateProducer);
}
use of org.apache.camel.Producer in project camel by apache.
the class RestSwaggerEndpoint method createProducer.
@Override
public Producer createProducer() throws Exception {
final CamelContext camelContext = getCamelContext();
final Swagger swagger = loadSpecificationFrom(camelContext, specificationUri);
final Map<String, Path> paths = swagger.getPaths();
for (final Entry<String, Path> pathEntry : paths.entrySet()) {
final Path path = pathEntry.getValue();
final Optional<Entry<HttpMethod, Operation>> maybeOperationEntry = path.getOperationMap().entrySet().stream().filter(operationEntry -> operationId.equals(operationEntry.getValue().getOperationId())).findAny();
if (maybeOperationEntry.isPresent()) {
final Entry<HttpMethod, Operation> operationEntry = maybeOperationEntry.get();
final String uriTemplate = pathEntry.getKey();
final HttpMethod httpMethod = operationEntry.getKey();
final String method = httpMethod.name();
final Operation operation = operationEntry.getValue();
return createProducerFor(swagger, operation, method, uriTemplate);
}
}
final String supportedOperations = paths.values().stream().flatMap(p -> p.getOperations().stream()).map(Operation::getOperationId).collect(Collectors.joining(", "));
throw new IllegalArgumentException("The specified operation with ID: `" + operationId + "` cannot be found in the Swagger specification loaded from `" + specificationUri + "`. Operations defined in the specification are: " + supportedOperations);
}
use of org.apache.camel.Producer 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());
}
}
}
Aggregations