Announcement Announcement Module
Collapse
No announcement yet.
axis2 or how to get applicationContext information? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • axis2 or how to get applicationContext information?

    Hi,

    I have a web application written in spring. Now I would like to integrate web services using axis2.

    At the moment there seems not to be an integration solution. Now I thought about using axis2 web application mixed up with mine ;-)

    Now I have the problem to get the beans in my independend java code. I thought about a class with static methods to inject the beans and to request them.

    Any suggestions? Is this a common way? Did somebody something similar? Is there a way to inject a reference to the beanfactory?

    thx
    Dominik

  • #2
    Replied to in http://forum.springframework.org/showthread.php?t=21750

    Comment


    • #3
      Hi yatesco,
      I am also looking for a solution, the link you mentioned above does not seem to have a solution to the problem. Basically I have 2 servlets:

      1- spring: org.springframework.web.servlet.DispatcherServlet
      Which contains my application
      2- axis: org.apache.axis.transport.http.AxisServlet
      Which contains my soap service interface (for example SoapUserManager,
      which needs a reference to the UserManagerImpl which is defined in the context of the spring servlet).

      Thanks,
      Hani

      Comment


      • #4
        Ok so here is a solution (got it from another post in this forum)
        In the spring context I load a SpringContext object

        Code:
        import org.springframework.beans.BeansException;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.ApplicationContextAware;
        
        public class SpringContext implements ApplicationContextAware {
        	private static ApplicationContext ctx;
        	
        	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        		ctx = applicationContext;
        	}
        	
        	public static ApplicationContext getContext() { return ctx; }
        	
        }
        Then in my soap service implementation I can get the spring context
        Code:
                ....
                Object aBean = SpringContext.getContext().getBean("aBean");
                .....
        I know this is not ideal, so if someone knows the 'proper way' please let me know.

        Hani

        Comment


        • #5
          Hi,

          thx for your help. Until axis2 adds spring support (or spring axis2 support) I'm going to use this approach.

          Comment


          • #6
            More Info on this solution

            Hello,
            I am trying to do the same thing. I have a spring application running and an Axis2 servlet running with my web services. I would like to call beans in my spring application from the Axis2 application. Can someone provide more details on the steps to accomlish this?

            Thanks!

            Yogesh

            Comment


            • #7
              If you have access to a standard ServletContext, and the spring applicationContext has already been bootstrapped then you can use http://www.springframework.org/docs/...textUtils.html.

              Comment


              • #8
                org.apache.axis2.extensions.spring.receivers.Appli cationContextHolder.getContext() will give you the ApplicationContext. I just used this and it seems to be working.

                If this doesn't work for you then the inject it into the application via applicationContextHolder.

                Comment


                • #9
                  ApplicationContextHolder works for me, too

                  Thank you. This is what I put in my constructor and it works:

                  ApplicationContext ctx = ApplicationContextHolder.getContext();
                  partnerService = (PartnerService) ctx.getBean("partnerService");

                  Comment


                  • #10
                    this combo works for me

                    I am running Axis2 inside my webapp and it is configured finally where my services can get access to Spring Application context.

                    Directory structure:
                    Code:
                    ./myApp
                    ./myApp/WEB-INF/hibernateSpringAxisContext.xml
                    ./myApp/WEB-INF/web.xml
                    ./myApp/WEB-INF/classes
                    ./myApp/WEB-INF/classes/hibernate.cfg.xml
                    ./myApp/WEB-INF/classes/myApp.hbm.xml
                    ./myApp/WEB-INF/classes/log4j.properties
                    ./myApp/WEB-INF/classes/com.bla.bla.MyService
                    ./myApp/WEB-INF/lib/axis2*.jars
                    ./myApp/WEB-INF/lib/all_axis2_jars
                    ./myApp/WEB-INF/services/MyWebService/META-INF/services.xml
                    services.xml
                    Code:
                    <serviceGroup>
                            <service name="MyService"
                                 targetNamespace="http://blabla.com/services/MyService/v.10.27.2007/">
                            <description>Book sample service</description>
                            
                            <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier</parameter>
                        	<parameter name="SpringBeanName">MyService</parameter>
                            
                            <schema schemaNamespace="http://blabla.com/services/MyService/v.10.27.2007/xsd/"/>
                            <parameter name="ServiceClass" locked="false">com.bla.bla.MyService</parameter>
                            <operation name="sayHi">
                                	<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
                    		</operation>
                            </service>
                    </serviceGroup>
                    web.xml
                    Code:
                    <web-app>		
                    	<servlet> <!-- another config for DAO -->
                    		<servlet-name>actionProc</servlet-name>
                    	    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                    	    <load-on-startup>1</load-on-startup>
                    	</servlet>
                    	
                        
                        <!-- hibernate configuration -->
                        <context-param>
                    		<param-name>contextConfigLocation</param-name>
                    		<param-value>/WEB-INF/hibernateSpringAxisContext.xml</param-value>
                    	</context-param>
                    	
                    	<listener>
                    		<listener-class>
                    			org.springframework.web.context.ContextLoaderListener
                    		</listener-class>
                    	</listener>
                    	
                    
                    	<!-- Axis2 setup -->
                    	<servlet>
                        	<servlet-name>AxisServlet</servlet-name>
                            <display-name>Apache-Axis Servlet</display-name>
                            <servlet-class>
                                org.apache.axis2.transport.http.AxisServlet</servlet-class>
                            <load-on-startup>1</load-on-startup>
                        </servlet>
                      
                      	<servlet-mapping>
                        	<servlet-name>AxisServlet</servlet-name>
                        	<url-pattern>/services/*</url-pattern>
                      	</servlet-mapping>
                    </web-app>
                    MyService.java
                    Code:
                    package com.bla.bla;
                    import org.springframework.context.ApplicationContext;
                    import org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder;
                    public class MyService {
                       public String sayHi(String text) {
                          ApplicationContext ctx = ApplicationContextHolder.getContext();
                          return "good deal: " + text;
                       }
                    }
                    url:
                    Code:
                    http://localhost/myApp/services/MyService

                    Comment


                    • #11
                      Is it synchronized

                      I would ask whether the code below is properly synchronized?
                      I'm afraid that not, because the ctx variable is not volatile nor the access to it is synchronized?


                      Originally posted by haninaguib View Post
                      Ok so here is a solution (got it from another post in this forum)
                      In the spring context I load a SpringContext object

                      Code:
                      import org.springframework.beans.BeansException;
                      import org.springframework.context.ApplicationContext;
                      import org.springframework.context.ApplicationContextAware;
                      
                      public class SpringContext implements ApplicationContextAware {
                      	private static ApplicationContext ctx;
                      	
                      	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
                      		ctx = applicationContext;
                      	}
                      	
                      	public static ApplicationContext getContext() { return ctx; }
                      	
                      }
                      Then in my soap service implementation I can get the spring context
                      Code:
                              ....
                              Object aBean = SpringContext.getContext().getBean("aBean");
                              .....
                      I know this is not ideal, so if someone knows the 'proper way' please let me know.

                      Hani

                      Comment

                      Working...
                      X