You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/04/28 13:56:41 UTC

[camel] branch camel-3.18.x updated: fix up MTOM doc for camel-cxf-soap (#9967)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new d804b634ba1 fix up MTOM doc for camel-cxf-soap (#9967)
d804b634ba1 is described below

commit d804b634ba145c09a77aa001a51777e4606b0fac
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Fri Apr 28 15:56:19 2023 +0200

    fix up MTOM doc for camel-cxf-soap (#9967)
    
    Co-authored-by: Freeman Fang <fr...@gmail.com>
---
 .../src/main/docs/cxf-component.adoc               | 126 +++++++++++----------
 1 file changed, 64 insertions(+), 62 deletions(-)

diff --git a/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc b/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
index 8011a0c58a2..915f518fc4a 100644
--- a/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
+++ b/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
@@ -915,17 +915,16 @@ possible to retrieve attachments by Camel Message API
 
 [source,java]
 --------------------------------------------
-DataHandler Message.getAttachment(String id)
+DataHandler Exchange.getIn(AttachmentMessage.class).getAttachment(String id)
 --------------------------------------------
 
-*Payload Mode:* MTOM is supported by the component. Attachments can be
+*Payload Mode:* MTOM is supported by this Mode. Attachments can be
 retrieved by Camel Message APIs mentioned above. SOAP with Attachment
 (SwA) is supported and attachments can be retrieved. SwA is
 the default (same as setting the CXF endpoint property "mtom-enabled" to
 false). 
 
 To enable MTOM, set the CXF endpoint property "mtom-enabled" to _true_.
-(I believe you can only do it with Spring.)
 
 [source,xml]
 ----
@@ -959,45 +958,45 @@ Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint",
         CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
             elements, null);
         exchange.getIn().setBody(body);
-        exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID,
+        exchange.getIn(AttachmentMessage.class).addAttachment(MtomTestHelper.REQ_PHOTO_CID,
             new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
 
-        exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID,
+        exchange.getIn(AttachmentMessage.class).addAttachment(MtomTestHelper.REQ_IMAGE_CID,
             new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
 
     }
 
 });
 
-// process response
+// process response 
 
-CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
-Assert.assertEquals(1, out.getBody().size());
+CxfPayload<SoapHeader> out = exchange.getMessage().getBody(CxfPayload.class);
+assertEquals(1, out.getBody().size());
 
-Map<String, String> ns = new HashMap<String, String>();
+Map<String, String> ns = new HashMap<>();
 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);
+Element ele = (Element) xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute,
+                XPathConstants.NODE);
 String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
 
-ele = (Element)xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute,
-                                   XPathConstants.NODE);
+ele = (Element) xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute,
+                XPathConstants.NODE);
 String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
 
-DataHandler dr = exchange.getOut().getAttachment(photoId);
-Assert.assertEquals("application/octet-stream", dr.getContentType());
-MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
+DataHandler dr = exchange.getMessage(AttachmentMessage.class).getAttachment(decodingReference(photoId));
+assertEquals("application/octet-stream", dr.getContentType());
+assertArrayEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
 
-dr = exchange.getOut().getAttachment(imageId);
-Assert.assertEquals("image/jpeg", dr.getContentType());
+dr = exchange.getMessage(AttachmentMessage.class).getAttachment(decodingReference(imageId));
+assertEquals("image/jpeg", dr.getContentType());
 
 BufferedImage image = ImageIO.read(dr.getInputStream());
-Assert.assertEquals(560, image.getWidth());
-Assert.assertEquals(300, image.getHeight());
+assertEquals(560, image.getWidth());
+assertEquals(300, image.getHeight());
 ----
 
 You can also consume a Camel message received from a CXF endpoint in
@@ -1008,49 +1007,52 @@ The https://github.com/apache/camel/blob/e818e0103490a106fa1538219f91a732ddebc56
 ----
 public static class MyProcessor implements Processor {
 
-    @SuppressWarnings("unchecked")
-    public void process(Exchange exchange) throws Exception {
-        CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);
-
-        // verify request
-        Assert.assertEquals(1, in.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 body = new XmlConverter().toDOMElement(in.getBody().get(0));
-        Element ele = (Element)xu.getValue("//ns:Detail/ns:photo/xop:Include", body,
-                                           XPathConstants.NODE);
-        String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
-        Assert.assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);
-
-        ele = (Element)xu.getValue("//ns:Detail/ns:image/xop:Include", body,
-                                           XPathConstants.NODE);
-        String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
-        Assert.assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);
-
-        DataHandler dr = exchange.getIn().getAttachment(photoId);
-        Assert.assertEquals("application/octet-stream", dr.getContentType());
-        MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
-
-        dr = exchange.getIn().getAttachment(imageId);
-        Assert.assertEquals("image/jpeg", dr.getContentType());
-        MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));
-
-        // create response
-        List<Source> elements = new ArrayList<Source>();
-        elements.add(new DOMSource(DOMUtils.readXml(new StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement()));
-        CxfPayload<SoapHeader> sbody = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
-            elements, null);
-        exchange.getOut().setBody(sbody);
-        exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID,
-            new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));
-
-        exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID,
-            new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));
+        @Override
+        @SuppressWarnings("unchecked")
+        public void process(Exchange exchange) throws Exception {
+            CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);
+
+            // verify request
+            assertEquals(1, in.getBody().size());
+
+            Map<String, String> ns = new HashMap<>();
+            ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
+            ns.put("xop", MtomTestHelper.XOP_NS);
+
+            XPathUtils xu = new XPathUtils(ns);
+            Element body = new XmlConverter().toDOMElement(in.getBody().get(0));
+            Element ele = (Element) xu.getValue("//ns:Detail/ns:photo/xop:Include", body,
+                    XPathConstants.NODE);
+            String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
+            assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);
+
+            ele = (Element) xu.getValue("//ns:Detail/ns:image/xop:Include", body,
+                    XPathConstants.NODE);
+            String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
+            assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);
+
+            DataHandler dr = exchange.getIn(AttachmentMessage.class).getAttachment(photoId);
+            assertEquals("application/octet-stream", dr.getContentType());
+            assertArrayEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
+
+            dr = exchange.getIn(AttachmentMessage.class).getAttachment(imageId);
+            assertEquals("image/jpeg", dr.getContentType());
+            assertArrayEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));
+
+            // create response
+            List<Source> elements = new ArrayList<>();
+            elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement()));
+            CxfPayload<SoapHeader> sbody = new CxfPayload<>(
+                    new ArrayList<SoapHeader>(),
+                    elements, null);
+            exchange.getMessage().setBody(sbody);
+            exchange.getMessage(AttachmentMessage.class).addAttachment(MtomTestHelper.RESP_PHOTO_CID,
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));
+
+            exchange.getMessage(AttachmentMessage.class).addAttachment(MtomTestHelper.RESP_IMAGE_CID,
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));
 
+        }
     }
 }
 ----