Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Web Service HttpServletRequestWrapper Issue: IllegalStateException
    primarykey
    data
    text
    <p>I am currently developing a RESTful Webservice in Java using the Jersey library.</p> <p>For security reasons, we want a custom authentication similar to Amazons Simple Storage Service. This requires, however, that I calculate an MD5 hash of the body (if there is any) to authenticate the request.</p> <p>So far, I have used a custom Authenticator and Realm and plugged them into my context. Upon trying to calculate the hash I first used the request itself resulting in an IllegalStateException, since the body can only be read once.</p> <p>After investigating the problem I tried to wrap the request inside a HttpServletRequestWrapper but hasn't been successful so far.</p> <p>I am basically using a wrapper like the one shown here: <a href="http://forums.oracle.com/forums/thread.jspa?threadID=2156814&amp;tstart=0" rel="nofollow">http://forums.oracle.com/forums/thread.jspa?threadID=2156814&amp;tstart=0</a></p> <p>Inside my realm, where I do the authentication, I am first creating the wrapper like so:</p> <pre><code>MyRequestWrapper requestWrapper = new MyRequestWrapper(request); </code></pre> <p>then I am calculating the MD5 using the requestWrapper and finally forwarding it</p> <pre><code>request.getRequestDispatcher("/*").forward(requestWrapper, response); </code></pre> <p>The processing works fine but I get an error like this after that:</p> <pre><code>Servlet.service() for servlet Jersey REST Service threw exception java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407) at com.sun.jersey.spi.container.servlet.WebComponent$Writer.finish(WebComponent.java:285) at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241) </code></pre> <p>Note that there is no mentioning of the getReader or getInputStream being called before (like I got without using any wrapper at all).</p> <p>Now I am sure I am doing something wrong here but I really don't know much about this and would be really glad if someone could help me out here :)</p> <p>Best Regards, Lukas</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload