SOAPMessage writeTo without attachment

I am using SOAPMessage.writeTo (OutputStream) to log web service messages. The problem is that it also records attachments. This space takes up a lot of space, and binary attachments are not readable. Is there a way to register a message without attachments, for example. shell?

There must be a better solution than this.

ByteArrayOutputStream out = new ByteArrayOutputStream(); message.writeTo(out); StringBuilder builder = new StringBuilder(out.toString()); int indexOfAttachment = builder.indexOf("------="); if (indexOfAttachment != -1) { return builder.substring(0, indexOfAttachment); } return builder.toString(); 

Message example

 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header /> <S:Body> <ns2:wsGetObjectByIDResponse xmlns:ns2="http://xxx.com/" xmlns:ns3="http://yyy.com/"> <return> <serviceResponse status="OK" /> <contentData formatName="jpeg_lres" objectContent="cid: e677f02c-002a-4c2c-8fd9-a3acdba5ad11@example.jaxws.sun.com " objectName="Smlouva1.jpg" /> </return> </ns2:wsGetObjectByIDResponse> </S:Body> </S:Envelope> ------=_Part_9_-806948376.1352979403086 Content-Type: image/jpeg Content-ID: < e677f02c-002a-4c2c-8fd9-a3acdba5ad11@example.jaxws.sun.com > Content-Transfer-Encoding: binary     \x00JFIF\x00\x00 \x00 \x00\x00  \x00C\x00 
+4
source share
2 answers

There is actually a way to make this perhaps cleaner.

Here is my code:

 // Get the Envelope Source Source src = message.getSOAPPart().getContent() ; // Transform the Source into a StreamResult to get the XML Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "no"); StreamResult result = new StreamResult(new StringWriter()); transformer.transform(src, result); String xmlString = result.getWriter().toString(); 

Then you can register xmlString, this only matches part of the envelope.

+2
source

You can use this link to find your answer. http://ws.apache.org/axiom/quickstart-samples.html Read the Recording MTOM Messages Without Integrated Optimized Binary Data section.

0
source

Source: https://habr.com/ru/post/1446223/


All Articles