gsakthivel
gsakthivel

Reputation: 375

javax.xml.soap.MessageFactory.createMessage call takes too long for large content

The http response content is a soap message with a 100mb content.

messageFactory.createMessage(null, responseinputstream) is taking 3 to 4 minutes, and the responseSoapMessage.getSOAPBody() takes another 4 minutes or more. After this, since I am in WildFly application server, the transaction times out.

MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
...
HttpEntity responseHttpEntity = httpResponse.getEntity();
...
InputStream responseContentStream = responseHttpEntity.getContent();
SOAPMessage responseSoapMessage = messageFactory.createMessage(null, responseContentStream);
SOAPBody responseSoapBody = responseSoapMessage.getSOAPBody();

On creating a SOAPMessage from the InputStream through MessageFactory, I wonder why it takes that long.

Could it be due to some JAR issue? I have two JARS in play: axis-1.4.jar, and saaj-impl-1.3.jar

However, while debugging, i found that the class used is SOAPMessageFactory1_2Impl from saaj-impl-1.3.jar.

Still, i could not reason out why it is taking more than 5 minutes to cross that two lines of code.

This is the SOAP XML in the response InputStream.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <ReceiveDocumentResponse xmlns="https://NAMESPACEURL">
         <ReceiveDocumentResult>
            <base64Binary>HERE IS THE JPG IMAGE CONTENT OF SIZE 100 MB OR MORE</base64Binary>
         </ReceiveDocumentResult>
      </ReceiveDocumentResponse>
   </soap:Body>
</soap:Envelope>

Please note that this method calls work reasonably good (quick) for contents less than 30 MBs.

Any tips to go about troubleshooting, Or any tips to go for an alternative approach to parse out the content, are really appreciated

Upvotes: 1

Views: 1538

Answers (1)

gsakthivel
gsakthivel

Reputation: 375

I replaced the above logic with what is below. It does take a minute or so for 100 MB content, but it works consistently.

DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 
builderFactory.setNamespaceAware(true);
DocumentBuilder domParser = null;
                    
domParser = builderFactory.newDocumentBuilder();
domDocument =  domParser.parse(responseContentStream);
NodeList elementList = domDocument.getElementsByTagName("base64Binary");
Node element = elementList.item(0);
String base64String = element.getTextContent();
byte[]  rawData= Base64.getDecoder().decode(base64String);
document.setBData(rawData);

Whatever it is...

Upvotes: 0

Related Questions