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 <[email protected]
<mailto:[email protected]>> 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/

Reply via email to