Note that there are some explanatory texts on larger screens.

plurals
  1. POOut of memory exception while retrieving large file using SOAP webservice
    primarykey
    data
    text
    <p>I'm struggling to read a large file transmitted through a SOAP based web service. The client code is failing with Out of memory exception. I'm using MTOM to send the binary data, hoping that would be able to take care of transmitting and reading large file. The file size in question is 750mb. I'm using apache cxf. Here's the web services endpoint implentation.</p> <pre><code> @MTOM @WebService(endpointInterface = "com.test.contentservice.service.IContentService") @BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING) public class ContentServiceImpl implements IContentService { @Override public ContentResponse getFile(ContentRequest req) { ContentResponse res = new ContentResponse(); try { File file = this.contentManager.getFile(req); DataSource source = new FileDataSource(file); DataHandler dataHandler = new DataHandler(source); res.setFileData(dataHandler); res.setFileName(file.getName()); } catch (Exception ex) { } return res; } </code></pre> <p>Spring entry </p> <pre><code> &lt;jaxws:endpoint id="contentService" implementor="#contentServiceImpl" address="/contentservice"&gt; &lt;jaxws:dataBinding&gt; &lt;bean class="org.apache.cxf.jaxb.JAXBDataBinding"&gt; &lt;property name="marshallerProperties"&gt; &lt;map&gt; &lt;entry&gt; &lt;key&gt; &lt;value&gt;jaxb.encoding&lt;/value&gt; &lt;/key&gt; &lt;value&gt;UTF-8&lt;/value&gt; &lt;/entry&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/jaxws:dataBinding&gt; &lt;jaxws:properties&gt; &lt;entry key="mtom-enabled" value="true" /&gt; &lt;/jaxws:properties&gt; &lt;/jaxws:endpoint&gt; </code></pre> <p>As you can notice, "mtom-enabled" is turned on.</p> <p>The client code is generated using cxf wsdl2java tool. Here's a sample client code</p> <pre><code> ContentResponse res = new ContentResponse(); try{ res = getRegisterPort().getFile(req); DataHandler dataHandler = res.getFileData(); if(dataHandler!=null){ final InputStream in = dataHandler.getInputStream(); byte[] bytes = IOUtils.toByteArray(in); } }catch (Exception ex) { LOGGER.error("Error in invoking getContent service",ex); } </code></pre> <p>Here's the response object</p> <pre><code> @XmlAccessorType( XmlAccessType.FIELD ) public class ContentResponse extends ContentServiceResponseBase { private String content; private String source; private String fileName; @XmlMimeType("application/octet-stream") private DataHandler fileData; // Getter / Setter ... } </code></pre> <p>I'm setting the mtom at the client code level as well</p> <p><code><pre> final BindingProvider bpAdmin = (BindingProvider) port; bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, curlUrl); SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding(); binding.setMTOMEnabled(true); </code></pre></p> <p>jvm entry is as follows :</p> <pre><code> java -Xms64m -Xmx6144m </code></pre> <p>And the exception : <code><pre> Exception in thread "taskExecutor-12" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2882) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515) at java.lang.StringBuilder.append(StringBuilder.java:189) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleCharacters(StAXStreamConnector.java:312) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:349) at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:109) at com.sun.xml.internal.bind.api.Bridge.unmarshal(Bridge.java:222) at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:514) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78) at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107) at $Proxy33.getFile(Unknown Source) </code></pre></p> <p>Not sure what I'm missing here, any pointer will be highly appreciated.</p> <ul> <li>Thanks</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload