Refine search
@Override public void onComplete(Object response) { exchange.getOut().setHeaders(exchange.getIn().getHeaders()); if (response == null) { exchange.getOut().setBody(response); } else { exchange.getOut().setBody(response, response.getClass()); } callback.done(false); }
@Override public boolean process(Exchange exchange, AsyncCallback callback) { Message message = exchange.getIn(); try { ThriftUtils.invokeAsyncMethod(thriftClient, configuration.getMethod(), message.getBody(), new AsyncClientMethodCallback(exchange, callback)); } catch (Exception e) { if (e.getCause() instanceof TException) { exchange.setException(e.getCause()); } else { exchange.setException(e); } callback.done(true); return true; } return false; }
@Override public boolean process(Exchange exchange, AsyncCallback callback) { final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class)); final CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { try { final RpcResponse response; if (ex != null) { // An exception occurred, store the exception in a new response LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { // No exception occurred, use the given response response = res; } try { exchange.getOut().setBody(module.marshalResponse(response), String.class); postProcess(exchange); } catch (Throwable t) { LOG.error("Marshalling a response in RPC module {} failed.", module, t); exchange.setException(t); exchange.getOut().setFault(true); } } finally { callback.done(false); } }); return false; }
@Override public void completed(Object body) { try { Response response = client.getResponse(); // handle cookies saveCookies(exchange, client, cxfRsEndpoint.getCookieHandler()); //handle error if (shouldHandleError(response)) { handleError(response); return; } if (!exchange.getPattern().isOutCapable()) { return; } LOG.trace("Response body = {}", response); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); final CxfRsBinding binding = cxfRsEndpoint.getBinding(); exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response, exchange)); exchange.getOut().setBody(binding.bindResponseToCamelBody(body, exchange)); exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, response.getStatus()); } catch (Exception exception) { LOG.error("Error while processing response", exception); fail(exception); } finally { callback.done(false); } }
public void run() { log.info("Calling ERP"); // simulate communication with ERP takes 5 seconds try { Thread.sleep(5000); } catch (InterruptedException e) { // ignore } log.info("ERP reply received"); // set reply String in = exchange.getIn().getBody(String.class); exchange.getOut().setBody(in + ";516"); // notify callback we are done // we must use done(false) because the process method returned false log.info("Continue routing"); callback.done(false); } }
@Override public void successCallback(String channel, Object message) { LOG.trace("PubNub response {}", message); exchange.getIn().setHeader(PubNubConstants.CHANNEL, channel); if (exchange.getPattern().isOutCapable()) { exchange.getOut().copyFrom(exchange.getIn()); exchange.getOut().setBody(message); } callback.done(false); }
message = getResponseMessage(exchange, ctx, msg); } catch (Exception e) { exchange.setException(e); callback.done(false); return; if (ExchangeHelper.isOutCapable(exchange)) { exchange.setOut(message); } else { exchange.setIn(message); if (ExchangeHelper.isOutCapable(exchange)) { close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } else { close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); callback.done(false);
@Override public void apply(IgniteFuture<Object> future) { Message in = exchange.getIn(); Message out = exchange.getOut(); MessageHelper.copyHeaders(in, out, true); Object result = null; try { result = future.get(); } catch (Exception e) { exchange.setException(e); callback.done(false); return; } exchange.getOut().setBody(result); callback.done(false); } };
exchange.getIn().getBody(); exchange.getIn().getHeaders(); LOG.trace("Processing exchange {} synchronously", exchange.getExchangeId()); processor.process(exchange); } catch (Exception e) { exchange.setException(e); } finally { callback.done(true); LOG.trace("Processing exchange {} asynchronously", exchange.getExchangeId()); boolean sync = processor.process(exchange, callback); if (!sync) {
public boolean process(Exchange exchange, AsyncCallback callback) { Object statistics = processExchange(exchange); if (statistics != null) { if (exchange.getPattern().isOutCapable()) { exchange.getOut().setBody(statistics); } else { exchange.getIn().setBody(statistics); } } callback.done(true); return true; }
private void processMessage(Exchange exchange, AsyncCallback callback, PNStatus status, Object body) { if (status.isError()) { PNErrorData errorData = status.getErrorData(); exchange.setException(errorData.getThrowable()); if (errorData != null && errorData.getThrowable() instanceof PubNubException) { PubNubException pubNubException = (PubNubException) errorData.getThrowable(); throw new RuntimeException(pubNubException.getPubnubError().getMessage(), errorData.getThrowable()); } throw new RuntimeException(status.getErrorData().getThrowable()); } if (exchange.getPattern().isOutCapable()) { exchange.getOut().copyFrom(exchange.getIn()); exchange.getOut().setBody(body); } else { exchange.getIn().setBody(body); } // signal exchange completion callback.done(false); }
@Override public void run() { org.apache.camel.Message message = exchange.getIn(); SpringAMQPMessage inMessage = new SpringAMQPMessage(message); exchange.setIn(inMessage); //Swap out the old message format String routingKeyHeader = message.getHeader(SpringAMQPComponent.ROUTING_KEY_HEADER, String.class); String routingKey = routingKeyHeader != null ? routingKeyHeader : endpoint.routingKey; String exchangeNameHeader = message.getHeader(SpringAMQPComponent.EXCHANGE_NAME_HEADER, String.class); String exchangeName = exchangeNameHeader != null ? exchangeNameHeader : endpoint.exchangeName; if(exchange.getPattern().isOutCapable()) { LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId()); Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter)); callback.done(false);
@Override public boolean process(final Exchange exchange, final AsyncCallback callback) { final String trackerId = KeyGenerator.createKey(); final long createdAt = System.nanoTime(); final Message in = exchange.getIn(); in.setHeader(IntegrationLoggingConstants.STEP_TRACKER_ID, trackerId); return super.process(exchange, doneSync -> { final String activityId = exchange.getProperty(IntegrationLoggingConstants.ACTIVITY_ID, String.class); final String stepId = in.getHeader(IntegrationLoggingConstants.STEP_ID, String.class); if (activityId != null) { tracker.track( "exchange", activityId, "step", stepId != null ? stepId : "none", "id", trackerId, "duration", System.nanoTime() - createdAt, "failure", failure(exchange) ); } callback.done(doneSync); }); } }
@Override public void done(boolean doneSync) { try { NettyHttpMessage nettyMessage = exchange.hasOut() ? exchange.getOut(NettyHttpMessage.class) : exchange.getIn(NettyHttpMessage.class); if (nettyMessage != null) { HttpResponse response = nettyMessage.getHttpResponse(); if (response != null) { // the actual url is stored on the IN message in the getRequestBody method as its accessed on-demand String actualUrl = exchange.getIn().getHeader(Exchange.HTTP_URL, String.class); int code = response.getStatus() != null ? response.getStatus().getCode() : -1; log.debug("Http responseCode: {}", code); // if there was a http error code then check if we should throw an exception boolean ok = NettyHttpHelper.isStatusCodeOk(code, configuration.getOkStatusCodeRange()); if (!ok && getConfiguration().isThrowExceptionOnFailure()) { // operation failed so populate exception to throw Exception cause = NettyHttpHelper.populateNettyHttpOperationFailedException(exchange, actualUrl, response, code, getConfiguration().isTransferException()); exchange.setException(cause); } } } } finally { // ensure we call the delegated callback callback.done(doneSync); } } }
log.warn("Timeout occurred after {} millis waiting for reply message with correlationID [{}] on destination {}." + " Setting ExchangeTimedOutException on {} and continue routing.", holder.getRequestTimeout(), holder.getCorrelationId(), replyTo, ExchangeHelper.logIds(exchange)); exchange.setException(new ExchangeTimedOutException(exchange, holder.getRequestTimeout(), msg)); } else { if (exchange.hasOut()) { exchange.getOut().setHeader(RabbitMQConstants.CORRELATIONID, holder.getOriginalCorrelationId()); } else { exchange.getIn().setHeader(RabbitMQConstants.CORRELATIONID, holder.getOriginalCorrelationId()); callback.done(false);
public boolean process(final Exchange exchange, AsyncCallback callback) { if (!isRunAllowed()) { if (exchange.getException() == null) { exchange.setException(new RejectedExecutionException()); callback.done(true); return true; if (body == null) { noReplyLogger.log("No payload to send for exchange: " + exchange); callback.done(true); return true; exchange.setException(e); callback.done(true); return true; exchange.setException(e); callback.done(true); return true; exchange.setException(new CamelExchangeException("Cannot get channel from pool", exchange)); callback.done(true); return true; if (exchange.getIn().getHeader(NettyConstants.NETTY_REQUEST_TIMEOUT) != null) { long timeoutInMs = exchange.getIn().getHeader(NettyConstants.NETTY_REQUEST_TIMEOUT, Long.class); ChannelHandler oldHandler = existing.getPipeline().get("timeout"); ReadTimeoutHandler newHandler = new ReadTimeoutHandler(getEndpoint().getTimer(), timeoutInMs, TimeUnit.MILLISECONDS);
String exchangeId = exchange.getExchangeId(); String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn()); Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, timestamp, Date.class); String routeId = routeDefinition.getId(); TracerEventMessage pseudo = new TracerEventMessage(tracer.incrementTraceCounter(), created, routeId, exchangeId, messageAsXml); } catch (Exception e) { exchange.setException(e); callback.done(true); return true; return processor.process(exchange, callback);
public void handleResponse(HttpResponse httpResponse, HttpContext httpContext) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Handle response"); } httpContext.setAttribute(RESPONSE_RECEIVED, Boolean.TRUE); Exchange e = (Exchange) httpContext.getAttribute(Exchange.class.getName()); e.getOut().setBody(httpResponse.getEntity()); HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy(); for (Iterator it = httpResponse.headerIterator(); it.hasNext();) { Header h = (Header) it.next(); if (strategy != null && !strategy.applyFilterToExternalHeaders(h.getName(), h.getValue())) { e.getOut().setHeader(h.getName(), h.getValue()); } } e.getOut().setHeader(HTTP_RESPONSE_CODE, httpResponse.getStatusLine().getStatusCode()); AsyncCallback callback = (AsyncCallback) e.removeProperty(AsyncCallback.class.getName()); callback.done(false); }
private boolean processInOnly(Exchange exchange, AsyncCallback callback) throws Exception { // remove the OVERRIDE header so it does not propagate String exchangeName = (String) exchange.getIn().removeHeader(RabbitMQConstants.EXCHANGE_OVERRIDE_NAME); // If it is BridgeEndpoint we should ignore the message header of EXCHANGE_OVERRIDE_NAME if (exchangeName == null || getEndpoint().isBridgeEndpoint()) { exchangeName = getEndpoint().getExchangeName(); } else { log.debug("Overriding header: {} detected sending message to exchange: {}", RabbitMQConstants.EXCHANGE_OVERRIDE_NAME, exchangeName); } String key = exchange.getIn().getHeader(RabbitMQConstants.ROUTING_KEY, String.class); // we just need to make sure RoutingKey option take effect if it is not BridgeEndpoint if (key == null || getEndpoint().isBridgeEndpoint()) { key = getEndpoint().getRoutingKey() == null ? "" : getEndpoint().getRoutingKey(); } if (ObjectHelper.isEmpty(key) && ObjectHelper.isEmpty(exchangeName)) { throw new IllegalArgumentException("ExchangeName and RoutingKey is not provided in the endpoint: " + getEndpoint()); } basicPublish(exchange, exchangeName, key); callback.done(true); return true; }