/** * Returns <code>true</code> if the message represents an error message. * * @return <code>true</code> if the message represents an error message. * * @see Exchange#isFailed() */ public boolean isFailed() { return exchange.isFailed(); }
/** * Returns <code>false</code> if the <code>response</code> exchange * failed indicating that processing shall stop. * * @param original * original message exchange. * @param response * response message exchange. * @return <code>false</code> if <code>response</code> failed, * <code>true</code> otherwise. */ @Override protected boolean process(Exchange original, Exchange response) { return !response.isFailed(); }
@Override public void onExchangeDone(Route route, Exchange exchange) { System.out.println(toJsonObject( "exchange", exchange.getExchangeId(), "status", "done", "failed", exchange.isFailed())); } };
... @Override public void process(Exchange exchange) throws Exception { System.out.println("In ........"); try { File file = new File("soapbody.xml"); // generic body in separate XML file for every time DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); String body = doc.toString(); exchange.getIn().setBody(body ); } catch (Exception e) { e.printStackTrace(); } System.out.println("in process method"); System.out.println(exchange.getExchangeId() + " : " + exchange.getFromRouteId() + " : " + exchange.isFailed()); } ...
@Override public final void process(final Exchange exchange) throws Exception { if (exchange.isFailed()) { return; } if (type == null) { return; } final Message message = message(exchange); final String bodyAsString = message.getBody(String.class); if (bodyAsString == null) { return; } try { final Object output = MAPPER.readValue(bodyAsString, type); message.setBody(output); } catch (final IOException e) { exchange.setException(e); } }
@Override public final void process(final Exchange exchange) throws Exception { if (exchange.isFailed()) { return; } if (type == null) { return; } final Message message = message(exchange); final String bodyAsString = message.getBody(String.class); if (bodyAsString == null) { return; } try { final Object output = MAPPER.readValue(bodyAsString, type); message.setBody(output); } catch (final IOException e) { exchange.setException(e); } }
@Override public void post(Span span, Exchange exchange, Endpoint endpoint) { if (exchange.isFailed()) { span.setTag(Tags.ERROR.getKey(), true); if (exchange.getException() != null) { Map<String, String> logEvent = new HashMap<>(); logEvent.put("event", "error"); logEvent.put("error.kind", "Exception"); logEvent.put("message", exchange.getException().getMessage()); span.log(logEvent); } } }
@Override public void process(final Exchange exchange) { if (exchange.isFailed()) { return; } if (type == null) { return; } final Message message = exchange.getIn(); final String bodyAsString = message.getBody(String.class); if (bodyAsString == null) { return; } try { final Object output = Json.reader().forType(type).readValue(bodyAsString); message.setBody(output); } catch (final IOException e) { exchange.setException(e); } } }
@Override public void onExchangeDone(Route route, Exchange exchange) { if (tracker == null) { return; } final String activityId = exchange.getProperty(IntegrationLoggingConstants.ACTIVITY_ID, String.class); final String exchangeId = exchange.getExchangeId(); if (Objects.nonNull(activityId) && Objects.equals(activityId, exchangeId)) { tracker.track( "exchange", activityId, "status", "done", "failed", exchange.isFailed() ); } } }
default Tags getTags(AbstractExchangeEvent event, Endpoint endpoint) { return Tags.of( CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(), SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(), EVENT_TYPE_TAG, event.getClass().getSimpleName(), ENDPOINT_NAME, endpoint.getEndpointUri(), FAILED_TAG, Boolean.toString(event.getExchange().isFailed()) ); } }
default Tags getTags(Route route, Exchange exchange) { return Tags.of( CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName(), SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(), ROUTE_ID_TAG, route.getId(), FAILED_TAG, Boolean.toString(exchange.isFailed()) ); }
private static String failure(Exchange exchange) { if (exchange.isFailed()) { if (exchange.getException() != null) { return getStackTrace(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
private static String failure(Exchange exchange) { if( exchange.isFailed() ) { if( exchange.getException()!=null ) { return toString(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
@Override public void onExchangeDone(Route route, Exchange exchange) { if (exchange != null && exchange.isFailed()) { Throwable t = exchange.getException(); if (t == null) { // this handles an alternative representation for exceptions in camel try { t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class); } catch (RuntimeException e) { LOG.warn("Unable to handle exception in exchange in route: [{}]", exchange.getFromRouteId()); t = e; } } if (t != null) { doHandleFailedExchange(exchange, t); } } } }
private ZooKeeperEndpoint createCandidateNode(CamelContext camelContext) { LOG.info("Initializing ZookeeperElection with uri '{}'", uri); ZooKeeperEndpoint zep = camelContext.getEndpoint(uri, ZooKeeperEndpoint.class); zep.getConfiguration().setCreate(true); String fullpath = createFullPathToCandidate(zep); Exchange e = zep.createExchange(); e.setPattern(ExchangePattern.InOut); e.getIn().setHeader(ZooKeeperMessage.ZOOKEEPER_NODE, fullpath); e.getIn().setHeader(ZooKeeperMessage.ZOOKEEPER_CREATE_MODE, CreateMode.EPHEMERAL_SEQUENTIAL); producerTemplate.send(zep, e); if (e.isFailed()) { LOG.warn("Error setting up election node {}", fullpath, e.getException()); } else { LOG.info("Candidate node '{}' has been created", fullpath); try { camelContext.addRoutes(new ElectoralMonitorRoute(zep)); } catch (Exception ex) { LOG.warn("Error configuring ZookeeperElection", ex); } } return zep; }
public void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException { Message target = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); if (exchange.isFailed()) { if (exchange.getException() != null) { doWriteExceptionResponse(exchange.getException(), response); } else { // it must be a fault, no need to check for the fault flag on the message doWriteFaultResponse(target, response, exchange); } } else { if (exchange.hasOut()) { // just copy the protocol relates header if we do not have them copyProtocolHeaders(exchange.getIn(), exchange.getOut()); } doWriteResponse(target, response, exchange); } }
private void handleInOnly(final Exchange exchange) throws HandlerException { try { final org.apache.camel.Exchange camelExchange = _producerTemplate.send(_uri, createProcessor(exchange)); Object propagateException = _domain.getProperty(Exchange.PROPAGATE_EXCEPTION_ON_IN_ONLY); if ((propagateException == null || Boolean.parseBoolean(propagateException.toString())) && camelExchange.isFailed()) { Exception camelException = camelExchange.getException(); if (camelException != null) { throw new HandlerException(camelException); } else { throw CommonCamelMessages.MESSAGES.camelExchangeFailedWithoutAnException(""); } } } catch (final CamelExecutionException e) { throw new HandlerException(e); } }
private void handleInOnly(final Exchange exchange) throws HandlerException { try { final org.apache.camel.Exchange camelExchange = _producerTemplate.send(_uri, createProcessor(exchange)); Object propagateException = _domain.getProperty(Exchange.PROPAGATE_EXCEPTION_ON_IN_ONLY); if ((propagateException == null || Boolean.parseBoolean(propagateException.toString())) && camelExchange.isFailed()) { Exception camelException = camelExchange.getException(); if (camelException != null) { throw new HandlerException(camelException); } else { throw CommonCamelMessages.MESSAGES.camelExchangeFailedWithoutAnException(""); } } } catch (final CamelExecutionException e) { throw new HandlerException(e); } }
protected void processResult(Object result, boolean lastElementInBatch) { // lets turn the result into an exchange and fire it // into the processor Exchange exchange = createExchange(result, lastElementInBatch); try { getProcessor().process(exchange); if (exchange.isFailed()) { throw new RuntimeCamelException(exchange.getException()); } } catch (Exception e) { LOG.error("Failed: " + e, e); if (e instanceof RuntimeCamelException) { throw (RuntimeCamelException)e; } else { throw new RuntimeCamelException(e); } } }
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); }