Realized that https://issues.jboss.org/browse/RESTEASY-233
<https://issues.jboss.org/browse/RESTEASY-233>  fixed it on the server
side only and not on the client-side. I have, for now, to keep my
project moving forward, applied a fix on top of
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor using
apache common's DefferedFileOutputStream
(http://commons.apache.org/io/apidocs/org/apache/commons/io/output/Defer
redFileOutputStream.html). 

If there is interest, I would be more than happy to share the fix.

 

Thank you,

Sandeep.

 

From: Sandeep Tikoo [mailto:sti...@digitalriver.com] 
Sent: Tuesday, May 15, 2012 6:31 PM
To: resteasy-users@lists.sourceforge.net
Subject: Re: [Resteasy-users] FileUpload with big files failing
withOutOfMemory Error

 

Hi,

 

I am using RestEasy on the client side (version 2.2.1.GA) and trying to
upload a huge file and I get a OutOfMemory Error:

            

Caused by: java.lang.OutOfMemoryError: Java heap space

            at java.util.Arrays.copyOf(Arrays.java:2786)

            at
java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:71)

            at
org.jboss.resteasy.plugins.providers.multipart.HeaderFlushedOutputStream
.write(HeaderFlushedOutputStream.java:56)

            at
org.jboss.resteasy.plugins.providers.InputStreamProvider.writeTo(InputSt
reamProvider.java:60)

            at
org.jboss.resteasy.plugins.providers.InputStreamProvider.writeTo(InputSt
reamProvider.java:22)

            at
org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.w
ritePart(AbstractMultipartWriter.java:62)

            at
org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartFormData
Writer.writeParts(AbstractMultipartFormDataWriter.java:32)

            at
org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.w
rite(AbstractMultipartWriter.java:33)

            at
org.jboss.resteasy.plugins.providers.multipart.MultipartFormAnnotationWr
iter.writeTo(MultipartFormAnnotationWriter.java:78)

            at
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.procee
d(MessageBodyWriterContextImpl.java:117)

            at
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor
.write(GZIPEncodingInterceptor.java:98)

            at
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.procee
d(MessageBodyWriterContextImpl.java:123)

            at
org.jboss.resteasy.client.ClientRequest.writeRequestBody(ClientRequest.j
ava:472)

 

 

 

It seems that this issue was addressed a long time ago using mime4j:
https://issues.jboss.org/browse/RESTEASY-233
<https://issues.jboss.org/browse/RESTEASY-233> 

I do have mime4j in my classpath but not sure if there is something I
need to do differently to make this work?

 

Here is my code:

 

The JAX-RS annotated interface:

 

@Path("/resource")

public interface RestClientAPI {

    @POST

    @Path(UPDATE_PRODUCTS_ASYNC_RESOURCE)

    //@Consumes(MediaType.APPLICATION_XML)

    @Consumes(MediaType.MULTIPART_FORM_DATA)

    @Produces(MediaType.APPLICATION_XML)

    

     Response upload(@MultipartForm final LoaderMultiPartForm loader);

 

 

}

 

The MultiPartForm class:

 

public class LoaderMultiPartForm {

    

 

    @FormParam("loader")

    @PartType(MediaType.APPLICATION_XML)

    private Loader loader;

 

    @FormParam("bulkProductTypeStream")

    @PartType(MediaType.APPLICATION_OCTET_STREAM)

    private InputStream bulkProductTypeStream;

 

    public Loader getLoader() {

        return this.loader;

    }

 

    public void setLoader(Loader loader) {

        this.loader = loader;

    }

 

    public InputStream getBulkProductTypeStream() {

        return this.bulkProductTypeStream;

    }

 

    public void setBulkProductTypeStream(InputStream
bulkProductTypeStream) {

        this.bulkProductTypeStream = bulkProductTypeStream;

    }

}

 

The Call:

 

                  RestClientAPI client =
factory.getClient(CatalogResource.class);

                  Loader loader = new Loader();

                  loader.setXXX();

 

                  LoaderMultiPartForm loaderForm = new
LoaderMultiPartForm();

 

                  loaderForm.setLoader(loader);

                  hugeFileUploadStream = new BufferedInputStream(new
FileInputStream(new File("C:\\tmp\\hugeFileToUpload.txt")));

 
loaderForm.setBulkProductTypeStream(hugeFileUploadStream);

                  

                  client.upload(loaderForm);

 

 

 

 

Appreciate any help.

 

Regards,

Sandeep.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to