You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jeff Walker <we...@gmail.com> on 2009/05/11 18:20:05 UTC

@Resource declared in impl class not getting populated

Hi all,
I have web service that utilizes CXF 2.2.1 and Spring 2.5.6. The web service
compiles and runs when deployed in Tomcat. The beginning of the impl class
is like this:
...
import javax.xml.ws.WebServiceContext;
...
@WebService(
    serviceName = "TestWebService",
    portName = "TestWebServicePort",
    targetNamespace = "http://mycompany.com/service",
    endpointInterface = "com.mycompany.service.TestWebServicePort")
public class TestWebServicePortImpl implements TestWebServicePort {

    private static Logger log =
Logger.getLogger(TestWebServicePortImpl.class);
*    @Resource WebServiceContext wscontext;    // Supposed to be injected by
JAX-WS framework. Doesn't work yet.
*...

But the wscontext property is never populated. In fact it throws an info
line to the Tomcat console:
...
INFO: failed to resolve resource
com.mycompany.service.TestWebServicePortImpl/wscontext
...

Now, wscontext is annotated with @Resource. I was under the impression that
CXF would populate this property for me. If CXF follows the JAX-WS 2.1 spec
strictly, would it not get populated?  Obviously, I am missing something,
but don't know what it is. Any help would be appreciated.
Thanks,
-jeff

Re: @Resource declared in impl class not getting populated

Posted by Jeff Walker <we...@gmail.com>.
So,
you guys have totally lost me.
But, I have managed to get the @Resource WebServiceContext populated by not
doing a silly thing, which I will now gleefully describe to you.

In my applicationContext.xml, I had declared a JAX-RS service to have the
same implementation class as my JAX-WS service. This actually seems to work,
but causes the @Resource WebServiceContext wscontext to never get populated.
I decided to break out the REST impl to its own class, and now the wscontext
gets populated. Here is my original, faulty, applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jaxrs="http://cxf.apache.org/jaxrs"
  xmlns:jaxws="http://cxf.apache.org/jaxws"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:p="http://www.springframework.org/schema/p" xmlns:context="
http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    http://cxf.apache.org/jaxrs
    http://cxf.apache.org/schemas/jaxrs.xsd"
    default-lazy-init="false">

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"
/>
  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />


  <!-- ======================= JAX-RS and JAX-WS DEFINITIONS
======================== -->

  <!-- JAX-RS -->
  <jaxrs:server id="testRESTService" address="/">
    <jaxrs:serviceBeans>
      <ref bean="testWebServicePortImpl" />
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
      <entry key="xml" value="application/xml" />
    </jaxrs:extensionMappings>
  </jaxrs:server>

  <jaxws:endpoint name="{http://mycompany.com/service}TestWebService"
    id="TestWebService"
    implementor="#testWebServicePortImpl"
    wsdlLocation="/WEB-INF/wsdl/TestWebService.wsdl"
    address="/TestWebService">
  </jaxws:endpoint>


  <!-- ================== BUSINESS OBJECT DEFINITIONS ======================
-->

