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

HttpServletRequest injection via Context in setter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 3.0.3
    • NeedMoreInfo
    • JAX-RS
    • None
    • Unknown

    Description

      I'm trying to inject HttpServletRequest to my JAX-RS resource via @Context annotation. It works fine if I inject it via method parameter. But I don't want to "mess" my interfaces with that so I'd like to inject it via setter.

      I use this simple method (I'm using Kotlin but I the issue should be the same for Java):

          var req : HttpServletRequest? = null
      
          Context
          fun setRequest(req : HttpServletRequest) {
              this.req = req
          }
      

      The thing is, that the setter is called via reflection in org.apache.cxf.jaxrs.utils.InjectionUtils in method injectThroughMethod. The method name is correct but as parameter value is instance of ThreadLocalHttpServletRequest which clearly is not HttpServletRequest (it is not inherited class) so this gets thrown:

      java.lang.IllegalArgumentException: object is not an instance of declaring class

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            d1x Zdeněk Obst
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: