Java Code Examples for org.apache.camel.Exchange#isFailed()
The following examples show how to use
org.apache.camel.Exchange#isFailed() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelSinkTask.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
@Override public void put(Collection<SinkRecord> sinkRecords) { for (SinkRecord record : sinkRecords) { TaskHelper.logRecordContent(LOG, record, config); Map<String, Object> headers = new HashMap<String, Object>(); Exchange exchange = new DefaultExchange(producer.getCamelContext()); headers.put(KAFKA_RECORD_KEY_HEADER, record.key()); for (Iterator<Header> iterator = record.headers().iterator(); iterator.hasNext();) { Header header = (Header)iterator.next(); if (header.key().startsWith(HEADER_CAMEL_PREFIX)) { addHeader(headers, header); } else if (header.key().startsWith(PROPERTY_CAMEL_PREFIX)) { addProperty(exchange, header); } } exchange.getMessage().setHeaders(headers); exchange.getMessage().setBody(record.value()); LOG.debug("Sending exchange {} to {}", exchange.getExchangeId(), LOCAL_URL); producer.send(LOCAL_URL, exchange); if (exchange.isFailed()) { throw new ConnectException("Exchange delivery has failed!", exchange.getException()); } } }
Example 2
Source File: QuarkusPlatformHttpConsumer.java From camel-quarkus with Apache License 2.0 | 6 votes |
static int determineResponseCode(Exchange camelExchange, Object body) { boolean failed = camelExchange.isFailed(); int defaultCode = failed ? 500 : 200; Message message = camelExchange.getMessage(); Integer currentCode = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); int codeToUse = currentCode == null ? defaultCode : currentCode; if (codeToUse != 500) { if ((body == null) || (body instanceof String && ((String) body).trim().isEmpty())) { // no content codeToUse = currentCode == null ? 204 : currentCode; } } return codeToUse; }
Example 3
Source File: DataShapeCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
@Override public void process(final Exchange exchange) { if (exchange.isFailed()) { return; } if (type == null) { return; } final Object body = exchange.getIn().getBody(type); if (body != null) { return; } try { final String bodyAsString = exchange.getIn().getBody(String.class); final Object output = JsonUtils.reader().forType(type).readValue(bodyAsString); exchange.getIn().setBody(output); } catch (final IOException e) { exchange.setException(e); } }
Example 4
Source File: ManagementBusServiceImpl.java From container with Apache License 2.0 | 6 votes |
/** * Handles the response from the plug-in. If needed the response is sent back to the API. * * @param exchange to handle. */ private void handleResponse(Exchange exchange) { if (exchange == null) { return; } // Response message back to caller. final ProducerTemplate template = collaborationContext.getProducer(); final String caller = exchange.getIn().getHeader(MBHeader.APIID_STRING.toString(), String.class); if (caller == null) { // notably the Java API does not set the APIID, because it never uses the information returned. LOG.debug("Invocation was InOnly. No response message will be sent to the caller."); return; } LOG.debug("Sending response message back to api: {}", caller); exchange = template.send("direct-vm:" + caller, exchange); if (exchange.isFailed()) { LOG.error("Sending exchange message failed! {}", exchange.getException().getMessage()); } }
Example 5
Source File: BeanValidatorResource.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Path("/get/{manufactor}/{plate}") @GET @Produces(MediaType.TEXT_PLAIN) public Response get(@PathParam("manufactor") String manufactor, @PathParam("plate") String plate) throws Exception { LOG.info("bean-validator: " + manufactor + "/" + plate); Car car = new Car(manufactor, plate); Exchange out = producerTemplate.request("direct:start", e -> e.getMessage().setBody(car)); if (out.isFailed()) { return Response.status(400, "Invalid car").build(); } else { return Response.status(200, "OK").build(); } }
Example 6
Source File: ActivityTrackingInterceptStrategy.java From syndesis with Apache License 2.0 | 5 votes |
private static String failure(Exchange exchange) { if (exchange.isFailed()) { if (exchange.getException() != null) { return Exceptions.toString(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
Example 7
Source File: TracingInterceptStrategy.java From syndesis with Apache License 2.0 | 5 votes |
private static String failure(Exchange exchange) { if (exchange.isFailed()) { if (exchange.getException() != null) { return Exceptions.toString(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
Example 8
Source File: CamelBehavior.java From flowable-engine with Apache License 2.0 | 5 votes |
protected boolean handleCamelException(Exchange exchange, DelegateExecution execution, boolean isV5Execution) { Exception camelException = exchange.getException(); boolean notHandledByCamel = exchange.isFailed() && camelException != null; if (notHandledByCamel) { if (camelException instanceof BpmnError) { if (isV5Execution) { Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler(); compatibilityHandler.propagateError((BpmnError) camelException, execution); return true; } ErrorPropagation.propagateError((BpmnError) camelException, execution); return true; } else { if (isV5Execution) { Flowable5CompatibilityHandler ompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler(); if (ompatibilityHandler.mapException(camelException, execution, mapExceptions)) { return true; } else { throw new FlowableException("Unhandled exception on camel route", camelException); } } if (ErrorPropagation.mapException(camelException, (ExecutionEntity) execution, mapExceptions)) { return true; } else { throw new FlowableException("Unhandled exception on camel route", camelException); } } } return false; }