use of org.apache.cxf.attachment.AttachmentImpl in project camel by apache.
the class DefaultCxfBinding method populateCxfRequestFromExchange.
// CxfBinding Methods
// -------------------------------------------------------------------------
/**
* This method is called by {@link CxfProducer#process(Exchange)}. It populates
* the CXF exchange and invocation context (i.e. request/response) contexts, it
* but does not create and populate a CXF message as a ClientImpl's invoke method
* will create a new CXF Message. That method will put all properties from the
* CXF exchange and request context to the CXF message.
*/
public void populateCxfRequestFromExchange(org.apache.cxf.message.Exchange cxfExchange, Exchange camelExchange, Map<String, Object> requestContext) {
// propagate request context
Map<String, Object> camelHeaders = camelExchange.getIn().getHeaders();
extractInvocationContextFromCamel(camelExchange, camelHeaders, requestContext, Client.REQUEST_CONTEXT);
// propagate headers
propagateHeadersFromCamelToCxf(camelExchange, camelHeaders, cxfExchange, requestContext);
String overrideAddress = camelExchange.getIn().getHeader(Exchange.DESTINATION_OVERRIDE_URL, String.class);
if (overrideAddress != null) {
LOG.trace("Client address is overridden by header '{}' to value '{}'", Exchange.DESTINATION_OVERRIDE_URL, overrideAddress);
requestContext.put(Message.ENDPOINT_ADDRESS, overrideAddress);
}
// propagate attachments
Set<Attachment> attachments = null;
boolean isXop = Boolean.valueOf(camelExchange.getProperty(Message.MTOM_ENABLED, String.class));
DataFormat dataFormat = camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class);
// already has the attachment information
if (!DataFormat.CXF_MESSAGE.equals(dataFormat)) {
for (Map.Entry<String, org.apache.camel.Attachment> entry : camelExchange.getIn().getAttachmentObjects().entrySet()) {
if (attachments == null) {
attachments = new HashSet<Attachment>();
}
AttachmentImpl attachment = new AttachmentImpl(entry.getKey());
org.apache.camel.Attachment camelAttachment = entry.getValue();
attachment.setDataHandler(camelAttachment.getDataHandler());
for (String name : camelAttachment.getHeaderNames()) {
attachment.setHeader(name, camelAttachment.getHeader(name));
}
attachment.setXOP(isXop);
attachments.add(attachment);
}
}
if (attachments != null) {
requestContext.put(CxfConstants.CAMEL_CXF_ATTACHMENTS, attachments);
}
}
use of org.apache.cxf.attachment.AttachmentImpl 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 org.apache.cxf.attachment.AttachmentImpl in project cxf by apache.
the class MustUnderstandInterceptorTest method prepareSoapMessage.
private void prepareSoapMessage(String payloadFileName) throws Exception {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(payloadFileName), "Application/xop+xml");
String cid = AttachmentUtil.createContentID("http://cxf.apache.org");
soapMessage.setContent(Attachment.class, new AttachmentImpl(cid, new DataHandler(bads)));
soapMessage.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(bads.getInputStream()));
}
use of org.apache.cxf.attachment.AttachmentImpl in project cxf by apache.
the class ReadHeaderInterceptorTest method prepareSoapMessage.
private void prepareSoapMessage(String message) throws IOException {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(message), "Application/xop+xml");
String cid = AttachmentUtil.createContentID("http://cxf.apache.org");
soapMessage.setContent(Attachment.class, new AttachmentImpl(cid, new DataHandler(bads)));
soapMessage.setContent(InputStream.class, bads.getInputStream());
}
use of org.apache.cxf.attachment.AttachmentImpl in project cxf by apache.
the class JAXBAttachmentMarshaller method addSwaRefAttachment.
@Override
public String addSwaRefAttachment(DataHandler handler) {
String id = UUID.randomUUID() + "@apache.org";
AttachmentImpl att = new AttachmentImpl(id, handler);
att.setXOP(false);
atts.add(att);
return id;
}
Aggregations