Hi Jan

I'm pretty sure now it is caused by Spring wrapping the service bean with one or more of its proxies. In cases like this the simplest option is to introduce a dedicated interface, say

public interface ContextAware {

   @Context
   public void setUriInfo(UriInfo ui);
}

and then do

class RoleControllerImpl implements ContextAware {

   // note, no @Context on the field
   private UriInfo ui;

   public void setUriInfo(UriInfo ui) {
       this.ui = ui;
   }
}

it will most likely fix the problem, can you add an interface like ContextAware and try again please ? In JAX-WS one can refer to the actual implementation class to avoid Spring AOP related injection issues, perhaps we can get that supported too, but having a dedicated interface for getting the contexts injected should also work

Thanks, Sergey


On 21/11/12 13:13, janb wrote:
Hi Sergey,

as far as I can see, Security Manager is actually disabled.
I tried to inject my UriInfo via a setter method (with a @Context annotation) 
and this fails likewise:

The exception occurs in Line 263 of InjectionUtils:

261:    try {
262:        Method methodToInvoke = checkProxy(method, requestObject);
263:        methodToInvoke.invoke(requestObject, new Object[]{parameterValue});
264:    } catch (IllegalAccessException ex) {
265:        reportServerError("METHOD_ACCESS_FAILURE", method.getName());
266:    } catch (Exception ex) {
267:        reportServerError("METHOD_INJECTION_FAILURE", method.getName());
268:    }

Since the exception is catched and not forwarded here is the root exception:

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

Could the ThreadLocal context be responsible for this exception?

Here is the content of all involved variables:

methodToInvoke:
public void 
org.apache.syncope.core.rest.controller.RoleControllerImpl.setUriInfo(javax.ws.rs.core.UriInfo)

requestObject:
org.apache.syncope.core.rest.controller.RoleControllerImpl@58276cfe

parameterValue:
org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo@3b5e4d1c

I use Spring security in my webapplication (if this is of any interest here)

I could also checkin my current development branch of syncope, even thou it is 
not stable. If you like you could checkout this branch and investigate 
directly. Would that help?

Best regards.
Jan

From: Sergey Beryozkin-5 [via CXF] 
[mailto:[email protected]]
Sent: Mittwoch, 21. November 2012 13:13
To: Jan Bernhardt
Subject: Re: IllegalArgumentException for UriInfo context injection

Hi Jan
On 21/11/12 09:09, janb wrote:

Hi Sergey,

I tried to set the required permissions to my webapp, but I still get the same 
error message.

First I added this to my catalina.policy file:

grant codeBase 
"file:${catalina.home}/webapps/syncope/WEB-INF/lib/cxf-rt-frontend-jaxrs-2.7.0.jar"
 {
      permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

After no success, I tried to set my permissions as low as possible, but still 
no success:

grant codeBase "file:${catalina.home}/webapps/syncope/WEB-INF/lib/-" {
      permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
                  permission java.security.AllPermission;
};

Can you please confirm that you actually have SecurityManager activated
in this Tomcat instance ? If yes then I will experiment on my end too...


I did not change the default spring scope for my service class, so it should be 
singleton. Here is my jaxrs:server code:

    <jaxrs:server id="restContainer" address="/">
      <jaxrs:serviceBeans>
        <bean class="org.apache.syncope.core.rest.controller.RoleControllerImpl" 
/>
      </jaxrs:serviceBeans>
      <jaxrs:providers>
        <ref bean="jaxbProvider" />
        <ref bean="jsonProvider" />
        <bean class="org.apache.syncope.exceptions.RestHttpStatusCodeMapper"/>
      </jaxrs:providers>
      <jaxrs:extensionMappings>
        <entry key="json" value="application/json;charset=UTF-8" />
        <entry key="xml" value="application/xml;charset=UTF-8" />
        <entry key="html" value="text/html;charset=UTF-8" />
      </jaxrs:extensionMappings>
    </jaxrs:server>


Yes, this is a singleton, I was thinking may be it was some advanced
Spring scope which was leading to the field becoming somehow
unaccessible due to the proxification, but it does not seem to be the
case...

Cheers, Sergey

Best regards.
Jan

From: Sergey Beryozkin-5 [via CXF] [mailto:[hidden 
email]</user/SendEmail.jtp?type=node&node=5718906&i=0>]
Sent: Dienstag, 20. November 2012 17:50
To: Jan Bernhardt
Subject: Re: IllegalArgumentException for UriInfo context injection

Hi Jan
On 20/11/12 15:42, janb wrote:

Hi,

I'm trying to use UriInfo within my REST webservice to create a dynamic
response URL. If I use @Context UriInfo uriInfo within my method signature
everything is working fine. But since I don't like to mix my business
service interface with REST specific arguments, I would rather like to use
UriInfo as a field with my service class. I tried a couple of CXF systest to
learn how this can be done. I even created my own sample app. All is working
well. But when I try to do the same thing in my much more complex
webapplication I cannot deploy my Service any longer, due to an
IllegalArgumentException caused by injecting my UriInfo field.... :(
I debugged CXF code, to find the place where the injection happens
(org.apache.cxf.jaxrs.utils.InjectionUtils, Line 167, Version 2.7.0), and
all the parameters look OK to me, but still I get an
IllegalArgumentException. I don't know how to solve this issue. Does someone
else knows how to investigate this issue any further?

I can see from the stack trace that
java.security.AccessController.doPrivileged is in the frame,

is SecurityManager enabled ? If yes then may be
http://cxf.apache.org/docs/secure-jax-rs-services.html#SecureJAX-RSServices-NoteaboutSecurityManager

will help ?

You can also inject "UriInfo" as a method parameter, example
"@GET Data get(@Context UriInfo ui, @PathParam("id") long id)",
but the field injection should also work...

The actual service bean, what Spring scope it is in ?

Cheers, Sergey

Best regads.
Jan

Here is my Tomcat log:

20.11.2012 15:35:55 org.apache.catalina.core.StandardContext listenerStart
SCHWERWIEGEND: Exception sending context initialized event to listener
instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'restContainer': Invocation of init method failed; nested
exception is org.apache.cxf.service.factory.ServiceConstructionException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
at
org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)
at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:201)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 26 more
Caused by: java.lang.IllegalArgumentException: Can not set
javax.ws.rs.core.UriInfo field
org.apache.syncope.core.rest.controller.RoleControllerImpl.uriInfo to
$Proxy98
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at
sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
at java.lang.reflect.Field.set(Field.java:657)
at org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:167)
at java.security.AccessController.doPrivileged(Native Method)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:163)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:921)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:365)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:391)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:151)
... 33 more
20.11.2012 15:35:55 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext



--
View this message in context: 
http://cxf.547215.n5.nabble.com/IllegalArgumentException-for-UriInfo-context-injection-tp5718839.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

________________________________
If you reply to this email, your message will be added to the discussion below:

NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://cxf.547215.n5.nabble.com/IllegalArgumentException-for-UriInfo-context-injection-tp5718839p5718895.html
Sent from the cxf-user mailing list archive at Nabble.com.


________________________________
If you reply to this email, your message will be added to the discussion below:
http://cxf.547215.n5.nabble.com/IllegalArgumentException-for-UriInfo-context-injection-tp5718839p5718906.html
To unsubscribe from IllegalArgumentException for UriInfo context injection, click 
here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5718839&code=amJlcm5oYXJkdEB0YWxlbmQuY29tfDU3MTg4Mzl8LTEzMDQ4ODk1MjM=>.
NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://cxf.547215.n5.nabble.com/IllegalArgumentException-for-UriInfo-context-injection-tp5718839p5718907.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to