/** * Creates an exchange with the given body */ protected Exchange createExchangeWithBody(CamelContext camelContext, Object body) { Exchange exchange = new DefaultExchange(camelContext); Message message = exchange.getIn(); message.setHeader("testClass", getClass().getName()); message.setBody(body); return exchange; }
/** * Creates the exchange for the next processor returned by * {@link #getProcessor()} from a source exchange. * * @param source * a source exchange. * @return exchange for the next processor. */ protected Exchange createDelegateExchange(Exchange source) { DefaultExchange result = new DefaultExchange(source.getContext()); result.getIn().copyFrom(source.getIn()); return result; }
/** * Creates a new {@link Exchange} instance using <code>context</code>. * The resulting exchange's pattern is defined by <code>pattern</code>. * * @param context * Camel context. * @param pattern * exchange pattern. * @return created exchange. */ public static Exchange createExchange(CamelContext context, ExchangePattern pattern) { DefaultExchange target = new DefaultExchange(context); target.setPattern(pattern); return target; }
/** * Creates a new {@link Exchange} instance from the given * <code>exchange</code>. The resulting exchange's pattern is defined by * <code>pattern</code>. * * @param source * exchange to copy from. * @param pattern * exchange pattern to set. * @return created exchange. */ public static Exchange createExchange(Exchange source, ExchangePattern pattern) { DefaultExchange target = new DefaultExchange(source.getContext()); copyExchange(source, target); target.setPattern(pattern); return target; }
public GetSelectionResponse getCurrentSelection() { Exchange e = new DefaultExchange(getContext()); e.getIn().setBody(new GetSelection()); getContext().createProducerTemplate().send("direct:sendAnnotationAlexInOut", e); return e.getOut().getBody(GetSelectionResponse.class); }
@Override @SuppressWarnings("unchecked") public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { oldExchange = new DefaultExchange(newExchange); oldExchange.getIn().setHeaders(newExchange.getIn().getHeaders()); List<Object> body = new ArrayList<Object>(); oldExchange.getIn().setBody(body); oldExchange.getExchangeId(); } oldExchange.getIn().getBody(List.class).add(newExchange.getIn().getBody()); return oldExchange; }
public synchronized void sendInOnlyMessage(Map properties, Map headers, Object body, String endpoint){ Exchange exchange = new DefaultExchange(getCamelContext()); exchange.setPattern(ExchangePattern.InOnly); Endpoint ep = getCamelContext().getEndpoint(endpoint); if (properties!=null){ if(properties.containsKey("methodName")) exchange.setProperty("methodName", properties.get("methodName")); if (properties.containsKey("protocol")) exchange.setProperty("protocol",properties.get("protocol")); } if (headers!=null) exchange.getIn().setHeaders(headers); exchange.getIn().setBody(body); producerTemplate.send(ep, exchange); if (exchange.getException() != null){ logger.warn("caught exception while sending jms message", exchange.getException()); } } @Override
@Override public void onNext(R r) { if (r == null) { throw new NullPointerException("element is null"); } Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody(r); delegate.onNext(exchange); }
String businessKey = execution.getBusinessKey(); Exchange exchange = new DefaultExchange(camelContext); exchange.setProperty(EXCHANGE_HEADER_PROCESS_INSTANCE_ID, execution.getProcessInstanceId()); if (businessKey != null) { exchange.setProperty(EXCHANGE_HEADER_BUSINESS_KEY, businessKey); exchange.setProperty(EXCHANGE_HEADER_CORRELATION_KEY, correlationKey); exchange.getIn().setBody(variablesToSend); exchange.setPattern(ExchangePattern.InOut); Exchange send = producerTemplate.send(endpointUri, exchange); return send.getIn().getBody();
Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut); exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE); exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response)); exchange.getIn().setHeader("CamelServletContextPath", contextPath); String httpPath = (String) exchange.getIn().getHeader(Exchange.HTTP_PATH); exchange.getIn().setHeader(Exchange.HTTP_PATH, httpPath.substring(contextPath.length()));
public synchronized boolean matches(Exchange e) { if (e == null) return false; Throwable t = e.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); Exchange faultMessageExchange = new DefaultExchange(e.getContext()); faultMessageExchange.getIn().setBody(fault.getMessage()); validMessage = faultMessageValidator.matches(faultMessageExchange); logger.warn("The SOAP Fault message is not as expected; received {}", fault.getCode()); Exchange codeExchange = new DefaultExchange(e.getContext()); codeExchange.getIn().setBody(fault.getFaultCode()); validCode = codeValidator.matches(codeExchange); Exchange detailExchange = new DefaultExchange(e.getContext()); detailExchange.getIn().setBody(fault.getDetail()); validDetail = detailValidator.matches(detailExchange);
@Test public void shouldNotConvertFailedExchanges() throws Exception { final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject"); final Exchange exchange = new DefaultExchange(context); final Message out = exchange.getOut(); exchange.setException(new Exception()); out.setBody("wat"); component.getAfterProducer().process(exchange); Assertions.assertThat(out.getBody()).isEqualTo("wat"); }
public static Exchange convertToExchange(CamelContext context, Object data) { Exchange exchange; if (data instanceof Exchange) { exchange = (Exchange) data; } else { exchange = new DefaultExchange(context); exchange.setPattern(ExchangePattern.InOut); exchange.getIn().setBody(data); } return exchange; }
@Test(timeout=60000) public void checkDefinedTimeout() throws Exception { System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "12345"); CamelContext context = getContext(); CamelRpcRequest<EchoRequest,EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest()); CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor(); DefaultExchange defaultExchange = new DefaultExchange(context); defaultExchange.getIn().setBody(wrapper); camelRpcClientPreProcessor.process(defaultExchange); context.stop(); assertEquals(12345L, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER)); }
Exchange exchange = new DefaultExchange(endpoint, exchangePattern); SpringAMQPMessage camelMessage = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpMessage); exchange.setIn(camelMessage); exchange.setException(t); org.apache.camel.Message outMessage = exchange.getOut(); SpringAMQPMessage replyMessage = new SpringAMQPMessage(outMessage);
@Test public void shouldAllowNullInput() throws Exception { final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject"); final Exchange exchange = new DefaultExchange(context); final Message in = exchange.getIn(); component.getBeforeProducer().process(exchange); Assertions.assertThat(in.getBody()).isNull(); }
Exchange inExchange = new DefaultExchange(getCamelContext(), pattern); SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn()); Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange); org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() : outExchange.getIn(); if (camelMsg.isFault()) { result = true;
private Exchange createExchange(Message message) { Exchange exchange = new DefaultExchange(endpoint); org.apache.camel.Message in = new DefaultMessage(); if (payload instanceof Map) { String query = HttpRequest.mapToQuery((Map) payload).toString(); in.setBody(query); } else if (payload instanceof HttpRequest){ HttpRequest httpRequest = (HttpRequest) payload; String queryString = httpRequest.getQueryString(); if (queryString != null) { in.setHeader(Exchange.HTTP_QUERY, queryString); in.setBody(body); exchange.setIn(in);
public Exchange createExchange(MessageExchange exchange) { Exchange result = new DefaultExchange(context); result.setProperty(MESSAGE_EXCHANGE, exchange); result.setPattern(getExchangePattern(exchange)); if (exchange.getOperation() != null) { result.setProperty(OPERATION, exchange.getOperation()); } if (exchange.getMessage("in") != null) { copyFromJbiToCamel(exchange.getMessage("in"), result.getIn()); } copyPropertiesFromJbiToCamel(exchange, result); return result; }