use of org.apache.camel.spi.Synchronization in project vertx-camel-bridge by vert-x3.
the class InboundEndpointTest method testNoReceiver.
@Test
public void testNoReceiver(TestContext tc) throws Exception {
Async async = tc.async();
Endpoint endpoint = camel.getEndpoint("direct:foo");
bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel(endpoint).toVertx("test").setTimeout(5000)));
camel.start();
BridgeHelper.startBlocking(bridge);
// Unlike the previous test, we don't register a consumer.
ProducerTemplate producer = camel.createProducerTemplate();
producer.asyncCallbackRequestBody(endpoint, "ping", new Synchronization() {
@Override
public void onComplete(Exchange exchange) {
tc.fail("The interaction should fail");
}
@Override
public void onFailure(Exchange exchange) {
tc.assertTrue(exchange.getException().getMessage().contains("No handlers for address test"));
async.complete();
}
});
}
use of org.apache.camel.spi.Synchronization in project webofneeds by researchstudio-sat.
the class MessagingServiceImpl method sendInOutMessageGeneric.
/**
* This method shall be used for Request-Reply messaging.
*
* @param properties
* @param headers
* @param body
* @param endpoint
* @return
*/
public ListenableFuture<String> sendInOutMessageGeneric(Map properties, Map headers, Object body, String endpoint) {
Exchange exchange = new DefaultExchange(getCamelContext());
// TODO: the method name shall be set in the header of the message.
Endpoint ep = getCamelContext().getEndpoint(endpoint);
if (properties != null) {
if (properties.containsKey("methodName")) {
exchange.setProperty("methodName", properties.get("methodName"));
}
}
if (headers != null) {
exchange.getIn().setHeaders(headers);
}
// exchange.getIn().getHeaders().put("CamelJmsRequestTimeout",DEFAULT_JMS_EXPIRATION_TIME);
// exchange.setProperty("JMSExpiration",DEFAULT_JMS_EXPIRATION_TIME);
exchange.getIn().setBody(body);
// exchange.getOut().setBody(body);
exchange.setPattern(ExchangePattern.InOut);
final SettableFuture<String> result = SettableFuture.create();
logger.debug("sending inout message");
producerTemplate.asyncCallback(ep, exchange, new Synchronization() {
@Override
public void onComplete(Exchange exchange) {
String resultObject = (String) exchange.getOut().getBody();
result.set(resultObject);
}
@Override
public void onFailure(Exchange exchange) {
if (exchange.getException() != null) {
logger.warn("caught exception while sending jms message", exchange.getException());
}
result.cancel(true);
}
});
return result;
}
Aggregations