Asutosh Rana
Asutosh Rana

Reputation: 64

Writing SOAP XML response to file

I am trying to access a SOAP service to get data from a URL. I have configured the SOAP service successfully. I am running the following methods for getting response from the SOAP service

soapResponse = soapConnection.call(SoapMsg, endPoint);
soapResponse.writeTo(fileName); 

But I get OutOfMemory Exception while getting the response

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3236) ~[na:1.8.0_131]
    at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118) ~[na:1.8.0_131]
    at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93) ~[na:1.8.0_131]
    at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153) ~[na:1.8.0_131]
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.readFully(HttpSOAPConnection.java:553) ~[na:1.8.0_131]
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:318) ~[na:1.8.0_131]
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:145) ~[na:1.8.0_131]

Hence I want to write to file by breaking the response into smaller chunks before the whole response is retrieved. Any idea how to configure it in this manner?

Thanks in advance.

Upvotes: 0

Views: 1315

Answers (1)

Daniel Przybylowski
Daniel Przybylowski

Reputation: 116

you might have to increase heap memory Increase heap size in Java

or try streaming the response.

connection.call(SoapMsg, endPoint).writeTo( new FileOutputStream( new File(fileName) ) );

Not sure if this one will work thought, as I usually work with rest API's.

Perhaps you could try reducing the amount of data returned by updating the SoapMsg. Maybe pagination is an option.

Upvotes: 2

Related Questions