cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sannabel <sanna...@ghx.com>
Subject Re: Error trying to use MessageContext with Spring Security enabled - JAX-RS
Date Wed, 17 Jun 2009 19:12:22 GMT

Okay, works now I'd forgotten to add the method to my IService Interface.

public void setMessageContext(MessageContext mc);

Seth




sannabel wrote:
> 
> Hi, I'm using CXF 2.2.2 JAX-RS, Spring 2.5.5, Spring Security 2.04, and
> Jetty.
> 
> I'm trying to use MessageContext in my JAX-RS Service Impl class.
> 
> @Produces("application/xml")
> @Path("/item/")
> public class ServiceImpl extends WebServiceBase implements IService{
> 
>     @Context
>     private org.apache.cxf.jaxrs.ext.MessageContext messageContext;
> 
>    ....
> 
> 
>     @GET
>     @Produces("text/xml")
>     @Path("vendoridsbybuyereid/")
>     @Override
>     public Response vendorIdsByBuyerEID(@QueryParam("buyerid") String id)
> throws ItemFault {
> 
> 
>         ApplicationContext ctx = Util.getSpringContext();
> 
>         try {
>             isDevUser(messageContext);
>         } catch (Exception ex) {
>             log.warn("Error", ex);
>         }
>         IItemService itemService = (IItemService)
> ctx.getBean(Constants.ITEM_SERVICE);
>         List<String> list = null;
> 
>         try {
>             list = itemService.vendorIdsByBuyerEID(id);
> 
>         } catch (Exception ex) {
>             log.error("Error trying to call service.", ex);
> 
>             throw new WebApplicationException(500);
>         }
>         return Response.ok(new StringCollection(list)).build();
>     }
> }
> <!--
> 	<global-method-security>
> 		<protect-pointcut expression="execution(*
> com.contractservice.webservice.IService.vendorIdsByBuyerEID(. .))"
> access="ROLE_ADMIN,ROLE_DEV"/>
> 		<protect-pointcut expression="execution(*
> com.contractservice.webservice.IService.mfgIdsByBuyerEID(. .))"
> access="ROLE_USER,ROLE_DEV"/>
> 
> 	</global-method-security>
> 	
> 	<http create-session="never" auto-config="false"
> 		realm="Restricted resources">
> 		<intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER,ROLE_DEV" />
> 		<http-basic />
> 		<logout />
> 	</http>
> -->
> 
> It works fine when I have the security pointcuts commented out, but when I
> include them I get the following error:
> 
> Thanks,
> Seth
> 
> ERROR [main] (ContextLoader.java:215) - Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean with name 'service': Invocation of init method failed; nested
> exception is org.apache.cxf.service.factory.ServiceConstructionException
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
>         at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
>         at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
>         at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
>         at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
>         at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
>         at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
>         at
> com.contractservice.test.util.SessionSetupUtil.getInstance(SessionSetupUtil.java:47)
>         at
> com.contractservice.test.BaseServletTest.setUp(BaseServletTest.java:39)
>         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.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
>         at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
>         at
> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>         at
> org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>         at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>         at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>         at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>         at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>         at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>         at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>         at
> org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
>         at org.junit.runners.Suite.access$000(Suite.java:26)
>         at org.junit.runners.Suite$1.run(Suite.java:93)
>         at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>         at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>         at org.junit.runners.Suite.run(Suite.java:91)
>         at
> org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
>         at org.junit.runners.Suite.access$000(Suite.java:26)
>         at org.junit.runners.Suite$1.run(Suite.java:93)
>         at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>         at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>         at org.junit.runners.Suite.run(Suite.java:91)
>         at
> junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:36)
>         at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:515)
>         at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1031)
>         at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:888)
> Caused by: org.apache.cxf.service.factory.ServiceConstructionException
>         at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:112)
>         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:1414)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
>         ... 46 more
> Caused by: java.lang.IllegalArgumentException: Can not set
> org.apache.cxf.jaxrs.ext.MessageContext field
> com.contractservice.webservice.impl.rest.ItemServiceImplRest.messageContext
> to $Proxy46
>         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:155)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:151)
>         at
> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtils.java:695)
>         at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:180)
>         at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:201)
>         at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:80)
>         ... 53 more
> 

-- 
View this message in context: http://www.nabble.com/Error-trying-to-use-MessageContext-with-Spring-Security-enabled---JAX-RS-tp24077137p24080094.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message