private Object sendToCamel(final Exchange switchyardExchange) throws HandlerException { final org.apache.camel.Exchange camelExchange = _producerTemplate.request(_uri, createProcessor(switchyardExchange)); if (camelExchange.getException() != null) { throw new HandlerException(camelExchange.getException()); } return camelExchange.getOut().getBody(); }
private Exchange sendMessage(String endpointUri, final Object msg) { Exchange exchange = template.request( endpointUri, new Processor() { public void process(final Exchange exchange) { exchange.getIn().setBody(msg); } }); return exchange; }
/* (non-Javadoc) * @see com.netflexity.qflex.agent.CallProcessor#processCall(java.lang.Object) */ @Override public OperationType processCall(final OperationType operation) { ProducerTemplate template = camelContext.createProducerTemplate(); Exchange exchange = template.request( route, new Processor() { /* (non-Javadoc) * @see org.apache.camel.Processor#process(org.apache.camel.Exchange) */ public void process(Exchange exchange) throws Exception { Request operationRequest = operation.getRequest(); Object obj = operationRequest.getAny(); exchange.getIn().setBody(obj); } }); OperationType.Result result = new OperationType.Result(); operation.setResult(result); Message message = exchange.getOut(); if (message != null) { logger.debug("Response:" + message.getBody()); if (exchange.getException() != null) { logger.error("Fault processing operation:", exchange.getException()); ErrorType error = new ErrorType(); operation.setError(error); if (exchange.getException() instanceof WMQFaultMessage) { WMQFaultMessage exc = (WMQFaultMessage) exchange.getException(); if (exc.getFaultInfo() != null) { error.setCode(exc.getFaultInfo().getReasonCode()); error.setDescription(exc.getFaultInfo().getDescription()); } else { error.setDescription(exc.getMessage()); } } else { error.setDescription(exchange.getException().getMessage()); } } else { result.setAny(message.getBody()); } message.setBody(operation); } return operation; }
@Test public void testCxfBusConfiguration() throws Exception { // get the camelContext from application context ProducerTemplate template = context.createProducerTemplate(); Exchange reply = template.request( "cxf:bean:serviceEndpoint", new Processor() { public void process(final Exchange exchange) { final List<String> params = new ArrayList<String>(); params.add("hello"); exchange.getIn().setBody(params); exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo"); } }); Exception ex = reply.getException(); assertTrue( "Should get the fault here", ex instanceof org.apache.cxf.interceptor.Fault || ex instanceof HTTPException); }
@Override protected void onExchange(Exchange exchange) throws Exception { ProducerTemplate template = getCamelContext().createProducerTemplate(); exchange = template.request( "http4://www.google.com", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(Exchange.HTTP_METHOD, "GET"); exchange.getIn().setBody("".getBytes("UTF-8")); } }); // Message out = exchange.getOut(); // if (getOutputType() == JoltInputOutputType.JsonString) { // out.setBody(JsonUtils.toJsonString(output)); // } else { // out.setBody(output); // } // out.setHeaders(exchange.getIn().getHeaders()); // out.setAttachments(exchange.getIn().getAttachments()); }