cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bud <chrisb.business.em...@gmail.com>
Subject Re: JAXRS Attachment InputStream empty for > 300 KB Files
Date Wed, 27 Apr 2016 11:11:31 GMT
Hi Sergey,

OK that did it!! My mistake, I overlooked that.  I notice the cxf logger
still cuts off the file contents but when I spit out the input stream I see
the entire file contents.

Now, is this part of a known issue? Seems like something CXF does behind
the scenes that's not reading the entire stream.. Do I have to parse the
stream myself or is there internal cxf calls I can use like
AttachmentBuilder?  I have multiple methods for uploading different file
types, with different parameters, ideally I won't have to parse each method
individually.

Thanks for everything!!
Chris

On Wed, Apr 27, 2016 at 6:44 AM, Sergey Beryozkin <sberyozkin@gmail.com>
wrote:

> Hi
>
> Can you please remove @Multipart which is bound right now to InputStream
> (as I did suggest) and retry ?
>
> Cheers, Sergey
>
> On 27/04/16 11:35, Chris Bud wrote:
>
>> Hi Sergey,
>>
>> Regarding the side note, I've tried many approaches, that was the last
>> attempt before turning to the mailing list. I did try
>> attachment.getObject()
>>
>> I get similar results when I changed my method to accept InputStream, I
>> only read the first parameter.  I'll attach files of the inbound message
>> my service receives, and my firebug output.  I changed my method as you
>> suggested.
>>
>> @Consumes(MediaType.MULTIPART_FORM_DATA)
>> @Produces(MediaType.APPLICATION_JSON)
>> public Response saveFile(
>>          @PathParam("name") String name,
>>          @Multipart InputStream body,
>>          @HeaderParam("CUSTOM-uid") String username);
>> ...
>>
>> public Response saveFile(String name, InputStream is, String username){
>> ...
>>                  try{
>> logger.info <http://logger.info
>> >("***************************************");
>> logger.info <http://logger.info
>> >("***************************************");
>>
>> logger.info <http://logger.info>("InputStream: " + is.available());
>>
>>                          BufferedReader br = null;
>>                          StringBuilder sb = new StringBuilder();
>>
>>                          String line;
>>                          try {
>>
>>                                  br = new BufferedReader(new
>> InputStreamReader(is));
>>                                  while ((line = br.readLine()) != null) {
>>                                          sb.append(line);
>>                                  }
>>
>>                          } catch (IOException e) {
>>                                  e.printStackTrace();
>>                          } finally {
>>                                  if (br != null) {
>>                                          try {
>>                                                  br.close();
>>                                          } catch (IOException e) {
>>                                                  e.printStackTrace();
>>                                          }
>>                                  }
>>                          }
>>
>> logger.info <http://logger.info>("Info: " + sb.toString());
>>
>> logger.info <http://logger.info
>> >("***************************************");
>> logger.info <http://logger.info
>> >("***************************************");
>>
>> Produces these logs
>> 2016-04-27 05:29:11,308 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] -
>> ***************************************
>> 2016-04-27 05:29:11,308 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] -
>> ***************************************
>> 2016-04-27 05:29:11,308 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] - InputStream: 4
>> 2016-04-27 05:29:11,309 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] - Info: 3304
>> 2016-04-27 05:29:11,310 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] -
>> ***************************************
>> 2016-04-27 05:29:11,310 [INFO] [http-nio-8080-exec-2]
>> [example.com.web.rs.impl.FileServiceImpl] -
>> ***************************************
>>
>> Thanks for you help!
>> Chris
>>
>> On Tue, Apr 26, 2016 at 4:24 PM, Sergey Beryozkin <sberyozkin@gmail.com
>> <mailto:sberyozkin@gmail.com>> wrote:
>>
>>     Hi
>>
>>     Can you please experiment with accepting it directly as InputStream:
>>
>>     @Consumes(MediaType.MULTIPART_FORM_DATA)
>>     > @Produces(MediaType.APPLICATION_JSON)
>>     > public Response saveFile(
>>     >        @PathParam(“name") String name,
>>      >        InputStream body,
>>     >        @HeaderParam("CUSTOM-uid") String username);
>>
>>     If the whole body is indeed available then saving this InputStream
>>     will show the complete multipart request (with the part separators,
>> etc)
>>
>>     As a side note,
>>     > for(Attachment attachment : body.getAllAttachments()) {
>>     >      … // how I get the input stream
>>     >      is = attachment.getDataHandler().getInputStream();
>>
>>     instead you can do
>>
>>     is = attachment.getObject(InputStream.class);
>>     or directly from the multipart body if a part id is known.
>>
>>     Sergey
>>
>>
>>     On 26/04/16 19:20, Chris Bud wrote:
>>
>>         Hi,
>>
>>         I'm using CXF 3.0.3, uploading files to jaxrs service from my
>>         webapp.
>>         Small files upload fine but when I use files > 300KB they're
>>         empty on my
>>         server, in my case I'm uploading an XML document containing test
>>         info for
>>         my system.  When I test for available bytes from the data
>>         handler's input
>>         stream, it's always empty. Not the case with small files, say
>> 500B.
>>         Regardless of size, the service returns a success.
>>
>>         My LoggingInInterceptor spits out a payload that is incomplete,
>>         but the
>>         POST in firebug shows the entire file contents. I feel like I'm
>>         missing
>>         some sort of config, I've read about MTOM but I don't think
>>         300KB should be
>>         a problem.... What am I missing? Thanks for helping
>>
>>         My service interface
>>         @POST
>>         @Path(“/save/{name}")
>>         @Consumes(MediaType.MULTIPART_FORM_DATA)
>>         @Produces(MediaType.APPLICATION_JSON)
>>         public Response saveFile(
>>                 @PathParam(“name") String name,
>>                 @Multipart MultipartBody body,
>>                 @HeaderParam("CUSTOM-uid") String username);
>>
>>         ...
>>         for(Attachment attachment : body.getAllAttachments()) {
>>               … // how I get the input stream
>>               is = attachment.getDataHandler().getInputStream();
>>
>>         Bean definition
>>         <jaxrs:server id=“wserver" address="/">
>>              <jaxrs:serviceBeans>
>>                 <bean class=“example.com.web.rs
>>         <http://example.com.web.rs>.impl.FileServiceImpl" />
>>                 ...
>>              </jaxrs:serviceBeans>
>>              <jaxrs:providers>
>>                 <bean
>>         class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
>>              </jaxrs:providers>
>>              <jaxrs:features>
>>                 <ref bean="logger" />
>>              </jaxrs:features>
>>
>>
>>         </jaxrs:server>
>>
>>
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message