jersey
  1. jersey
  2. JERSEY-2055

the problem when inject HttpServletRequest into Spring-managed resource's field

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2
    • Fix Version/s: backlog
    • Component/s: None
    • Labels:
      None
    • Environment:

      java 1.7

      Description

      According to the documentation https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e2030, Table 3.2. and if i remember, in jersey 1.x, the HttpServletRequest can be inject into resource's field directly. but now i only can inject the HttpServletRequest using setter method mode or resource methods mode:

       private @Context HttpServletRequest request; // this will not work
       private @Context HttpServletRequest request2; // valid via setter method
      
      @Context
      public void setRequest2(HttpServletRequest request2) {
              this.request2 = request2;
      }
      
      @Path("server")
      @POST
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public AgentConfiguration register(AgentMachine agent, @Context HttpServletRequest request) throws RemoteException
      {
         // valid in resource method.
      }
      

      My resource class declaration:

      @Path("agent")
      @Scope("request")
      @Component
      public class AgentResource
      

      i using jersey 2.2 with spring 3.x

        Activity

        Hide
        Marek Potociar added a comment -

        Moving to backlog - community contribution for the fix welcome.

        Show
        Marek Potociar added a comment - Moving to backlog - community contribution for the fix welcome.
        Hide
        schrepfler added a comment - - edited

        I think the CXF guys had the similar issue and fixed it around the 2.2.6 release
        https://issues.apache.org/jira/browse/CXF-2471
        This would allow services to have a strong response type (good for documentation) but also add header metadata like cache control, etags which can bring a lot of value to a REST API.

        Show
        schrepfler added a comment - - edited I think the CXF guys had the similar issue and fixed it around the 2.2.6 release https://issues.apache.org/jira/browse/CXF-2471 This would allow services to have a strong response type (good for documentation) but also add header metadata like cache control, etags which can bring a lot of value to a REST API.

          People

          • Assignee:
            Unassigned
            Reporter:
            wenbois2000
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: