3 Replies Latest reply on Apr 30, 2014 7:55 AM by Jean-Frederic Clere

    How to append trailer headers with @WebServlet?

    Rick-Rainer Ludwig Newbie

      We need to send large streams over the net via HTTP and we need to handle connection interrupts. We want to implement this via


      Transport-Encoding: chunked

      Trailer: Content-MD5


      as trailing header. The stream is send to the client and beside the sending, we use a stream to calculate the MD5 sum for the stream. The client shall be able to check the presence of the MD5 sum and the value of the MD5 sum to check for a complete and consistent stream.


      Can this be implemented with @WebServlet? The code is like that one:



      public class MyServlet extends HttpServlet {

          public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

              response.setHeader(HttpHeaderNames.TRAILER, HttpHeaderNames.CONTENT_MD5);



              ServletOutputStream outputStream = response.getOutputStream();

              /* Put some stuff into the stream with MD5 sum calculation... */


              response.setHeader(HttpHeaderNames.CONTENT_MD5, "the calculated MD5 sum");




      I have a response where we can put our content into the stream., but what do I need to do to add trailer headers? The code above does not work, because setHeader checks for a commit and ignores the request, but the used implementation of Tomcat included in JBoss 7.1.1 (the version we use and btw. what version of Tomcat is it?) shall be compatible with HTTP/1.1, but it seems not to be complete, does it? Is there a way to add trailer headers in another way? Is it possible with Resteasy via REST interface?