[ 
https://issues.apache.org/jira/browse/CXF-6190?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14271105#comment-14271105
 ] 

Zdeněk Obst commented on CXF-6190:
----------------------------------

You are not correct. I had same thought as you in first place but
ThreadLocalHttpServletRequest does NOT implement HttpServletRequest.
It is only a "holder" class (it has HttpServletRequest only as a generic type).

While ThreadLocalHttpServletRequest is part of CXF I think it has to do 
something with CXF.
And as I sad, there is no way to check what 'req' is because it never gets 
called. Look at InjectionUtils.injectThroughMethod. The call is made via 
reflection. So it tries to call that setRequest method (from correct package, 
correct method) but it passes parameterValue that ThreadLocalHttpServletRequest 
- and this reflection call, of course, fails. Because it expects 
HttpServletRequest as a parameter and not that ThreadLoacal one.

> HttpServletRequest injection via Context in setter
> --------------------------------------------------
>
>                 Key: CXF-6190
>                 URL: https://issues.apache.org/jira/browse/CXF-6190
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.3
>            Reporter: Zdeněk Obst
>
> 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):
> {code:java}
>     var req : HttpServletRequest? = null
>     Context
>     fun setRequest(req : HttpServletRequest) {
>         this.req = req
>     }
> {code}
> 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



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to