  <!-- Spring2 needs to know about our service implementation bean -->
  <bean id="testWebServicePortImpl"
class="com.mycompany.service.TestWebServicePortImpl">
    <!-- <property name="appContext" ref="appContext"/> -->
  </bean>

</beans>


I seem to be back in business now (by making the jaxrs:server refer to a
different bean class than the one in the jaxws:endpoint).
Thanks to Dan, and Ron. I don't fully understand what your both saying, but
will listen to any further conversation on this @Resource thing to try to
learn.
-jeff





On Wed, May 13, 2009 at 10:59 AM, Daniel Kulp <dk...@apache.org> wrote:

> On Wed May 13 2009 10:45:47 am Ron Grimes wrote:
> > Dan,
> >
> > What do you mean that "Spring code explicitly does NOT process any
> > WebServiceContext resources" via the @Resource annotation? Maybe I'm not
> > getting what you're saying, but I explicitly do use the @Resource
> > annotation to grab the WebServiceContext for me.
>
>
> What I mean is that if you use the Spring CommonAnnotationBeanPostProcessor
> class to process the JSR250 annotations, it will explicitely ignore the
> WebServiceContext.    If you look at the code:
> https://fisheye.springsource.org/browse/~raw,r=305/spring-
>
> framework/trunk/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java<https://fisheye.springsource.org/browse/%7Eraw,r=305/spring-%0Aframework/trunk/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java>
> in the constructor, you see:
> ignoreResourceType("javax.xml.ws.WebServiceContext");
>
>
> That's basically what I mean.   The CommonAnnotationBeanPostProcessor can
> be
> used to process all the @Resource things, but NOT the @Resource on the
> WebServiceContext.   We need to go back and then process those ourselves.
> Most of the time (in all my tests), we're succeeding with that, but
> apparently
> in this case, we're not.   I'd like to know more details about the users
> testcase to try and figure out why we're failing.
>
> Dan
>
>
> >
> > ApplicationContext.xml:
> > <bean id="webServiceContextImpl"
> >       class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />
> >
> >
> >
> > Service class:
> > @WebService(endpointInterface = "com.ssc.common.ws.IPGeographyService",
> >               serviceName = "IPGeographyService")
> > public class IPGeographyServiceImpl implements IPGeographyService
> > {
> >       @Resource(name = "webServiceContextImpl")
> >       private WebServiceContext wsContext;
> >
> >
> > Method that uses WebServiceContext:
> > private String getIpAddress()
> > {
> >       MessageContext mc       = wsContext.getMessageContext();
> >       HttpServletRequest request =
> >               (javax.servlet.http.HttpServletRequest)
> > mc.get(MessageContext.SERVLET_REQUEST);
> >       InetAddress inetAddress = null;
> >       // Get the non-proxied IP address as a default
> >       // (in case we're not behind a proxy).
> >       // Will be 127.0.0.1, if we are behind a proxy, but we'll
> >       // use it as the default return value in case the
> > x-forwarded-for
> >       // header isn't available.
> >       String ipAddress = request.getRemoteAddr();
> >
> >       try
> >       {
> >               // If behind a proxy, get "x-forwarded-for" header,
> >               // which contains the client's IP address.
> >               if (request.getHeader("x-forwarded-for") != null)
> >               {
> >                       try
> >                       {
> >                               inetAddress     =
> > InetAddress.getByName(request.getHeader("x-forwarded-for"));
> >                               ipAddress       =
> > inetAddress.getHostAddress();
> >                       } catch (UnknownHostException e) {}
> >               }
> >       } catch (Exception e1) {}
> >
> >       return ipAddress;
> > }
> >
> >
> > Ron
> >
> >
> > -----Original Message-----
> > From: Daniel Kulp [mailto:dkulp@apache.org]
> > Sent: Tuesday, May 12, 2009 3:14 PM
> > To: users@cxf.apache.org
> > Cc: Jeff Walker
> > Subject: Re: @Resource declared in impl class not getting populated
> >
> >
> > How are you configuring the CXF stuff?   Is it a Spring application
> > context
> > listener thing?    Are you using Springs annotation processor?  That
> > kind of
> > information can help track it down a bit.   Spring CAN process @Resource
> >
> > things, but the Spring code explicitely does NOT process any
> > WebServiceContext
> > resources.   Thus, we get into a situation where we should ONLY process
> > those,
> > but nothing else and that can also get confusing.
> >
> > If you are using a context listener approach, you can try importing
> > /META-INF/cxf/cxf-extension-jaxws.xml
> > that may help.
> >
> > Dan
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>

Re: @Resource declared in impl class not getting populated

Posted by Daniel Kulp <dk...@apache.org>.
It SOUNDS like you are getting some sort of mix of 2.1.2 and 2.2.1 jars mixed 
together.     We no longer have anything that is marked 
@Resource(name = "bus")
which is what would have caused this.    2.1.2 and earlier did have some 
resources  marked that way which is why I think some mix of jars is occuring.

Dan


On Fri May 22 2009 9:41:32 am Scott Archer wrote:
> I'm getting the following stack trace when I start up a minimal webapp with
> a cxf web service configured.
>
> It fails when I add the spring CommonAnnotationBeanPostProcessor to the
> spring beans.xml file.
> Is there a way the CommonAnnotationBeanPostProcessor and CXF can both work
> together?
>
> Thanks,
>
> Scott
>
>
> <bean
> class="org.springframework.context.annotation.CommonAnnotationBeanPostProce
>ssor"> <property name="fallbackToDefaultTypeMatch" value="false"/>
> </bean>
>
>
> It's working in our app with cxf 2.1.2, but I get this error with 2.1.3+.
> My simple test app is using cxf 2.2.1 and spring 2.5.5.
>
> my simple test app - http://www.microsped.com/~archer/files/cxf-test.zip
>
>
> stacktrace -
>
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean with name 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor':
> Injection of resource methods failed; nested exception is
> org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
> named 'bus' is defined
>     at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.po
>stProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.populateBean(AbstractAutowireCapableBeanFactory.java:998) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y$1.run(AbstractAutowireCapableBeanFactory.java:409) at
> java.security.AccessController.doPrivileged(Native Method)
>     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.createBean(AbstractAutowireCapableBeanFactory.java:380) at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(A
>bstractBeanFactory.java:264) at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getS
>ingleton(DefaultSingletonBeanRegistry.java:221) at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abs
>tractBeanFactory.java:261) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:185) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:164) at
> org.springframework.context.support.AbstractApplicationContext.getBean(Abst
>ractApplicationContext.java:881) at
> org.springframework.context.support.AbstractApplicationContext.registerBean
>PostProcessors(AbstractApplicationContext.java:597) at
> org.springframework.context.support.AbstractApplicationContext.refresh(Abst
>ractApplicationContext.java:366) at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(C
>ontextLoader.java:255) at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(Con
>textLoader.java:199) at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(Co
>ntextLoaderListener.java:45) at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java
>:3843) at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
>     at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>     at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>     at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>     at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
>     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
> No bean named 'bus' is defined
>     at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.getBea
>nDefinition(DefaultListableBeanFactory.java:387) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLoca
>lBeanDefinition(AbstractBeanFactory.java:968) at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abs
>tractBeanFactory.java:246) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:185) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:168) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.au
>towireResource(CommonAnnotationBeanPostProcessor.java:435) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.ge
>tResource(CommonAnnotationBeanPostProcessor.java:409) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$Re
>sourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537
>) at
> org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElem
>ent.inject(InjectionMetadata.java:192) at
> org.springframework.beans.factory.annotation.InjectionMetadata.injectMethod
>s(InjectionMetadata.java:117) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.po
>stProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:302) ... 31
> more
> May 21, 2009 5:01:55 PM org.apache.catalina.core.StandardContext
> listenerStart
> SEVERE: 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 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor':
> Injection of resource methods failed; nested exception is
> org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
> named 'bus' is defined
>     at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.po
>stProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.populateBean(AbstractAutowireCapableBeanFactory.java:998) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y$1.run(AbstractAutowireCapableBeanFactory.java:409) at
> java.security.AccessController.doPrivileged(Native Method)
>     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor
>y.createBean(AbstractAutowireCapableBeanFactory.java:380) at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(A
>bstractBeanFactory.java:264) at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getS
>ingleton(DefaultSingletonBeanRegistry.java:221) at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abs
>tractBeanFactory.java:261) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:185) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:164) at
> org.springframework.context.support.AbstractApplicationContext.getBean(Abst
>ractApplicationContext.java:881) at
> org.springframework.context.support.AbstractApplicationContext.registerBean
>PostProcessors(AbstractApplicationContext.java:597) at
> org.springframework.context.support.AbstractApplicationContext.refresh(Abst
>ractApplicationContext.java:366) at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(C
>ontextLoader.java:255) at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(Con
>textLoader.java:199) at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(Co
>ntextLoaderListener.java:45) at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java
>:3843) at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
>     at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>     at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>     at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>     at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
>     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
> No bean named 'bus' is defined
>     at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.getBea
>nDefinition(DefaultListableBeanFactory.java:387) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLoca
>lBeanDefinition(AbstractBeanFactory.java:968) at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abs
>tractBeanFactory.java:246) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:185) at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
>actBeanFactory.java:168) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.au
>towireResource(CommonAnnotationBeanPostProcessor.java:435) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.ge
>tResource(CommonAnnotationBeanPostProcessor.java:409) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$Re
>sourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537
>) at
> org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElem
>ent.inject(InjectionMetadata.java:192) at
> org.springframework.beans.factory.annotation.InjectionMetadata.injectMethod
>s(InjectionMetadata.java:117) at
> org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.po
>stProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:302) ... 31
> more
>
> On Wed, May 13, 2009 at 10:24 AM, Ron Grimes <rg...@sinclairoil.com>wrote:
> > Ok, got it. I'm only using the
> > org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcess
> > or. Plus, my @Resource references the bean id explicitly. So, those
> > might be the differences.
> >
> > Ron
> >
> >
> > -----Original Message-----
> > From: Daniel Kulp [mailto:dkulp@apache.org]
> > Sent: Wednesday, May 13, 2009 9:00 AM
> > To: users@cxf.apache.org
> > Cc: Ron Grimes
> > Subject: Re: @Resource declared in impl class not getting populated
> >
> > On Wed May 13 2009 10:45:47 am Ron Grimes wrote:
> > > Dan,
> > >
> > > What do you mean that "Spring code explicitly does NOT process any
> > > WebServiceContext resources" via the @Resource annotation? Maybe I'm
> > > not getting what you're saying, but I explicitly do use the @Resource
> > > annotation to grab the WebServiceContext for me.
> >
> > What I mean is that if you use the Spring
> > CommonAnnotationBeanPostProcessor class to process the JSR250
> > annotations, it will explicitely ignore the
> > WebServiceContext.    If you look at the code:
> > https://fisheye.springsource.org/browse/~raw,r=305/spring-
> > framework/trunk/org.springframework.context/src/main/java/org/springfram
> > ework/context/annotation/CommonAnnotationBeanPostProcessor.java<https://f
> >isheye.springsource.org/browse/%7Eraw,r=305/spring-%0Aframework/trunk/org.
> >springframework.context/src/main/java/org/springfram%0Aework/context/annot
> >ation/CommonAnnotationBeanPostProcessor.java> in the constructor, you see:
> > ignoreResourceType("javax.xml.ws.WebServiceContext");
> >
> >
> > That's basically what I mean.   The CommonAnnotationBeanPostProcessor
> > can be
> > used to process all the @Resource things, but NOT the @Resource on the
> > WebServiceContext.   We need to go back and then process those
> > ourselves.
> > Most of the time (in all my tests), we're succeeding with that, but
> > apparently
> > in this case, we're not.   I'd like to know more details about the users
> >
> > testcase to try and figure out why we're failing.
> >
> > Dan
> >
> > > ApplicationContext.xml:
> > > <bean id="webServiceContextImpl"
> > >       class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />
> > >
> > >
> > >
> > > Service class:
> > > @WebService(endpointInterface =
> >
> > "com.ssc.common.ws.IPGeographyService",
> >
> > >               serviceName = "IPGeographyService")
> > > public class IPGeographyServiceImpl implements IPGeographyService
> > > {
> > >       @Resource(name = "webServiceContextImpl")
> > >       private WebServiceContext wsContext;
> > >
> > >
> > > Method that uses WebServiceContext:
> > > private String getIpAddress()
> > > {
> > >       MessageContext mc       = wsContext.getMessageContext();
> > >       HttpServletRequest request =
> > >               (javax.servlet.http.HttpServletRequest)
> > > mc.get(MessageContext.SERVLET_REQUEST);
> > >       InetAddress inetAddress = null;
> > >       // Get the non-proxied IP address as a default
> > >       // (in case we're not behind a proxy).
> > >       // Will be 127.0.0.1, if we are behind a proxy, but we'll
> > >       // use it as the default return value in case the
> > > x-forwarded-for
> > >       // header isn't available.
> > >       String ipAddress = request.getRemoteAddr();
> > >
> > >       try
> > >       {
> > >               // If behind a proxy, get "x-forwarded-for" header,
> > >               // which contains the client's IP address.
> > >               if (request.getHeader("x-forwarded-for") != null)
> > >               {
> > >                       try
> > >                       {
> > >                               inetAddress     =
> > > InetAddress.getByName(request.getHeader("x-forwarded-for"));
> > >                               ipAddress       =
> > > inetAddress.getHostAddress();
> > >                       } catch (UnknownHostException e) {}
> > >               }
> > >       } catch (Exception e1) {}
> > >
> > >       return ipAddress;
> > > }
> > >
> > >
> > > Ron
> > >
> > >
> > > -----Original Message-----
> > > From: Daniel Kulp [mailto:dkulp@apache.org]
> > > Sent: Tuesday, May 12, 2009 3:14 PM
> > > To: users@cxf.apache.org
> > > Cc: Jeff Walker
> > > Subject: Re: @Resource declared in impl class not getting populated
> > >
> > >
> > > How are you configuring the CXF stuff?   Is it a Spring application
> > > context
> > > listener thing?    Are you using Springs annotation processor?  That
> > > kind of
> > > information can help track it down a bit.   Spring CAN process
> >
> > @Resource
> >
> > > things, but the Spring code explicitely does NOT process any
> > > WebServiceContext
> > > resources.   Thus, we get into a situation where we should ONLY
> >
> > process
> >
> > > those,
> > > but nothing else and that can also get confusing.
> > >
> > > If you are using a context listener approach, you can try importing
> > > /META-INF/cxf/cxf-extension-jaxws.xml
> > > that may help.
> > >
> > > Dan
> >
> > --
> > Daniel Kulp
> > dkulp@apache.org
> > http://www.dankulp.com/blog

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

Re: @Resource declared in impl class not getting populated

Posted by Scott Archer <sc...@gmail.com>.
I'm getting the following stack trace when I start up a minimal webapp with
a cxf web service configured.

It fails when I add the spring CommonAnnotationBeanPostProcessor to the
spring beans.xml file.
Is there a way the CommonAnnotationBeanPostProcessor and CXF can both work
together?

Thanks,

Scott


<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
    <property name="fallbackToDefaultTypeMatch" value="false"/>
</bean>


It's working in our app with cxf 2.1.2, but I get this error with 2.1.3+.
My simple test app is using cxf 2.2.1 and spring 2.5.5.

my simple test app - http://www.microsped.com/~archer/files/cxf-test.zip


stacktrace -

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor': Injection of
resource methods failed; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'bus' is defined
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)
    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    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:221)
    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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
    at
