2 Replies Latest reply on Oct 23, 2009 7:00 AM by sagolsb

    Spring bean injection to Service implementation

    sagolsb

      Hi,

      I have been trying to inject Spring beans to JBossWS native service implementation but still not successful. I tried getting the WebApplicationContext as follows, via @Resource WebServiceContext context, but it returns null (java.lang.UnsupportedOperationException: Not yet supported):

      ServletContext servletContext =
      (ServletContext) context.getMessageContext().get(
      MessageContext.SERVLET_CONTEXT);
      webApplicationContext =
      WebApplicationContextUtils.getWebApplicationContext(servletContext);

      Is there any example to inject Spring beans to JBossWS (native) services?

      Regards,
      Sagol

        • 1. Re: Spring bean injection to Service implementation
          sagolsb

          Here are some more information: when the web application starts up the web application context is started as shown in the stack trace below:

          [[/CredentialService]] Initializing Spring root WebApplicationContext
          [ContextLoader] Root WebApplicationContext: initialization started
          ....................
          [XmlWebApplicationContext] Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@f582e9]: org.springframework.beans.factory.support.DefaultListableBeanFactory@b9915a
          .......
          [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b9915a: defining beans [echoService]; root of factory hierarchy
          ..............
          [ContextLoader] Root WebApplicationContext: initialization completed in 170 ms



          Within the web service implementation class, the WebServiceContext is injected through @Resource and the ServletContext is retrieved from this through the MessageContext, both of which are printed out from the service implementation as shown below:


          [STDOUT] WebServiceContext: org.jboss.wsf.stack.jbws.WebServiceContextJSE@477e4c
          [STDOUT] ServletContext: org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorServletContext@1b4e510


          But when I try to retrive the WebApplicationContext through:
          webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
          which in turn internally calls:
          servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

          throws the exception:

          ERROR [InvocationHandlerJAXWS] Method invocation failed with exception: null
          java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          ........................
          Caused by: java.lang.UnsupportedOperationException: Not yet supported
          at org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorServletContext.getAttribute(SOAPProcessorServletContext.java:45)
          ..................................


          Can you please let me know if I'm missing something?

          Regards,
          Sagol

          • 2. Re: Spring bean injection to Service implementation
            sagolsb

            Just realized that this is a problem with the JBossESB SOAPProcessor; it works perfectly fine if I access the service directly, bypassing the ESB. Still I need a solution; please.

            thanks,
            Sagol