2 Replies Latest reply on Jul 22, 2013 8:39 AM by asoldano

    JBossWS-CXF Web Service with Spring calls default constructor

    bapats

      We are building a CXF Web Service using jbossws-cxf.xml/Spring approach in EAP 6.1. The jaxws:endpoint implementor bean (web service), is constructed with several dependencies (Spring beans) using constructor injection.

       

      Initially, we ran into JBAS011054: Could not find default constructor. As a result we had to add default constructor to the web service.

       

      Here's what is happening with the web service invocation.

       

      1. At EAP startup, during deployment, the web service class is constructed with all the Spring injected dependencies as expected.
      2. When the web service is invoked, the default constructor for the web service is getting called. It  constructs a new web service object with the default constructor, and invokes the web service method on this instance. As a result, none of the dependencies are injected, and the call fails. The call stack when it is calling the default constructor is below.


      Why is it constructing new web service objects by calling the default constructor, when the web service has been already constructed with the correct injection during deployment time? This is causing the web service to not function. Is there a configuration parameter I am missing that is causing this behavior?

       

      Call stack when default constructor is getting called:

       

      Daemon Thread [http-/127.0.0.1:8443-1] (Suspended (breakpoint at line 99 in TestService))
      TestService$$$view8(TestService).() line: 99     
      TestService$$$view8.() line: not available     
      NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]     
      NativeConstructorAccessorImpl.newInstance(Object[]) line: 39     
      DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27     
      Constructor.newInstance(Object...) line: 513     
      Class.newInstance0() line: 355     
      Class.newInstance() line: 308     
      ProxyFactory(AbstractClassFactory).newInstance() line: 225     
      ProxyFactory.newInstance(InvocationHandler) line: 270     
      ViewService$DefaultViewInstanceFactory.createViewInstance(ComponentView, Map) line: 263     
      ViewService$View.createInstance(Map) line: 157     
      ViewService$View.createInstance() line: 153     
      InvocationHandlerJAXWS(AbstractInvocationHandler).getComponentView() line: 79     
      InvocationHandlerJAXWS(AbstractInvocationHandler).invoke(Endpoint, Invocation) line: 101     
      JBossWSInvoker.performInvocation(Exchange, Object, Method, Object[]) line: 149     
      JBossWSInvoker(AbstractInvoker).invoke(Exchange, Object, Method, List) line: 96     
      JBossWSInvoker(AbstractJAXWSMethodInvoker).invoke(Exchange, Object, Method, List) line: 178     
      JBossWSInvoker(JAXWSMethodInvoker).invoke(Exchange, Object, Method, List) line: 66     
      JBossWSInvoker.invoke(Exchange, Object) line: 129     
      ServiceInvokerInterceptor$1.run() line: 58     
      Executors$RunnableAdapter.call() line: 439     
      FutureTask$Sync.innerRun() line: 303     
      ServiceInvokerInterceptor$2(FutureTask).run() line: 138     
      SynchronousExecutor.execute(Runnable) line: 37     
      ServiceInvokerInterceptor.handleMessage(Message) line: 107     
      PhaseInterceptorChain.doIntercept(Message) line: 262     
      ChainInitiationObserver.onMessage(Message) line: 121     
      ServletDestination(AbstractHTTPDestination).invoke(ServletConfig, ServletContext, HttpServletRequest, HttpServletResponse) line: 237     
      RequestHandlerImpl.handleHttpRequest(Endpoint, HttpServletRequest, HttpServletResponse, ServletContext) line: 95     
      ServletHelper.callRequestHandler(HttpServletRequest, HttpServletResponse, ServletContext, Bus, Endpoint) line: 156     
      CXFServletExt.invoke(HttpServletRequest, HttpServletResponse) line: 87     
      CXFServletExt(AbstractHTTPServlet).handleRequest(HttpServletRequest, HttpServletResponse) line: 225     
      CXFServletExt(AbstractHTTPServlet).doPost(HttpServletRequest, HttpServletResponse) line: 145     
      CXFServletExt(HttpServlet).service(HttpServletRequest, HttpServletResponse) line: 754     
      CXFServletExt.service(HttpServletRequest, HttpServletResponse, ServletContext) line: 135     
      WSFServlet.service(HttpServletRequest, HttpServletResponse) line: 140     
      WSFServlet(HttpServlet).service(ServletRequest, ServletResponse) line: 847     
      ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 295     
      ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 214     
      StandardWrapperValve.invoke(Request, Response) line: 230     
      StandardContextValve.invoke(Request, Response) line: 149     
      NonLoginAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 481     
      SecurityContextAssociationValve.invoke(Request, Response) line: 169     
      StandardHostValve.invoke(Request, Response) line: 145     
      ErrorReportValve.invoke(Request, Response) line: 97     
      StandardEngineValve.invoke(Request, Response) line: 102     
      CoyoteAdapter.service(Request, Response) line: 336     
      Http11Processor.process(Socket) line: 856     
      Http11Protocol$Http11ConnectionHandler.process(Socket) line: 653     
      JIoEndpoint$Worker.run() line: 920     
      Thread.run() line: 662     

       

       

      Thanks

       

        • 1. Re: JBossWS-CXF Web Service with Spring calls default constructor
          bapats

          I am attaching a sample war file that reproduces this. It is deployed on the base EAP 6.1.0, with org.springframework.spring module added.

           

          Here's an excerpt from the log file which shows the corresponding logs when this war is deployed, and when the web method is called.

           

          Deployment:

          16:50:29,486 INFO  [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.1.3.Final-redhat-3

          16:50:29,600 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "demo-hello-world.war" (runtime-name: "demo-hello-world.war")

           

          ...

           

          16:50:30,045 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-6) JBAS018567: Deployment "deployment.demo-hello-world.war" is using a private module ("org.apache.cxf.impl:main") which may be changed or removed in future versions without notice.

          16:50:30,046 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-6) JBAS018567: Deployment "deployment.demo-hello-world.war" is using a private module ("org.apache.cxf.impl:main") which may be changed or removed in future versions without notice.

          16:50:30,638 INFO  [org.apache.cxf.bus.spring.BusApplicationContext] (MSC service thread 1-7) Refreshing org.apache.cxf.bus.spring.BusApplicationContext@288315b9: startup date [Wed Jun 12 16:50:30 EDT 2013]; root of context hierarchy

          16:50:30,711 INFO  [org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader] (MSC service thread 1-7) Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]

          16:50:30,789 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-7) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4a62b9d3: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor]; root of factory hierarchy

          16:50:31,129 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-7) Loading XML bean definitions from resource loaded through InputStream

          16:50:31,269 INFO  [org.springframework.context.support.GenericApplicationContext] (MSC service thread 1-7) Refreshing org.springframework.context.support.GenericApplicationContext@4873e835: startup date [Wed Jun 12 16:50:31 EDT 2013]; parent: org.apache.cxf.bus.spring.BusApplicationContext@288315b9

          16:50:31,273 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-7) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@706b7099: defining beans [helloWorldServiceEndpoint,testBean,helloWorldServiceBean]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@4a62b9d3

          16:50:31,304 INFO  [com.test.demo.ws.HelloWorldService] (MSC service thread 1-7) ~~~~~ Non default constructor called

          16:50:31,367 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-7) Creating Service {http://test.com/services/demo/HelloWorldService}HelloWorldService from class com.test.demo.ws.HelloWorldServiceI

          16:50:32,112 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-7) Setting the server's publish address to be http://localhost:8080/demo-hello-world/HelloWorldService

          16:50:32,205 INFO  [org.jboss.ws.cxf.deployment] (MSC service thread 1-7) JBWS024074: WSDL published to: file:/C:/jboss-eap-6.1/standalone/data/wsdl/demo-hello-world.war/HelloWorldService.wsdl

          16:50:32,244 INFO  [org.jboss.as.webservices] (MSC service thread 1-5) JBAS015539: Starting service jboss.ws.port-component-link

          16:50:32,259 INFO  [org.jboss.as.webservices] (MSC service thread 1-1) JBAS015539: Starting service jboss.ws.endpoint."demo-hello-world.war".HelloWorldService

          16:50:32,269 INFO  [org.jboss.ws.common.management] (MSC service thread 1-1) JBWS022050: Endpoint registered: jboss.ws:context=demo-hello-world,endpoint=HelloWorldService

          16:50:32,296 INFO  [org.jboss.web] (ServerService Thread Pool -- 49) JBAS018210: Register web context: /demo-hello-world

          16:50:32,562 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 26) JBAS018559: Deployed "demo-hello-world.war" (runtime-name : "demo-hello-world.war")

           

          ...

           

          Invoke web service method:


          16:50:40,165 INFO  [com.test.demo.ws.HelloWorldService] (http-/127.0.0.1:8080-1) ~~~~~ Default constructor called

          16:50:40,168 INFO  [com.test.demo.ws.HelloWorldService] (http-/127.0.0.1:8080-1) ~~~~~ Default constructor called

          16:50:40,169 INFO  [com.test.demo.ws.HelloWorldService] (http-/127.0.0.1:8080-1) ~~~~~ testBean is NULL

          • 2. Re: JBossWS-CXF Web Service with Spring calls default constructor
            asoldano

            Hi,

            sorry for the late reply. I've create a jira to track this and with a brief explanation of what's happening: https://issues.jboss.org/browse/JBWS-3670

            I think I remember the need for having a public default constructor in the WS endpoint is from JAXWS spec. Still the problem here is that the endpoint is instanciated twice. Will see if there's anything that can be done to help.