You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by shamikb <sh...@gmail.com> on 2013/06/19 01:24:03 UTC

Out of memory exception while retrieving large file using CXF SOAP webservice

Hi,

 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 implementation.

@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;
    }


I've turned on MTOM through spring , Spring entry :

<jaxws:endpoint id="contentService" implementor="#contentServiceImpl"
        address="/contentservice">
        <jaxws:dataBinding>
            <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
                <property name="marshallerProperties">
                    <map>
                        <entry>
                            <key>
                                <value>jaxb.encoding</value>
                            </key>
                            <value>UTF-8</value>
                        </entry>
                    </map>
                </property>
            </bean>
        </jaxws:dataBinding>
        <jaxws:properties>
            <entry key="mtom-enabled" value="true" />
        </jaxws:properties>
    </jaxws:endpoint>

The client code is generated using cxf wsdl2java tool. Here's a sample
client 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);
        }

Here's the response object

@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 ...
}

Turned on mtom in client code :

final BindingProvider bpAdmin = (BindingProvider) port;
		bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
curlUrl);
		SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding();
		binding.setMTOMEnabled(true);


jvm entry is as follows :

-Xms64m -Xmx6144m

And the exception :

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)


Not sure what I'm missing here, any pointer will be highly appreciated.

- Thanks




--
View this message in context: http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Out of memory exception while retrieving large file using CXF SOAP webservice

Posted by Ted <r6...@gmail.com>.
have you actaully checked your heap space?

-Xmx does not specify which pool the memory goes to, you're going to
need more parameters than that.

keep in mind 750mb is just the object once in memory, when you create
the soap message it may duplicate the bytes, and if it does a
base4encoding on it, it may tripple in size so you might need to
ensure your smallest memory pool is close to 3g or 4g... given it
splits the memory pools into different parts, I'm not convinced your
-Xmx6g is enough...

I must say 750mb soap payload is quite impressively large.

On 6/19/13, shamikb <sh...@gmail.com> wrote:
> Hi,
>
>  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 implementation.
>
> @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;
>     }
>
>
> I've turned on MTOM through spring , Spring entry :
>
> <jaxws:endpoint id="contentService" implementor="#contentServiceImpl"
>         address="/contentservice">
>         <jaxws:dataBinding>
>             <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>                 <property name="marshallerProperties">
>                     <map>
>                         <entry>
>                             <key>
>                                 <value>jaxb.encoding</value>
>                             </key>
>                             <value>UTF-8</value>
>                         </entry>
>                     </map>
>                 </property>
>             </bean>
>         </jaxws:dataBinding>
>         <jaxws:properties>
>             <entry key="mtom-enabled" value="true" />
>         </jaxws:properties>
>     </jaxws:endpoint>
>
> The client code is generated using cxf wsdl2java tool. Here's a sample
> client 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);
>         }
>
> Here's the response object
>
> @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 ...
> }
>
> Turned on mtom in client code :
>
> final BindingProvider bpAdmin = (BindingProvider) port;
> 		bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
> curlUrl);
> 		SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding();
> 		binding.setMTOMEnabled(true);
>
>
> jvm entry is as follows :
>
> -Xms64m -Xmx6144m
>
> And the exception :
>
> 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)
>
>
> Not sure what I'm missing here, any pointer will be highly appreciated.
>
> - Thanks
>
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Ted.

Re: Out of memory exception while retrieving large file using CXF SOAP webservice

Posted by Freeman Fang <fr...@gmail.com>.
FUSE ESB 4.3 is quite old.
Anyway, this discussion moved to FUSE forum as it's FUSE ESB kit, just for a better track, the discussion is here[1]

[1]http://fusesource.com/forums/thread.jspa?messageID=17470

-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋



On 2013-6-19, at 下午2:03, shamikb wrote:

> Thanks Dan, I'll look into the classpath. I'm using cxf with
> spring-dm in fuse 4.3 environment, not sure why would it be using JAX-WS
> underneath. In jre.properties. jdk 1.6 related APIs are all commented out.
> Also, the bundles doesn't have any reference to JAX-WS, the import
> statement in pom file
> 
> <Import-Package>
>       javax.jws,
>       javax.wsdl,
>       javax.xml.bind,
>       javax.xml.bind.annotation,
>       javax.xml.namespace,
>       javax.xml.ws,
>       META-INF.cxf,
>       META-INF.cxf.osgi,
>       org.apache.cxf.bus,
>       org.apache.cxf.bus.spring,
>       org.apache.cxf.bus.resource,
>       org.apache.cxf.configuration.spring,
>       org.apache.cxf.resource,
>       org.apache.cxf.jaxws,
>       org.apache.cxf.transport.http,
>       org.springframework.beans.factory.config,
>       *;resolution:=optional
> </Import-Package>
> 
> Thanks for the pointer again, I'll take a deeper look.
> 
> 
> On Tue, Jun 18, 2013 at 8:47 PM, Daniel Kulp [via CXF] <
> ml-node+s547215n5729469h35@n5.nabble.com> wrote:
> 
>> 
>> You aren't using CXF:
>> 
>> 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
>> 
>> That's the JAX-WS RI built into the JDK which cannot handle streaming MTOM
>> without a bunch of extra custom configuration and annotations.  Check you
>> classpath to make sure the CXF JAX-WS implementation is there.
>> 
>> 
>> Dan
>> 
>> 
>> 
>> On Jun 18, 2013, at 7:24 PM, shamikb <[hidden email]<http://user/SendEmail.jtp?type=node&node=5729469&i=0>>
>> wrote:
>> 
>>> Hi,
>>> 
>>> 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 implementation.
>>> 
>>> @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;
>>>   }
>>> 
>>> 
>>> I've turned on MTOM through spring , Spring entry :
>>> 
>>> <jaxws:endpoint id="contentService" implementor="#contentServiceImpl"
>>>       address="/contentservice">
>>>       <jaxws:dataBinding>
>>>           <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>>>               <property name="marshallerProperties">
>>>                   <map>
>>>                       <entry>
>>>                           <key>
>>>                               <value>jaxb.encoding</value>
>>>                           </key>
>>>                           <value>UTF-8</value>
>>>                       </entry>
>>>                   </map>
>>>               </property>
>>>           </bean>
>>>       </jaxws:dataBinding>
>>>       <jaxws:properties>
>>>           <entry key="mtom-enabled" value="true" />
>>>       </jaxws:properties>
>>>   </jaxws:endpoint>
>>> 
>>> The client code is generated using cxf wsdl2java tool. Here's a sample
>>> client 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);
>>>       }
>>> 
>>> Here's the response object
>>> 
>>> @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 ...
>>> }
>>> 
>>> Turned on mtom in client code :
>>> 
>>> final BindingProvider bpAdmin = (BindingProvider) port;
>>> 
>> bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
>>> curlUrl);
>>> SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding();
>>> binding.setMTOMEnabled(true);
>>> 
>>> 
>>> jvm entry is as follows :
>>> 
>>> -Xms64m -Xmx6144m
>>> 
>>> And the exception :
>>> 
>>> 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)
>>> 
>>> 
>>> Not sure what I'm missing here, any pointer will be highly appreciated.
>>> 
>>> - Thanks
>>> 
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>> http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
>> --
>> Daniel Kulp
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5729469&i=1> -
>> http://dankulp.com/blog
>> 
>> Talend Community Coder - http://coders.talend.com
>> 
>> 
>> 
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> 
>> http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463p5729469.html
>> To unsubscribe from Out of memory exception while retrieving large file
>> using CXF SOAP webservice, click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5729463&code=c2hhbWlrYkBnbWFpbC5jb218NTcyOTQ2M3w2MzMwMTIyOA==>
>> .
>> NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>> 
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463p5729474.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: Out of memory exception while retrieving large file using CXF SOAP webservice

Posted by shamikb <sh...@gmail.com>.
Thanks Dan, I'll look into the classpath. I'm using cxf with
spring-dm in fuse 4.3 environment, not sure why would it be using JAX-WS
underneath. In jre.properties. jdk 1.6 related APIs are all commented out.
Also, the bundles doesn't have any reference to JAX-WS, the import
statement in pom file

<Import-Package>
       javax.jws,
       javax.wsdl,
       javax.xml.bind,
       javax.xml.bind.annotation,
       javax.xml.namespace,
       javax.xml.ws,
       META-INF.cxf,
       META-INF.cxf.osgi,
       org.apache.cxf.bus,
       org.apache.cxf.bus.spring,
       org.apache.cxf.bus.resource,
       org.apache.cxf.configuration.spring,
       org.apache.cxf.resource,
       org.apache.cxf.jaxws,
       org.apache.cxf.transport.http,
       org.springframework.beans.factory.config,
       *;resolution:=optional
</Import-Package>

Thanks for the pointer again, I'll take a deeper look.


On Tue, Jun 18, 2013 at 8:47 PM, Daniel Kulp [via CXF] <
ml-node+s547215n5729469h35@n5.nabble.com> wrote:

