On Tue November 10 2009 6:20:18 pm Pydipati, Karuna wrote:
> I kind of found the issue. Since, I am doing my own Spring-AOP, I need
> to modify the jaxws:endpoint XML config as follows.
> 
> <jaxws:endpoint  id="XXXService"
>    implementorClass="com.xxx.ws.soap.XXXServiceImpl"
>    implementor="#xxxServiceImpl"
>   address="/XXXService"/>
> 
> Because of this, since Spring works on proxies, somehow, @Resource
> (WebServiceContext ) is failing. This is because ResourceInjector (CXF
> class) works on Fields (using Reflections API) rather than on methods.
> If the accessing of WebServiceContext is done using Methods (Reflections
> API),  it would not be a problem because proxies have methods too.
>

Thats because the @Resource annotation is on the field.   That's per spec.   
If you add a setContext(WebServiceContext) method to the class and add a 
@WebResource annotation on it, it should inject via the method. 

> So it appears that, we can not have any custom annotations in CXF
> implementor classes. I see this is a limitation of CXF (at least for
> now). I might need to do some other way of doing Throttling in stead of
> using Custom annotations.

It's really a bug or limitation of Spring, not CXF.   CXF can only work with 
the Objects Spring gives us.    If Spring wrappers the object with a proxy or 
does some other odd thing, we cannot get access to the field that is 
annotated.  

There's a few other ways to work around it as well.   You can import the META-
INF/cxf/cxf-extension-jaxws.xml  and then set it directly as a Spring property 
on you bean using a bean ref of "javax.xml.ws.WebServiceContext".    You could 
forget the whole injection thing and just do:

WebServiceContext ctx = new 
org.apache.cxf.jaxws.context.WebServiceContextImpl();

That would also work just fine.

Dan

> 
> Has anybody done any custom annotations on CXF implementor class which
> have @Resource (WebServiceContext)?
> 
> 
> Regards
> 
> Karuna Pydipati
> 
> StubHub/eBay - Platform & Services
> 
> Phone: (415)222-8752
> 
> Email: kpydip...@ebay.com <mailto:kpydip...@ebay.com>
> 
> 
> 
> 
> 
> ________________________________
> 
> From: Pydipati, Karuna
> Sent: Monday, November 09, 2009 3:49 PM
> To: users@cxf.apache.org; 'Sergey Beryozkin'; Sergey Beryozkin
> Subject: CXF and Custom Annotation
> 
> 
> Hi
> 
> I have a weird issue. I have a JAX-WS java-first webservice using CXF
> and Spring. I have WebServiceContext in my Implementer class. Here is
> snippet of my Implementer class
> 
> @WebService(endpointInterface = "com.xxx.ws.soap.XXXService",
> serviceName = "XXXService")
> @WebFault(targetNamespace = "com.xxx.ws.soap", name = "XXXFault",
> faultBean = "XXXFault")
> public class XXXServiceImpl implements XXXService {
> 
>  @Resource
>  private WebServiceContext webServiceContext;
> 
>  @Throttle
>  public PatientMatchResp getSomeMethod()
>     throws ApplicationFault {
>  ....
>  ....
>  ....
>  }
> 
> I have a custom annotation @Throttle and would like to do some work
> (basically throttling the method such as way that this service is not
> abused by users when exposed to public) on that method using Spring AOP.
> 
> 
> 1) My issue is when I started my Tomcat with this implementation, I am
> getting this error. Again, this is at the startup time of Tomcat time.
> Not at some invocation of webservice time. If I comment either
> WebServiceContext OR @Throttle, then, things are OK. Why is my custom
> annotation is giving problem for CXF startup?
> 
> 2) Second questions is.. is there a easy way to get hold of
> HttpServletRequest into my Aspect (Spring AOP). I don't know whether
> this is a right forum or not. Currently, I am trying to get hold of
> WebServiceContext using reflections API in my Aspect class and trying to
> get HttpServletRequest. Is there an example where I can write a CXF
> Handler/Filter and put WebServiceContext  into ThreadLocal so that I can
> get it wherever I want down-the-line(here..in this case my Aspect
> class)?
> 
> Caused by: javax.xml.ws.WebServiceException: Creation of Endpoint failed
>  at
> org.apache.cxf.jaxws.JaxWsServerFactoryBean.init(JaxWsServerFactoryBean.
> java:181)
>  at
> org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBea
> n.java:168)
>  at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:346)
>  at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:259)
>  at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:209)
>  at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:404)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> a:39)
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> Impl.java:25)
>  at java.lang.reflect.Method.invoke(Method.java:585)
>  at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1413
> )
>  at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1374)
>  at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
>  ... 39 more
> Caused by: java.lang.IllegalArgumentException
>  at
> sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.ja
> va:37)
>  at
> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorI
> mpl.java:57)
>  at java.lang.reflect.Field.set(Field.java:656)
>  at
> org.apache.cxf.common.injection.ResourceInjector.injectField(ResourceInj
> ector.java:283)
>  at
> org.apache.cxf.common.injection.ResourceInjector.visitField(ResourceInje
> ctor.java:167)
>  at
> org.apache.cxf.common.annotation.AnnotationProcessor.processFields(Annot
> ationProcessor.java:101)
>  at
> org.apache.cxf.common.annotation.AnnotationProcessor.accept(AnnotationPr
> ocessor.java:69)
>  at
> org.apache.cxf.common.injection.ResourceInjector.inject(ResourceInjector
> .java:81)
>  at
> org.apache.cxf.jaxws.JaxWsServerFactoryBean.injectResources(JaxWsServerF
> actoryBean.java:221)
>  at
> org.apache.cxf.jaxws.JaxWsServerFactoryBean.init(JaxWsServerFactoryBean.
> java:175)
>  ... 51 more
> Nov 9, 2009 3:32:14 PM org.apache.catalina.core.ApplicationContext log
> 
> 
> 
> Regards
> 
> Karuna Pydipati
> 
> StubHub/eBay - Platform & Services
> 
> Phone: (415)222-8752
> 
> Email: kpydip...@ebay.com <mailto:kpydip...@ebay.com>
> 

-- 
Daniel Kulp
dk...@apache.org
http://www.dankulp.com/blog

Reply via email to