简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM