public Message getResponse() { return exchange.getOut(); }
protected void processInTransaction(final Exchange exchange) throws Exception { Boolean externalRedelivered = exchange.isExternalRedelivered(); final String redelivered = externalRedelivered != null ? externalRedelivered.toString() : "unknown"; final String ids = ExchangeHelper.logIds(exchange); if (exchange.getUnitOfWork() != null) { exchange.getUnitOfWork().beginTransactedBy(transactionKey); exchange.setException(e); logTransactionRollback(redelivered, ids, e, false); } finally { if (exchange.getUnitOfWork() != null) { exchange.getUnitOfWork().endTransactedBy(transactionKey); Boolean onlyLast = (Boolean) exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST); if (onlyLast != null && onlyLast) { Exception cause = exchange.getException(); if (cause != null) { log.debug("Transaction rollback (" + transactionKey + ") redelivered(" + redelivered + ") for " exchange.setException(null);
if (!sync) { log.trace("Waiting for asynchronous callback before continuing for exchangeId: {} -> {}", exchange.getExchangeId(), exchange); try { latch.await(); } catch (InterruptedException e) { exchange.setException(e); exchange.getExchangeId(), exchange);
protected void doInTransactionWithoutResult(TransactionStatus status) { // wrapper exception to throw if the exchange failed // IMPORTANT: Must be a runtime exception to let Spring regard it as to do "rollback" RuntimeException rce; // and now let process the exchange by the error handler processByErrorHandler(exchange); // after handling and still an exception or marked as rollback only then rollback if (exchange.getException() != null || exchange.isRollbackOnly()) { // wrap exception in transacted exception if (exchange.getException() != null) { rce = ObjectHelper.wrapRuntimeCamelException(exchange.getException()); } else { // create dummy exception to force spring transaction manager to rollback rce = new TransactionRollbackException(); } if (!status.isRollbackOnly()) { status.setRollbackOnly(); } // throw runtime exception to force rollback (which works best to rollback with Spring transaction manager) if (log.isTraceEnabled()) { log.trace("Throwing runtime exception to force transaction to rollback on {}", transactionTemplate.getName()); } throw rce; } } });
private void restoreDroplet(Exchange exchange) throws Exception { if (ObjectHelper.isEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID))) { throw new IllegalArgumentException(DigitalOceanHeaders.IMAGE_ID + " must be specified"); } Action action = getEndpoint().getDigitalOceanClient().restoreDroplet(dropletId, exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID, Integer.class)); LOG.trace("DropletAction Restore [{}] ", action); exchange.getOut().setBody(action); }
@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 void process(Exchange exchange) throws Exception { final INDArray arr = (INDArray) exchange.getIn().getBody(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); byte[] bytes = bos.toByteArray(); String base64 = Base64.encodeBase64String(bytes); exchange.getIn().setBody(base64, String.class); String id = UUID.randomUUID().toString(); exchange.getIn().setHeader(KafkaConstants.KEY, id); exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id); } }).to(kafkaUri);
private void handleHttpFailure(Exchange exchange) { HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT, String.format("%d %s", e.getStatusCode(), e.getResponseBody()) )); } }
@Test public void testValidator4() throws InterruptedException, IOException { final String xml = IOUtils.toString(getClass().getResourceAsStream("/xsd/invalidtest.xml"), Charset.defaultCharset()); error.expectedMessageCount(1); Exchange exchange = producerTemplate.send("direct:validator-xml-test", ExchangePattern.InOut, exchange1 -> exchange1.getIn().setBody(xml)); assertEquals(ValidationException.class, exchange.getException() .getClass()); ValidationException e = (ValidationException) exchange.getException(); assertEquals(5, e.getCauses().length); error.assertIsSatisfied(2000); }
@Override public String unlink(final GroupPatch groupPatch) { PollingConsumer pollingConsumer = getConsumer("direct:unlinkGroupPort"); sendMessage("direct:unlinkGroup", groupPatch); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(GroupPatch.class).getKey(); }
protected static boolean hasParameter(String nextParam, Exchange exchange, Object body) { Map<?, ?> bodyMap = safeMap(exchange.getContext().getTypeConverter().tryConvertTo(Map.class, body)); Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders()); if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) { return true; } else if (bodyMap.containsKey(nextParam)) { return true; } else if (headersMap.containsKey(nextParam)) { return true; } return false; }
public void process(Exchange exchange) throws Exception { exchange.setPattern( ExchangePattern.InOut ); BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty( BindingOperationInfo.class.toString() ); if ( boi != null ) { LOG.info( "boi.isUnwrapped" + boi.isUnwrapped() ); } SOAPMessage soapMessage = (SOAPMessage) exchange.getIn().getBody(); exchange.getOut().setBody( soapMessage.getSOAPBody().getTextContent() ); } }
private Object getMultiInsertBody(Exchange exchange) { Object insert; // we try List first, because it should be the common case insert = exchange.getIn().getBody(List.class); if (insert != null) { // if the body of type List was obtained, ensure that all items are of type DBObject and cast the List to List<DBObject> insert = attemptConvertToList((List<?>) insert, exchange); } else { insert = exchange.getContext().getTypeConverter().tryConvertTo(BasicDBList.class, exchange, exchange.getIn().getBody()); } if (insert == null) { throw new CamelMongoDbException("MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject>"); } return insert; }
@Test public void testExceptionMessage() throws InterruptedException { mockOutput.expectedMessageCount(1); Exchange result = producerTemplate.request("direct:input2", exchange -> exchange.getIn().setBody("blah")); mockOutput.assertIsSatisfied(); Exchange received = mockOutput.getExchanges().get(0); assertEquals("message rejected", result.getException().getMessage()); assertEquals("message rejected", result.getOut().getBody()); assertNull(received.getException()); }
private void compare(long expected, Exchange exchange) { long update = exchange.getIn().getBody(Long.class); if (ObjectHelper.isEmpty(expected)) { throw new IllegalArgumentException("Expected value must be specified"); } exchange.getOut().setBody(this.atomicnumber.compareAndSet(expected, update)); }
@SuppressWarnings("unchecked") public void updateExchange(Exchange groupedExchange) { List<Exchange> exchangeList = groupedExchange.getProperty(Exchange.GROUPED_EXCHANGE, List.class); if (exchangeList.size() == 1) { Exchange orignalBookingExchange = exchangeList.get(0); String federatedQueryGUID = (String) orignalBookingExchange.getIn().getHeader("federatedQueryRequestGUID"); groupedExchange.getIn().setBody(orignalBookingExchange.getIn().getHeader("requestMessageBody")); groupedExchange.getIn().setHeader("federatedQueryRequestGUID", federatedQueryGUID); } }
@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); }
private static void getParamsFromHeaders( Exchange exchange, Collection<String> args) { Map<String, Object> headers = exchange.getIn().getHeaders(); for (Map.Entry<String, Object> header : headers.entrySet()) { Object headerValue = header.getValue(); if (headerValue != null) { String headerStringValue = exchange.getContext().getTypeConverter() .convertTo(String.class, exchange, headerValue); args.add("--context_param " + header.getKey() + '=' + headerStringValue); } } }