>
> You aren't using CXF:
>
>  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
>
> That's the JAX-WS RI built into the JDK which cannot handle streaming MTOM
> without a bunch of extra custom configuration and annotations.  Check you
> classpath to make sure the CXF JAX-WS implementation is there.
>
>
> Dan
>
>
>
> On Jun 18, 2013, at 7:24 PM, shamikb <[hidden email]<http://user/SendEmail.jtp?type=node&node=5729469&i=0>>
> wrote:
>
> > Hi,
> >
> > 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 implementation.
> >
> > @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;
> >    }
> >
> >
> > I've turned on MTOM through spring , Spring entry :
> >
> > <jaxws:endpoint id="contentService" implementor="#contentServiceImpl"
> >        address="/contentservice">
> >        <jaxws:dataBinding>
> >            <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
> >                <property name="marshallerProperties">
> >                    <map>
> >                        <entry>
> >                            <key>
> >                                <value>jaxb.encoding</value>
> >                            </key>
> >                            <value>UTF-8</value>
> >                        </entry>
> >                    </map>
> >                </property>
> >            </bean>
> >        </jaxws:dataBinding>
> >        <jaxws:properties>
> >            <entry key="mtom-enabled" value="true" />
> >        </jaxws:properties>
> >    </jaxws:endpoint>
> >
> > The client code is generated using cxf wsdl2java tool. Here's a sample
> > client 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);
> >        }
> >
> > Here's the response object
> >
> > @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 ...
> > }
> >
> > Turned on mtom in client code :
> >
> > final BindingProvider bpAdmin = (BindingProvider) port;
> >
> bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
> > curlUrl);
> > SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding();
> > binding.setMTOMEnabled(true);
> >
> >
> > jvm entry is as follows :
> >
> > -Xms64m -Xmx6144m
> >
> > And the exception :
> >
> > 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)
> >
> >
> > Not sure what I'm missing here, any pointer will be highly appreciated.
> >
> > - Thanks
> >
> >
> >
> >
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
>
> --
> Daniel Kulp
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5729469&i=1> -
> http://dankulp.com/blog
>
> Talend Community Coder - http://coders.talend.com
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463p5729469.html
>  To unsubscribe from Out of memory exception while retrieving large file
> using CXF SOAP webservice, click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5729463&code=c2hhbWlrYkBnbWFpbC5jb218NTcyOTQ2M3w2MzMwMTIyOA==>
> .
> NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463p5729474.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Out of memory exception while retrieving large file using CXF SOAP webservice

Posted by Daniel Kulp <dk...@apache.org>.
You aren't using CXF:

 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

That's the JAX-WS RI built into the JDK which cannot handle streaming MTOM without a bunch of extra custom configuration and annotations.  Check you classpath to make sure the CXF JAX-WS implementation is there.


Dan



On Jun 18, 2013, at 7:24 PM, shamikb <sh...@gmail.com> wrote:

> Hi,
> 
> 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 implementation.
> 
> @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;
>    }
> 
> 
> I've turned on MTOM through spring , Spring entry :
> 
> <jaxws:endpoint id="contentService" implementor="#contentServiceImpl"
>        address="/contentservice">
>        <jaxws:dataBinding>
>            <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>                <property name="marshallerProperties">
>                    <map>
>                        <entry>
>                            <key>
>                                <value>jaxb.encoding</value>
>                            </key>
>                            <value>UTF-8</value>
>                        </entry>
>                    </map>
>                </property>
>            </bean>
>        </jaxws:dataBinding>
>        <jaxws:properties>
>            <entry key="mtom-enabled" value="true" />
>        </jaxws:properties>
>    </jaxws:endpoint>
> 
> The client code is generated using cxf wsdl2java tool. Here's a sample
> client 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);
>        }
> 
> Here's the response object
> 
> @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 ...
> }
> 
> Turned on mtom in client code :
> 
> final BindingProvider bpAdmin = (BindingProvider) port;
> 		bpAdmin.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
> curlUrl);
> 		SOAPBinding binding = (SOAPBinding)bpAdmin.getBinding();
> 		binding.setMTOMEnabled(true);
> 
> 
> jvm entry is as follows :
> 
> -Xms64m -Xmx6144m
> 
> And the exception :
> 
> 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)
> 
> 
> Not sure what I'm missing here, any pointer will be highly appreciated.
> 
> - Thanks
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Out-of-memory-exception-while-retrieving-large-file-using-CXF-SOAP-webservice-tp5729463.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com