集成Spring和Axis- -

集成Spring Framework和Axis的一个简单方案,使Axis Web服务引擎可以使用Spring的IoC容器和AOP技术。要使用SpringProvider,Axis的server-config.wsdd配置例子如下:
<service name="SpringTestService" provider="java:SPRING">
<parameter name="beanName" value="springTest"/>
<parameter name="allowedMethods" value="*"/>
</service>

配置Spring的applicationContext.xml如下:
<beans>
<bean id="springTest" class="org.samples.SpringAxisTest"/>
</beans>

以下是集成Spring Framework和Axis引擎的类结构图,可以使用同样的方法集成Axis和其他IoC容器(如PicoContainer)。





以上类图中,紫色的是Spring Framework原有的类;草绿和天蓝色的类是Axis原有的类,其中草绿色的类需要做些修改;只有橙色的是需要开发的类。以下是SpringProvider类的代码片断:

public class SpringProvider extends RPCProvider {
protected static Log log = LogFactory.getLog(SpringProvider.class.getName());

public static final String OPTION_BEANNAME = "beanName";

protected Object makeNewServiceObject(MessageContext msgContext, String clsName) throws Exception {
String beanName = getStrOption(OPTION_BEANNAME, msgContext.getService());
return getService(beanName, msgContext);
}

protected String getServiceClassNameOptionName() {
return OPTION_BEANNAME;
}

protected Object getService(String beanName, MessageContext context) throws AxisFault {
ApplicationContext appContext = getAppContext(context);
if (appContext == null) {
log.fatal("Spring ApplicationContext is NULL.");
throw new AxisFault("get Spring ApplicationContext error.");
}

Object bean = appContext.getBean(beanName);
if (bean == null) {
log.error("bean named:" + beanName + " is NULL");
throw new AxisFault("bean named:" + beanName + " is NULL");
}
return bean;
}

protected String getStrOption(String optionName, Handler service) {
String value = null;
if (service != null)
value = (String) service.getOption(optionName);
if (value == null)
value = (String) getOption(optionName);
return value;
}

protected Class getServiceClass(String beanName, SOAPService service, MessageContext msgContext) throws AxisFault {
ConfigurableListableBeanFactory beanFactory = getBeanFactory(msgContext);
if (beanFactory == null) {
log.error("BeanFactory is NULL");
throw new AxisFault("BeanFactory is NULL");
}
Object bean = beanFactory.getBeanDefinition(beanName);
return bean.getClass();
}

protected XmlWebApplicationContext getAppContext(MessageContext msgContext) {
HttpServlet servlet = (HttpServlet) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLET);
ServletContext servletContext = servlet.getServletContext();
XmlWebApplicationContext appContext = (XmlWebApplicationContext) servletContext
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
return appContext;
}

private final ConfigurableListableBeanFactory getBeanFactory(MessageContext msgContext) {
XmlWebApplicationContext appContext = getAppContext(msgContext);
return appContext.getBeanFactory();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值