PDA

View Full Version : axis2 or how to get applicationContext information?



soawork
Jan 24th, 2006, 10:22 AM
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

Colin Yates
Jan 25th, 2006, 08:25 AM
Replied to in http://forum.springframework.org/showthread.php?t=21750

haninaguib
Jan 28th, 2006, 11:26 AM
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

haninaguib
Jan 28th, 2006, 01:39 PM
Ok so here is a solution (got it from another post in this forum)
In the spring context I load a SpringContext object



import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAwar e;

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


....
Object aBean = SpringContext.getContext().getBean("aBean");
.....


I know this is not ideal, so if someone knows the 'proper way' please let me know.

Hani

soawork
Jan 29th, 2006, 10:16 AM
Hi,

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

ychawla
Jul 21st, 2006, 10:04 AM
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

Colin Yates
Jul 21st, 2006, 02:49 PM
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/api/org/springframework/web/context/support/WebApplicationContextUtils.html.

sshaikhtraverse
Mar 13th, 2007, 02:55 PM
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.

hotwater
May 17th, 2007, 06:05 PM
Thank you. This is what I put in my constructor and it works:

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

ysbelman
Nov 1st, 2007, 07:57 PM
I am running Axis2 inside my webapp and it is configured finally where my services can get access to Spring Application context.

Directory structure:


./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


<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.Sprin gAppContextAwareObjectSupplier</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


<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.ContextLoaderListe ner
</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


package com.bla.bla;
import org.springframework.context.ApplicationContext;
import org.apache.axis2.extensions.spring.receivers.Appli cationContextHolder;
public class MyService {
public String sayHi(String text) {
ApplicationContext ctx = ApplicationContextHolder.getContext();
return "good deal: " + text;
}
}


url:


http://localhost/myApp/services/MyService

look_as
Feb 26th, 2008, 01:59 AM
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?



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



import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAwar e;

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


....
Object aBean = SpringContext.getContext().getBean("aBean");
.....


I know this is not ideal, so if someone knows the 'proper way' please let me know.

Hani