3

Basically I need to read the body of HttpServletRequest multiple times, based on my research I found that one of easiest way for doing that is by using ContentCachingRequestWrapper

Here is how I implemented it:

ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper((HttpServletRequest) request);

try{
    MultipartRequest multipartRequest = new MultipartRequest(requestWrapper, ImageDirecoty, 1024*1024*5);
    String test = requestWrapper.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
    System.out.print(test);
} catch(IOException e){
    System.out.println(e.getMessage());
    return;
}

FYI: I am uploading a simple file from my client to server.

Now at first it reads the request body just fine, but in the second line which I have String test = requestWrapper to read it's content and to output it to console I don't get my Ecplise console outputing me anything and I don't get any error too, I'd really appreciate if somebody tell me what am i doing wrong.

Mr.Cup
  • 31
  • 3
  • 1
    Check out the solution here http://stackoverflow.com/questions/28158826/how-to-read-a-servletinputstream-more-than-once-when-you-dont-have-control-of-t/28159475#28159475 – Palamino Sep 20 '16 at 13:12

1 Answers1

0

actually the easy est way to do it is to use(convert the response), to some kind of Pojo class, and then saving it to whatever you want. here is a link to convert it to pojo

http://www.jsonschema2pojo.org/

also you can use library's like Retrofit 2.0 to make your http calls much easier.

http://square.github.io/retrofit/

Chief Madog
  • 1,738
  • 4
  • 28
  • 55