use of java.util.List in project camel by apache.
the class SimpleCxfRsBinding method bindHeadersFromSubresourceLocators.
/**
* Transfers path parameters from the full path (including ancestor subresource locators) into Camel IN Message Headers.
*/
@SuppressWarnings("unchecked")
protected void bindHeadersFromSubresourceLocators(Exchange cxfExchange, org.apache.camel.Exchange camelExchange) {
MultivaluedMap<String, String> pathParams = (MultivaluedMap<String, String>) cxfExchange.getInMessage().get(URITemplate.TEMPLATE_PARAMETERS);
// return immediately if we have no path parameters
if (pathParams == null || (pathParams.size() == 1 && pathParams.containsKey(URITemplate.FINAL_MATCH_GROUP))) {
return;
}
Message m = camelExchange.getIn();
for (Entry<String, List<String>> entry : pathParams.entrySet()) {
// skip over the FINAL_MATCH_GROUP which stores the entire path
if (URITemplate.FINAL_MATCH_GROUP.equals(entry.getKey())) {
continue;
}
m.setHeader(entry.getKey(), entry.getValue().get(0));
}
}
use of java.util.List in project camel by apache.
the class CxfConsumerWithTryCatchTest method createRouteBuilder.
// START SNIPPET: example
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(SIMPLE_ENDPOINT_URI).choice().when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_OPERATION)).process(new Processor() {
public void process(final Exchange exchange) {
Message in = exchange.getIn();
// Get the parameter list
List<?> parameter = in.getBody(List.class);
// Get the operation name
String operation = (String) in.getHeader(CxfConstants.OPERATION_NAME);
Object result = operation + " " + (String) parameter.get(0);
// Put the result back
exchange.getOut().setBody(result);
}
}).when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_BOOLEAN_OPERATION)).doTry().process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new IllegalStateException();
}
}).doCatch(IllegalStateException.class).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
// Get the parameter list
List<?> parameter = in.getBody(List.class);
// Put the result back
exchange.getOut().setBody(parameter.get(0));
}
}).end();
}
};
}
use of java.util.List in project camel by apache.
the class DefaultCxfBindingTest method testPopupalteExchangeFromCxfResponse.
@Test
public void testPopupalteExchangeFromCxfResponse() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
Map<String, Object> responseContext = new HashMap<String, Object>();
responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
headers.put("Content-Length", Arrays.asList("241"));
responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
cxfExchange.setInMessage(cxfMessage);
Set<Attachment> attachments = new HashSet<Attachment>();
AttachmentImpl attachment = new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml")));
attachment.setHeader("additional-header", "value 1");
attachments.add(attachment);
cxfMessage.setAttachments(attachments);
cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);
Map<String, Object> camelHeaders = exchange.getOut().getHeaders();
assertNotNull(camelHeaders);
assertEquals(responseContext, camelHeaders.get(Client.RESPONSE_CONTEXT));
Map<String, org.apache.camel.Attachment> camelAttachments = exchange.getOut().getAttachmentObjects();
assertNotNull(camelAttachments);
assertNotNull(camelAttachments.get("att-1"));
assertEquals("value 1", camelAttachments.get("att-1").getHeader("additional-header"));
}
use of java.util.List 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.List 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
}
};
}
Aggregations