1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

JAX-RS add headers to chunked response

Discussão em 'StackOverflow' iniciado por Stack, Maio 28, 2021.

  1. Stack

    Stack Membro Participativo

    I'm having some trouble with my REST API service on my JBOSS 7.1.1 server.
    Right now I use a RESTEasy implementation and I have the following filter to add CORS headers to the response:

    @WebFilter(filterName = "HeaderFilter", urlPatterns = {"/*"})
    public class HeaderFilter implements Filter {

    public void init(FilterConfig arg0) throws ServletException{}
    public void destroy(){}

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
    {
    //Just continue the request
    filterChain.doFilter(request, response);

    //After the request add the response headers
    HttpServletResponse responseObj = (HttpServletResponse)response;
    responseObj.addHeader("Access-Control-Allow-Origin", "*");
    responseObj.addHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
    responseObj.addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length");
    }
    }


    My problem is that the server sometimes chooses to send the response in parts.
    Via the Transfer-Encoding: chunked "protocol".
    This doesn't matter and I have no problem with that but it doesn't add the CORS headers anymore when it does this. The client side of the application is now unable to use the data and I cannot figure out how to add the CORS headers to the final response.

    Do you guys know how I could fix this issue?

    EDIT: I'm using Jackson to turn my lazy loaded model into JSON by the way, so I don't think it's as easy as just setting the Content-Length.

    Continue reading...

Compartilhe esta Página