use of java.util.ArrayList in project camel by apache.
the class CxfMixedModeRouterTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
errorHandler(noErrorHandler());
from(routerEndpointURI).process(new Processor() {
// convert request message
public void process(Exchange exchange) throws Exception {
CxfPayload<?> message = exchange.getIn().getBody(CxfPayload.class);
List<String> params = new ArrayList<String>();
if (message != null) {
// convert CxfPayload to list of objects any way you like
Element element = new XmlConverter().toDOMElement(message.getBody().get(0));
params.add(element.getFirstChild().getTextContent());
}
// replace the body
exchange.getIn().setBody(params);
// if you need to change the operation name
//exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
}
}).to(serviceEndpointURI).process(new Processor() {
// convert response to CxfPayload
public void process(Exchange exchange) throws Exception {
List<?> list = exchange.getIn().getBody(List.class);
CxfPayload<SoapHeader> message = null;
if (list != null) {
// convert the list of objects to CxfPayload any way you like
String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">" + "<return xmlns=\"http://cxf.component.camel.apache.org/\">" + list.get(0) + "</return></ns1:echoResponse>";
List<Element> body = new ArrayList<Element>();
body.add(StaxUtils.read(new StringReader(s)).getDocumentElement());
message = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), body);
}
exchange.getIn().setBody(message);
// we probably should be smarter in detecting data format based on message body
// but for now we need to explicitly reset the mode (see CAMEL-3420)
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
}
});
}
};
}
use of java.util.ArrayList in project camel by apache.
the class LoadDistributorFeatureTest method startRoute.
private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
ctx.addRoutes(new RouteBuilder() {
public void configure() {
List<String> serviceList = new ArrayList<String>();
serviceList.add(SERVICE_ADDRESS_1);
serviceList.add(SERVICE_ADDRESS_2);
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(serviceList);
LoadDistributorFeature ldf = new LoadDistributorFeature();
ldf.setStrategy(strategy);
CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
endpoint.getFeatures().add(ldf);
from(proxy).to(endpoint);
}
});
ctx.start();
}
use of java.util.ArrayList 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 java.util.ArrayList in project camel by apache.
the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.
protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
if (!expect) {
if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
return;
}
fail("Should have got *no* out-of-band headers, but some were found");
}
if (oobHdr == null) {
fail("Should have got List of out-of-band headers");
}
assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
for (Header hdr1 : oobHdr) {
if (hdr1.getObject() instanceof Node) {
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
hdrToTest.add((OutofBandHeader) job.getValue());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
use of java.util.ArrayList in project camel by apache.
the class DefaultCxfRsBindingTest method testCopyProtocolHeader.
@Test
public void testCopyProtocolHeader() {
DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
Message camelMessage = new DefaultMessage();
org.apache.cxf.message.Message cxfMessage = new MessageImpl();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("emptyList", Collections.EMPTY_LIST);
headers.put("zeroSizeList", new ArrayList<String>(0));
cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange);
assertNull("We should get nothing here", camelMessage.getHeader("emptyList"));
assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList"));
}
Aggregations