Boolean onlyLast = (Boolean) exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST); if (onlyLast != null && onlyLast) {
public void onExchangeDone(Exchange exchange) { Timer.Context context = (Timer.Context) exchange.removeProperty("MetricsRoutePolicy-" + routeId); if (context != null) { context.stop(); } } }
@Override public final void process(Exchange exchange) throws Exception { // check error CallbackResponse callbackResponse = (CallbackResponse) exchange.removeProperty(AsynchConstants.ERR_CALLBACK_RES_PROP); if (callbackResponse == null) { // no error callbackResponse = exchange.getIn().getBody(CallbackResponse.class); } exchange.getIn().setBody(setCallbackResponse(callbackResponse)); }
void handleStop(Exchange exchange, MetricRegistry registry, String metricsName) { String propertyName = getPropertyName(metricsName); Timer.Context context = getTimerContextFromExchange(exchange, propertyName); if (context != null) { context.stop(); exchange.removeProperty(propertyName); } else { LOG.warn("Timer \"{}\" not found", metricsName); } }
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); }
protected void finalizeExternalCall(Exchange exchange, ExternalCall externalCall, ExternalCallService service) { Boolean success = exchange.getProperty(ExtCallComponentParams.EXTERNAL_CALL_SUCCESS, Boolean.class); if (success == null) { // success is not defined forcefully -> determine success normally success = !exchange.isFailed() && isNotTrue(exchange.getProperty(Exchange.ROUTE_STOP, Boolean.class)); } if (success) { service.complete(externalCall); } else { service.failed(externalCall); } // cleanup: exchange.removeProperty(ExtCallComponentParams.EXTERNAL_CALL_OPERATION); exchange.removeProperty(ExtCallComponentParams.EXTERNAL_CALL_KEY); exchange.removeProperty(ExtCallComponentParams.EXTERNAL_CALL_SUCCESS); }
/** * Extracts the exception handled while processing the given * exchange (if any), and optionally marks the exchange as non-failed. * * @param exchange * Camel exchange, should be not <code>null</code>. * @param cleanup * <code>true</code> iff the information about the occurred exception * should be removed from the given exchange. * @return * an {@link Exception} instance, or <code>null</code> when no exception was handled. */ public static Exception extractException(Exchange exchange, boolean cleanup) { Exception exception = exchange.getException(); if (exception != null) { if (cleanup) { exchange.setException(null); } } else if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); if (cleanup) { exchange.removeProperty(Exchange.EXCEPTION_CAUGHT); exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED); } } return exception; }
@Override public void removeProperty(Property property) { switch (property.getScope()) { case EXCHANGE: _exchange.removeProperty(property.getName()); break; default: _message.removeHeader(property.getName()); break; } }
@Override public void removeProperty(Property property) { switch (property.getScope()) { case EXCHANGE: _exchange.removeProperty(property.getName()); break; default: _message.removeHeader(property.getName()); break; } }
protected void executeExternalCall(Exchange exchange, String targetURI) { try { // success should not be determined before the call is made exchange.removeProperty(ExtCallComponentParams.EXTERNAL_CALL_SUCCESS); // route exchange to external call target getEndpoint().getProducerTemplate().send(targetURI, exchange); } catch (Exception exc) { exchange.setException(exc); // this also marks exchange as failed } }
/** * Strategy when processing the exchange failed. * * @param mail the mail message * @param exchange the exchange */ protected void processRollback(Message mail, Exchange exchange) { String uid = (String) exchange.removeProperty(MAIL_MESSAGE_UID); // need to remove on rollback if (getEndpoint().getIdempotentRepository() != null) { getEndpoint().getIdempotentRepository().remove(uid); } Exception cause = exchange.getException(); if (cause != null) { LOG.warn("Exchange failed, so rolling back message status: {}", exchange, cause); } else { LOG.warn("Exchange failed, so rolling back message status: {}", exchange); } }
@Override protected void doProcess(Exchange exchange, MicrometerEndpoint endpoint, Timer timer) { String propertyName = getPropertyName(timer.getId().getName()); Timer.Sample sample = getTimerSampleFromExchange(exchange, propertyName); sample.stop(timer); exchange.removeProperty(propertyName); }
public Exchange unmarshallExchange(CamelContext camelContext, byte[] buffer) throws IOException, ClassNotFoundException { DefaultExchangeHolder pe = decode(buffer); Exchange answer = new DefaultExchange(camelContext); DefaultExchangeHolder.unmarshal(answer, pe); // restore the from endpoint String fromEndpointUri = (String) answer.removeProperty("CamelAggregatedFromEndpoint"); if (fromEndpointUri != null) { Endpoint fromEndpoint = camelContext.hasEndpoint(fromEndpointUri); if (fromEndpoint != null) { answer.setFromEndpoint(fromEndpoint); } } return answer; }
public Exchange unmarshallExchange(CamelContext camelContext, byte[] buffer) throws IOException, ClassNotFoundException { DefaultExchangeHolder pe = decode(camelContext, buffer); Exchange answer = new DefaultExchange(camelContext); DefaultExchangeHolder.unmarshal(answer, pe); // restore the from endpoint String fromEndpointUri = (String) answer.removeProperty("CamelAggregatedFromEndpoint"); if (fromEndpointUri != null) { Endpoint fromEndpoint = camelContext.hasEndpoint(fromEndpointUri); if (fromEndpoint != null) { answer.setFromEndpoint(fromEndpoint); } } return answer; }
public Exchange unmarshallExchange(CamelContext camelContext, ByteBuffer buffer) throws IOException, ClassNotFoundException { DefaultExchangeHolder pe = (DefaultExchangeHolder) deserialize(new ByteBufferInputStream(buffer)); Exchange answer = new DefaultExchange(camelContext); DefaultExchangeHolder.unmarshal(answer, pe); // restore the from endpoint String fromEndpointUri = (String) answer.removeProperty("CamelAggregatedFromEndpoint"); if (fromEndpointUri != null) { Endpoint fromEndpoint = camelContext.hasEndpoint(fromEndpointUri); if (fromEndpoint != null) { answer.setFromEndpoint(fromEndpoint); } } return answer; }
/** * Processes the audit event */ public void process(AuditEventNotifier auditor, AuditEvent auditEvent) { if (matchesEvent(auditEvent)) { ProducerTemplate producer = auditor.getProducerTemplate(); Endpoint endpoint = getToEndpoint(auditor.getCamelContext()); if (endpoint != null) { Exchange exchange = endpoint.createExchange(); // make sure we don't send out events for this as well // mark exchange as being published to event, to prevent creating new events // for this as well (causing a endless flood of events) exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.TRUE); Object payload = createPayload(auditEvent); exchange.getIn().setBody(payload); try { producer.send(endpoint, exchange); } finally { // TODO why do we bother removing the notify event flag??? // and remove it when its done exchange.removeProperty(Exchange.NOTIFY_EVENT); } } } }
public Exchange unmarshallExchange(CamelContext camelContext, Buffer buffer) throws IOException { DataByteArrayInputStream bais = new DataByteArrayInputStream(buffer); DefaultExchangeHolder pe = exchangeCodec.decode(bais); Exchange answer = new DefaultExchange(camelContext); DefaultExchangeHolder.unmarshal(answer, pe); // restore the from endpoint String fromEndpointUri = (String) answer.removeProperty("CamelAggregatedFromEndpoint"); if (fromEndpointUri != null) { Endpoint fromEndpoint = camelContext.hasEndpoint(fromEndpointUri); if (fromEndpoint != null) { answer.setFromEndpoint(fromEndpoint); } } return answer; }
public void onExchangeDone(Exchange exchange) { Timer.Sample sample = (Timer.Sample) exchange.removeProperty(propertyName(exchange)); if (sample != null) { Timer timer = Timer.builder(namingStrategy.getName(route)) .tags(namingStrategy.getTags(route, exchange)) .description(route.getDescription()) .register(meterRegistry); sample.stop(timer); } }
Boolean onlyLast = (Boolean) exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST); if (onlyLast != null && onlyLast) {
protected void handleDoneEvent(AbstractExchangeEvent doneEvent) { String name = namingStrategy.getName(doneEvent.getExchange(), doneEvent.getExchange().getFromEndpoint()); Tags tags = namingStrategy.getTags(doneEvent, doneEvent.getExchange().getFromEndpoint()); // Would have preferred LongTaskTimer, but you cannot set the FAILED_TAG once it is registered Timer.Sample sample = (Timer.Sample) doneEvent.getExchange().removeProperty("eventTimer:" + name); if (sample != null) { sample.stop(getMeterRegistry().timer(name, tags)); } }