use of org.apache.camel.Processor in project camel by apache.
the class CxfPayLoadMessageXmlBindingRouterTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("cxf:bean:routerEndpoint?dataFormat=PAYLOAD").process(new Processor() {
public void process(Exchange exchange) throws Exception {
CxfPayload<?> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull("We should get the elements here", elements);
assertEquals("Get the wrong elements size", elements.size(), 1);
Element el = new XmlConverter().toDOMElement(elements.get(0));
assertEquals("Get the wrong namespace URI", el.getNamespaceURI(), "http://cxf.component.camel.apache.org/");
}
}).to("cxf:bean:serviceEndpoint?dataFormat=PAYLOAD");
}
};
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfPayLoadSoapHeaderTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: payload
from(getRouterEndpointURI()).process(new Processor() {
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull("We should get the elements here", elements);
assertEquals("Get the wrong elements size", 1, elements.size());
Element el = new XmlConverter().toDOMElement(elements.get(0));
elements.set(0, new DOMSource(el));
assertEquals("Get the wrong namespace URI", "http://camel.apache.org/pizza/types", el.getNamespaceURI());
List<SoapHeader> headers = payload.getHeaders();
assertNotNull("We should get the headers here", headers);
assertEquals("Get the wrong headers size", headers.size(), 1);
assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
// alternatively you can also get the SOAP header via the camel header:
headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
assertNotNull("We should get the headers here", headers);
assertEquals("Get the wrong headers size", headers.size(), 1);
assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
}
}).to(getServiceEndpointURI());
// END SNIPPET: payload
}
};
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfMessageHeadersRelayTest method testInoutHeaderCXFClientNoServiceClassNoRelay.
@Test
public void testInoutHeaderCXFClientNoServiceClassNoRelay() throws Exception {
// TODO: Fix this test later
QName qname = QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SOAPHeaderInfo");
String uri = "cxf:bean:routerNoRelayNoServiceClassEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy";
String requestHeader = "<ns2:SOAPHeaderInfo xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><originator>CxfSoapHeaderRoutePropagationTest.testInOutHeader Requestor" + "</originator><message>Invoking CxfSoapHeaderRoutePropagationTest.testInOutHeader() Request" + "</message></ns2:SOAPHeaderInfo>";
String requestBody = "<ns2:inoutHeader xmlns:ns2=\"http://apache.org/camel/component/cxf/soap/headers\">" + "<requestType>CXF user</requestType></ns2:inoutHeader>";
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(requestBody)).getDocumentElement()));
final List<SoapHeader> headers = new ArrayList<SoapHeader>();
headers.add(new SoapHeader(qname, StaxUtils.read(new StringReader(requestHeader)).getDocumentElement()));
final CxfPayload<SoapHeader> cxfPayload = new CxfPayload<SoapHeader>(headers, elements, null);
Exchange exchange = template.request(uri, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(cxfPayload);
exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inoutHeader");
exchange.getIn().setHeader(Header.HEADER_LIST, headers);
}
});
CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
assertEquals(1, out.getBodySources().size());
assertTrue(out.getBodySources().get(0) instanceof DOMSource);
assertEquals(0, out.getHeaders().size());
String responseExp = "<ns2:inoutHeaderResponse xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><responseType>pass</responseType>" + "</ns2:inoutHeaderResponse>";
String response = StaxUtils.toString(out.getBody().get(0));
//REVISIT use a more reliable comparison to tolerate some namespaces being added to the root element
assertTrue(response, response.startsWith(responseExp.substring(0, 87)) && response.endsWith(responseExp.substring(88, responseExp.length())));
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
from(CXF_RS_ENDPOINT_URI).recipientList(simple("direct:${header.operationName}"));
from("direct:getCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertNotNull(exchange.getIn().getHeader("id"));
long id = exchange.getIn().getHeader("id", Long.class);
if (id == 123) {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals(MessageContentsList.class, exchange.getIn().getBody().getClass());
exchange.getOut().setBody(new Customer(123, "Raul"));
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
} else if (id == 456) {
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
} else {
fail();
}
}
});
from("direct:updateCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
Customer c = exchange.getIn().getBody(Customer.class);
assertEquals(123, c.getId());
assertNotNull(c);
}
});
from("direct:newCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Customer c = exchange.getIn().getBody(Customer.class);
assertNotNull(c);
assertEquals(123, c.getId());
}
});
from("direct:listVipCustomers").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals(MessageContentsList.class, exchange.getIn().getBody().getClass());
assertEquals(0, exchange.getIn().getBody(MessageContentsList.class).size());
CustomerList response = new CustomerList();
List<Customer> list = new ArrayList<Customer>(2);
list.add(new Customer(123, "Raul"));
list.add(new Customer(456, "Raul2"));
response.setCustomers(list);
exchange.getOut().setBody(response);
}
});
from("direct:updateVipCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals("123", exchange.getIn().getHeader("id"));
Customer c = exchange.getIn().getBody(Customer.class);
assertEquals(123, c.getId());
assertNotNull(c);
}
});
from("direct:deleteVipCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals("123", exchange.getIn().getHeader("id"));
}
});
from("direct:uploadImageInputStream").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type"));
assertTrue(InputStream.class.isAssignableFrom(exchange.getIn().getBody().getClass()));
InputStream is = exchange.getIn().getBody(InputStream.class);
is.close();
exchange.getOut().setBody(null);
}
});
from("direct:uploadImageDataHandler").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type"));
assertTrue(DataHandler.class.isAssignableFrom(exchange.getIn().getBody().getClass()));
DataHandler dh = exchange.getIn().getBody(DataHandler.class);
assertEquals("image/jpeg", dh.getContentType());
dh.getInputStream().close();
exchange.getOut().setBody(null);
}
});
from("direct:multipartPostWithParametersAndPayload").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("abcd", exchange.getIn().getHeader("query"));
assertEquals("123", exchange.getIn().getHeader("id"));
assertNotNull(exchange.getIn().getAttachment("part1"));
assertNotNull(exchange.getIn().getAttachment("part2"));
assertNull(exchange.getIn().getHeader("part1"));
assertNull(exchange.getIn().getHeader("part2"));
assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass());
exchange.getOut().setBody(null);
}
});
from("direct:multipartPostWithoutParameters").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertNotNull(exchange.getIn().getAttachment("part1"));
assertNotNull(exchange.getIn().getAttachment("part2"));
assertNull(exchange.getIn().getHeader("part1"));
assertNull(exchange.getIn().getHeader("part2"));
assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass());
exchange.getOut().setBody(null);
}
});
}
};
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfEndpointBeansRouterTest method testCxfBusConfiguration.
@Test
public void testCxfBusConfiguration() throws Exception {
// get the camelContext from application context
CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
ProducerTemplate template = camelContext.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);
}
Aggregations