Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4986

jax-rs2 request filter is unable to modify request header by adding a new header

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.7.2
    • 2.7.5, 3.0.0-milestone1
    • JAX-RS
    • None
    • cxf on tomcat

    • Unknown

    Description

      I have a filter implementation as follows

      @Provider
      public class AuthSessionFilter implements ContainerRequestFilter {
      public AuthSessionFilter() {
      }

      @Override
      public void filter(ContainerRequestContext requestContext) throws IOException {
      //another @Prematching filter is setting this session id so it is definitely not null
      Object sessionId = requestContext.getProperty("sessionId");
      if (sessionId == null || GeneralUtils.isNullOrBlank(sessionId + ""))

      { requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED) .entity("missing sessionId").build()); }

      //this line gets invoked without problems, however, the added header is not available from the resource class
      requestContext.getHeaders().putSingle("sessionId", sessionId+"");
      }
      }

      The line requestContext.getHeaders().putSingle("sessionId", sessionId+""); is not making the added sessionId header available when trying to obtain it from my resource. getHeaders() is supposed to return a mutable map in accordance with the spec, but its implementation 'ContainerRequestContextImpl' is returning a readonly map instead. it returning:

      return new MetadataMap<String, String>(
      (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS), false, true, true);

      where it is passing 'true' for the readonly parameter.

      in my resource, I am trying to obtain the header using

      public Response doSomething(UriInfo uriInfo, HttpServletRequest request) {
      //this is always null even though it shouldn't be null

      String sessionId = request.getHeader("sessionId");
      }

      Attachments

        1. bug4986.zip
          17 kB
          abdelgadiri
        2. bug4986-1.0.war
          8.28 MB
          abdelgadiri

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            abdelgadiri abdelgadiri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: