cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zdeněk Obst (JIRA) <>
Subject [jira] [Commented] (CXF-6190) HttpServletRequest injection via Context in setter
Date Fri, 09 Jan 2015 08:32:35 GMT


Zdeněk Obst commented on CXF-6190:

The issue is that injection via setter is not working and throws that IllegalArgumentException.
You are right that it happens during runtime, this is what happens:

public static void injectThroughMethod(Object requestObject,
                                               Method method,
                                               Object parameterValue, // !!! This is ThreadLocalHttpServletRequest
                                               Message inMessage) {
        try {
            Method methodToInvoke = checkProxy(method, requestObject);
            methodToInvoke.invoke(requestObject, new Object[]{parameterValue}); // !!! This
fails as you cannot call setRequest(ThreadLocalHttpServletRequest)
        } catch (IllegalAccessException ex) {
            reportServerError("METHOD_ACCESS_FAILURE", method.getName());
        } catch (InvocationTargetException ex) {
            Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage);
            if (r != null) {
                inMessage.getExchange().put(Response.class, r);
                throw new WebApplicationException();
            reportServerError("METHOD_ACCESS_FAILURE", method.getName());
        } catch (Exception ex) {
            reportServerError("METHOD_INJECTION_FAILURE", method.getName());

> HttpServletRequest injection via Context in setter
> --------------------------------------------------
>                 Key: CXF-6190
>                 URL:
>             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

View raw message