Search in sources :

Example 6 with SoapHeader

use of org.apache.cxf.binding.soap.SoapHeader in project camel by apache.

the class CxfMessageHeadersRelayTest method buildOutOfBandHeaderList.

protected static List<Header> buildOutOfBandHeaderList(boolean invalid) throws JAXBException {
    OutofBandHeader ob = new OutofBandHeader();
    ob.setName("testOobHeader");
    ob.setValue("testOobHeaderValue");
    ob.setHdrAttribute(invalid ? "dontProcess" : "testHdrAttribute");
    SoapHeader hdr = new SoapHeader(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_REQUEST_ELEM), ob, new JAXBDataBinding(ob.getClass()));
    hdr.setMustUnderstand(invalid);
    List<Header> headers = new ArrayList<Header>();
    headers.add(hdr);
    return headers;
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) ArrayList(java.util.ArrayList) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 7 with SoapHeader

use of org.apache.cxf.binding.soap.SoapHeader in project camel by apache.

the class CxfMtomProducerPayloadModeTest method testProducer.

@SuppressWarnings("unchecked")
@Test
public void testProducer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }
    // START SNIPPET: producer
    Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            List<Source> elements = new ArrayList<Source>();
            elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement()));
            CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
            exchange.getIn().setBody(body);
            exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
            exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
        }
    });
    // process response 
    CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
    Assert.assertEquals(1, out.getBody().size());
    Map<String, String> ns = new HashMap<String, String>();
    ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
    ns.put("xop", MtomTestHelper.XOP_NS);
    XPathUtils xu = new XPathUtils(ns);
    Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
    Element ele = (Element) xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute, XPathConstants.NODE);
    // skip "cid:"
    String photoId = ele.getAttribute("href").substring(4);
    ele = (Element) xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute, XPathConstants.NODE);
    // skip "cid:"
    String imageId = ele.getAttribute("href").substring(4);
    DataHandler dr = exchange.getOut().getAttachment(decodingReference(photoId));
    Assert.assertEquals("application/octet-stream", dr.getContentType());
    MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
    dr = exchange.getOut().getAttachment(decodingReference(imageId));
    Assert.assertEquals("image/jpeg", dr.getContentType());
    BufferedImage image = ImageIO.read(dr.getInputStream());
    Assert.assertEquals(560, image.getWidth());
    Assert.assertEquals(300, image.getHeight());
// END SNIPPET: producer
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Processor(org.apache.camel.Processor) CxfPayload(org.apache.camel.component.cxf.CxfPayload) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DOMSource(javax.xml.transform.dom.DOMSource) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Source(javax.xml.transform.Source) BufferedImage(java.awt.image.BufferedImage) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter) Exchange(org.apache.camel.Exchange) XPathUtils(org.apache.cxf.helpers.XPathUtils) StringReader(java.io.StringReader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Aggregations

SoapHeader (org.apache.cxf.binding.soap.SoapHeader)7 ArrayList (java.util.ArrayList)5 Exchange (org.apache.camel.Exchange)5 Processor (org.apache.camel.Processor)5 StringReader (java.io.StringReader)4 List (java.util.List)4 Source (javax.xml.transform.Source)4 DOMSource (javax.xml.transform.dom.DOMSource)4 CxfPayload (org.apache.camel.component.cxf.CxfPayload)3 XmlConverter (org.apache.camel.converter.jaxp.XmlConverter)3 Element (org.w3c.dom.Element)3 BufferedImage (java.awt.image.BufferedImage)2 DataHandler (javax.activation.DataHandler)2 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)2 QName (javax.xml.namespace.QName)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Header (org.apache.cxf.headers.Header)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1