org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:597)
    at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at
org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at
org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'bus' is defined
    at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:968)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537)
    at
org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:192)
    at
org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:302)
    ... 31 more
May 21, 2009 5:01:55 PM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: 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 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor': Injection of
resource methods failed; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'bus' is defined
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)
    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    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:221)
    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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
    at
org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:597)
    at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at
org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at
org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'bus' is defined
    at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:968)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537)
    at
org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:192)
    at
org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117)
    at
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:302)
    ... 31 more

On Wed, May 13, 2009 at 10:24 AM, Ron Grimes <rg...@sinclairoil.com>wrote:

> Ok, got it. I'm only using the
> org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcess
> or. Plus, my @Resource references the bean id explicitly. So, those
> might be the differences.
>
> Ron
>
>
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: Wednesday, May 13, 2009 9:00 AM
> To: users@cxf.apache.org
> Cc: Ron Grimes
> Subject: Re: @Resource declared in impl class not getting populated
>
> On Wed May 13 2009 10:45:47 am Ron Grimes wrote:
> > Dan,
> >
> > What do you mean that "Spring code explicitly does NOT process any
> > WebServiceContext resources" via the @Resource annotation? Maybe I'm
> > not getting what you're saying, but I explicitly do use the @Resource
> > annotation to grab the WebServiceContext for me.
>
>
> What I mean is that if you use the Spring
> CommonAnnotationBeanPostProcessor class to process the JSR250
> annotations, it will explicitely ignore the
> WebServiceContext.    If you look at the code:
> https://fisheye.springsource.org/browse/~raw,r=305/spring-
> framework/trunk/org.springframework.context/src/main/java/org/springfram
> ework/context/annotation/CommonAnnotationBeanPostProcessor.java<https://fisheye.springsource.org/browse/%7Eraw,r=305/spring-%0Aframework/trunk/org.springframework.context/src/main/java/org/springfram%0Aework/context/annotation/CommonAnnotationBeanPostProcessor.java>
> in the constructor, you see:
> ignoreResourceType("javax.xml.ws.WebServiceContext");
>
>
> That's basically what I mean.   The CommonAnnotationBeanPostProcessor
> can be
> used to process all the @Resource things, but NOT the @Resource on the
> WebServiceContext.   We need to go back and then process those
> ourselves.
> Most of the time (in all my tests), we're succeeding with that, but
> apparently
> in this case, we're not.   I'd like to know more details about the users
>
> testcase to try and figure out why we're failing.
>
> Dan
>
>
> >
> > ApplicationContext.xml:
> > <bean id="webServiceContextImpl"
> >       class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />
> >
> >
> >
> > Service class:
> > @WebService(endpointInterface =
> "com.ssc.common.ws.IPGeographyService",
> >               serviceName = "IPGeographyService")
> > public class IPGeographyServiceImpl implements IPGeographyService
> > {
> >       @Resource(name = "webServiceContextImpl")
> >       private WebServiceContext wsContext;
> >
> >
> > Method that uses WebServiceContext:
> > private String getIpAddress()
> > {
> >       MessageContext mc       = wsContext.getMessageContext();
> >       HttpServletRequest request =
> >               (javax.servlet.http.HttpServletRequest)
> > mc.get(MessageContext.SERVLET_REQUEST);
> >       InetAddress inetAddress = null;
> >       // Get the non-proxied IP address as a default
> >       // (in case we're not behind a proxy).
> >       // Will be 127.0.0.1, if we are behind a proxy, but we'll
> >       // use it as the default return value in case the
> > x-forwarded-for
> >       // header isn't available.
> >       String ipAddress = request.getRemoteAddr();
> >
> >       try
> >       {
> >               // If behind a proxy, get "x-forwarded-for" header,
> >               // which contains the client's IP address.
> >               if (request.getHeader("x-forwarded-for") != null)
> >               {
> >                       try
> >                       {
> >                               inetAddress     =
> > InetAddress.getByName(request.getHeader("x-forwarded-for"));
> >                               ipAddress       =
> > inetAddress.getHostAddress();
> >                       } catch (UnknownHostException e) {}
> >               }
> >       } catch (Exception e1) {}
> >
> >       return ipAddress;
> > }
> >
> >
> > Ron
> >
> >
> > -----Original Message-----
> > From: Daniel Kulp [mailto:dkulp@apache.org]
> > Sent: Tuesday, May 12, 2009 3:14 PM
> > To: users@cxf.apache.org
> > Cc: Jeff Walker
> > Subject: Re: @Resource declared in impl class not getting populated
> >
> >
> > How are you configuring the CXF stuff?   Is it a Spring application
> > context
> > listener thing?    Are you using Springs annotation processor?  That
> > kind of
> > information can help track it down a bit.   Spring CAN process
> @Resource
> >
> > things, but the Spring code explicitely does NOT process any
> > WebServiceContext
> > resources.   Thus, we get into a situation where we should ONLY
> process
> > those,
> > but nothing else and that can also get confusing.
> >
> > If you are using a context listener approach, you can try importing
> > /META-INF/cxf/cxf-extension-jaxws.xml
> > that may help.
> >
> > Dan
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>

RE: @Resource declared in impl class not getting populated

Posted by Ron Grimes <rg...@sinclairoil.com>.
Ok, got it. I'm only using the
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcess
or. Plus, my @Resource references the bean id explicitly. So, those
might be the differences.

Ron
 

-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: Wednesday, May 13, 2009 9:00 AM
To: users@cxf.apache.org
Cc: Ron Grimes
Subject: Re: @Resource declared in impl class not getting populated

On Wed May 13 2009 10:45:47 am Ron Grimes wrote:
> Dan,
>
> What do you mean that "Spring code explicitly does NOT process any 
> WebServiceContext resources" via the @Resource annotation? Maybe I'm 
> not getting what you're saying, but I explicitly do use the @Resource 
> annotation to grab the WebServiceContext for me.


What I mean is that if you use the Spring
CommonAnnotationBeanPostProcessor class to process the JSR250
annotations, it will explicitely ignore the 
WebServiceContext.    If you look at the code:
https://fisheye.springsource.org/browse/~raw,r=305/spring-
framework/trunk/org.springframework.context/src/main/java/org/springfram
ework/context/annotation/CommonAnnotationBeanPostProcessor.java
in the constructor, you see:
ignoreResourceType("javax.xml.ws.WebServiceContext");


That's basically what I mean.   The CommonAnnotationBeanPostProcessor
can be 
used to process all the @Resource things, but NOT the @Resource on the 
WebServiceContext.   We need to go back and then process those
ourselves.   
Most of the time (in all my tests), we're succeeding with that, but
apparently 
in this case, we're not.   I'd like to know more details about the users

testcase to try and figure out why we're failing.

Dan


>
> ApplicationContext.xml:
> <bean	id="webServiceContextImpl"
> 	class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />
>
>
>
> Service class:
> @WebService(endpointInterface =
"com.ssc.common.ws.IPGeographyService",
> 		serviceName = "IPGeographyService")
> public class IPGeographyServiceImpl implements IPGeographyService
> {
> 	@Resource(name = "webServiceContextImpl")
> 	private WebServiceContext wsContext;
>
>
> Method that uses WebServiceContext:
> private String getIpAddress()
> {
> 	MessageContext mc	= wsContext.getMessageContext();
> 	HttpServletRequest request =
> 		(javax.servlet.http.HttpServletRequest)
> mc.get(MessageContext.SERVLET_REQUEST);
> 	InetAddress inetAddress	= null;
> 	// Get the non-proxied IP address as a default
> 	// (in case we're not behind a proxy).
> 	// Will be 127.0.0.1, if we are behind a proxy, but we'll
> 	// use it as the default return value in case the
> x-forwarded-for
> 	// header isn't available.
> 	String ipAddress = request.getRemoteAddr();
>
> 	try
> 	{
> 		// If behind a proxy, get "x-forwarded-for" header,
> 		// which contains the client's IP address.
> 		if (request.getHeader("x-forwarded-for") != null)
> 		{
> 			try
> 			{
> 				inetAddress	=
> InetAddress.getByName(request.getHeader("x-forwarded-for"));
> 				ipAddress	=
> inetAddress.getHostAddress();
> 			} catch (UnknownHostException e) {}
> 		}
> 	} catch (Exception e1) {}
>
> 	return ipAddress;
> }
>
>
> Ron
>
>
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: Tuesday, May 12, 2009 3:14 PM
> To: users@cxf.apache.org
> Cc: Jeff Walker
> Subject: Re: @Resource declared in impl class not getting populated
>
>
> How are you configuring the CXF stuff?   Is it a Spring application
> context
> listener thing?    Are you using Springs annotation processor?  That
> kind of
> information can help track it down a bit.   Spring CAN process
@Resource
>
> things, but the Spring code explicitely does NOT process any
> WebServiceContext
> resources.   Thus, we get into a situation where we should ONLY
process
> those,
> but nothing else and that can also get confusing.
>
> If you are using a context listener approach, you can try importing
> /META-INF/cxf/cxf-extension-jaxws.xml
> that may help.
>
> Dan

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

Re: @Resource declared in impl class not getting populated

Posted by Daniel Kulp <dk...@apache.org>.
On Wed May 13 2009 10:45:47 am Ron Grimes wrote:
> Dan,
>
> What do you mean that "Spring code explicitly does NOT process any
> WebServiceContext resources" via the @Resource annotation? Maybe I'm not
> getting what you're saying, but I explicitly do use the @Resource
> annotation to grab the WebServiceContext for me.


What I mean is that if you use the Spring CommonAnnotationBeanPostProcessor 
class to process the JSR250 annotations, it will explicitely ignore the 
WebServiceContext.    If you look at the code:
https://fisheye.springsource.org/browse/~raw,r=305/spring-
framework/trunk/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
in the constructor, you see:
ignoreResourceType("javax.xml.ws.WebServiceContext");


That's basically what I mean.   The CommonAnnotationBeanPostProcessor can be 
used to process all the @Resource things, but NOT the @Resource on the 
WebServiceContext.   We need to go back and then process those ourselves.   
Most of the time (in all my tests), we're succeeding with that, but apparently 
in this case, we're not.   I'd like to know more details about the users 
testcase to try and figure out why we're failing.

Dan


>
> ApplicationContext.xml:
> <bean	id="webServiceContextImpl"
> 	class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />
>
>
>
> Service class:
> @WebService(endpointInterface = "com.ssc.common.ws.IPGeographyService",
> 		serviceName = "IPGeographyService")
> public class IPGeographyServiceImpl implements IPGeographyService
> {
> 	@Resource(name = "webServiceContextImpl")
> 	private WebServiceContext wsContext;
>
>
> Method that uses WebServiceContext:
> private String getIpAddress()
> {
> 	MessageContext mc	= wsContext.getMessageContext();
> 	HttpServletRequest request =
> 		(javax.servlet.http.HttpServletRequest)
> mc.get(MessageContext.SERVLET_REQUEST);
> 	InetAddress inetAddress	= null;
> 	// Get the non-proxied IP address as a default
> 	// (in case we're not behind a proxy).
> 	// Will be 127.0.0.1, if we are behind a proxy, but we'll
> 	// use it as the default return value in case the
> x-forwarded-for
> 	// header isn't available.
> 	String ipAddress = request.getRemoteAddr();
>
> 	try
> 	{
> 		// If behind a proxy, get "x-forwarded-for" header,
> 		// which contains the client's IP address.
> 		if (request.getHeader("x-forwarded-for") != null)
> 		{
> 			try
> 			{
> 				inetAddress	=
> InetAddress.getByName(request.getHeader("x-forwarded-for"));
> 				ipAddress	=
> inetAddress.getHostAddress();
> 			} catch (UnknownHostException e) {}
> 		}
> 	} catch (Exception e1) {}
>
> 	return ipAddress;
> }
>
>
> Ron
>
>
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: Tuesday, May 12, 2009 3:14 PM
> To: users@cxf.apache.org
> Cc: Jeff Walker
> Subject: Re: @Resource declared in impl class not getting populated
>
>
> How are you configuring the CXF stuff?   Is it a Spring application
> context
> listener thing?    Are you using Springs annotation processor?  That
> kind of
> information can help track it down a bit.   Spring CAN process @Resource
>
> things, but the Spring code explicitely does NOT process any
> WebServiceContext
> resources.   Thus, we get into a situation where we should ONLY process
> those,
> but nothing else and that can also get confusing.
>
> If you are using a context listener approach, you can try importing
> /META-INF/cxf/cxf-extension-jaxws.xml
> that may help.
>
> Dan

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

RE: @Resource declared in impl class not getting populated

Posted by Ron Grimes <rg...@sinclairoil.com>.
Dan,

What do you mean that "Spring code explicitly does NOT process any
WebServiceContext resources" via the @Resource annotation? Maybe I'm not
getting what you're saying, but I explicitly do use the @Resource
annotation to grab the WebServiceContext for me. 

ApplicationContext.xml:
<bean	id="webServiceContextImpl" 
	class="org.apache.cxf.jaxws.context.WebServiceContextImpl" />



Service class:
@WebService(endpointInterface = "com.ssc.common.ws.IPGeographyService",
		serviceName = "IPGeographyService")
public class IPGeographyServiceImpl implements IPGeographyService
{
	@Resource(name = "webServiceContextImpl")
	private WebServiceContext wsContext;


Method that uses WebServiceContext:
private String getIpAddress() 
{
	MessageContext mc	= wsContext.getMessageContext();
	HttpServletRequest request = 
		(javax.servlet.http.HttpServletRequest)
mc.get(MessageContext.SERVLET_REQUEST);
	InetAddress inetAddress	= null;
	// Get the non-proxied IP address as a default 
	// (in case we're not behind a proxy).
	// Will be 127.0.0.1, if we are behind a proxy, but we'll
	// use it as the default return value in case the
x-forwarded-for
	// header isn't available.
	String ipAddress = request.getRemoteAddr();	

	try
	{
		// If behind a proxy, get "x-forwarded-for" header, 
		// which contains the client's IP address.
		if (request.getHeader("x-forwarded-for") != null)
		{
			try
			{
				inetAddress	=
InetAddress.getByName(request.getHeader("x-forwarded-for"));
				ipAddress	=
inetAddress.getHostAddress();
			} catch (UnknownHostException e) {}
		} 
	} catch (Exception e1) {}

	return ipAddress;
}


Ron 


-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: Tuesday, May 12, 2009 3:14 PM
To: users@cxf.apache.org
Cc: Jeff Walker
Subject: Re: @Resource declared in impl class not getting populated


How are you configuring the CXF stuff?   Is it a Spring application
context 
listener thing?    Are you using Springs annotation processor?  That
kind of 
information can help track it down a bit.   Spring CAN process @Resource

things, but the Spring code explicitely does NOT process any
WebServiceContext 
resources.   Thus, we get into a situation where we should ONLY process
those, 
but nothing else and that can also get confusing.  

If you are using a context listener approach, you can try importing
/META-INF/cxf/cxf-extension-jaxws.xml
that may help.  

Dan


Re: @Resource declared in impl class not getting populated

Posted by Daniel Kulp <dk...@apache.org>.
How are you configuring the CXF stuff?   Is it a Spring application context 
listener thing?    Are you using Springs annotation processor?  That kind of 
information can help track it down a bit.   Spring CAN process @Resource 
things, but the Spring code explicitely does NOT process any WebServiceContext 
resources.   Thus, we get into a situation where we should ONLY process those, 
but nothing else and that can also get confusing.  

If you are using a context listener approach, you can try importing 
/META-INF/cxf/cxf-extension-jaxws.xml
that may help.  

Dan



On Mon May 11 2009 12:20:05 pm Jeff Walker wrote:
> Hi all,
> I have web service that utilizes CXF 2.2.1 and Spring 2.5.6. The web
> service compiles and runs when deployed in Tomcat. The beginning of the
> impl class is like this:
> ...
> import javax.xml.ws.WebServiceContext;
> ...
> @WebService(
>     serviceName = "TestWebService",
>     portName = "TestWebServicePort",
>     targetNamespace = "http://mycompany.com/service",
>     endpointInterface = "com.mycompany.service.TestWebServicePort")
> public class TestWebServicePortImpl implements TestWebServicePort {
>
>     private static Logger log =
> Logger.getLogger(TestWebServicePortImpl.class);
> *    @Resource WebServiceContext wscontext;    // Supposed to be injected
> by JAX-WS framework. Doesn't work yet.
> *...
>
> But the wscontext property is never populated. In fact it throws an info
> line to the Tomcat console:
> ...
> INFO: failed to resolve resource
> com.mycompany.service.TestWebServicePortImpl/wscontext
> ...
>
> Now, wscontext is annotated with @Resource. I was under the impression that
> CXF would populate this property for me. If CXF follows the JAX-WS 2.1 spec
> strictly, would it not get populated?  Obviously, I am missing something,
> but don't know what it is. Any help would be appreciated.
> Thanks,
> -jeff

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