axis2 1.6.1 与项目整合

 1、在web.xml加入如下配置

<servlet > 
	     <servlet-name>AxisServlet</servlet-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>

 

2、将axis2/WEB-INF下的modules、service和conf文件件拷至工程的WEB-INF目录下。(modules和conf可选)

把lib下的jar包拷过去

最精简jar包 参考 http://mtvwang.iteye.com/blog/506299

以下是我的项目中新加的lib

axis2整合spring项目lib

拷贝axis2-web页面文件到工程(可方便管理)

 

3、新加一个服务 参考 http://mtvwang.iteye.com/blog/506299

与spring整合时service.xml中这样配置

<parameter name="ServiceObjectSupplier">  
        org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier   
</parameter>  
<parameter name="SpringBeanName">此处填写spring中配置的bean</parameter>

 

4、如果要使用axis2的后台管理功能,找到下载的war包中相关class放到部署环境中"axis2\WEB-INF\classes\org"

并在web.xml中加入AxisAdminServlet的相关配置。【注意在conf/axis2.xml中修改用户名和密码确保安全】

 

5、axis2客户端提供异步调用功能,从其它地方拷贝的示例,暂时未测试

import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class RPCAsyncClient
{
public static void main(String[] args) throws Exception
{
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(
"http://localhost:8080/axis2/services/myService");
options.setTo(targetEPR);
Object[] opAddEntryArgs = new Object[]{};
QName opAddEntry = new QName("http://service", "getName");
serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs,
new org.apache.axis2.client.async.AxisCallback()
{
@Override
public void onComplete()
{
}
@Override
public void onError(Exception arg0)
{
}                    }
@Override
public void onFault(MessageContext arg0)
{
}
@Override
public void onMessage(MessageContext mc)
{
//  输出返回值
System.out.println(mc.getEnvelope().getFirstElement()
.getFirstElement().getFirstElement().getText());
}
});
System.out.println("异步调用!");
//  阻止程序退出
System.in.read();
}
}  

 

Axis2默认把Service类中所有的public方法都发布成web service的operation(就是对外公布的ws接口)
在services.xml用如下方法可以排除不需要公开的public方法

参考http://desert3.iteye.com/blog/801339

<!-- 排除setBusiness001 -->  
<excludeOperations>  
         <operation>setBusiness001</operation>  
</excludeOperations>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值