• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
天使龙
博客园    首页    新随笔    联系   管理    订阅  订阅
WebService using Spring throwed org.xml.sax.SAXException: Bad envelope tag: htm

最近在公司做一个项目用到Spring中包涵Webservice时,服务端部署成功,也就是http://127.0.0.1:8080/itzc/AxisDeviceServerImpl.jws?wsdl可以访问,但客户端调用时老报org.xml.sax.SAXException: Bad envelope tag:  htm异常,网上找了半天,发现很多网友碰到这种情况,但都没有解决的,最后自己攻克了,现在贴出来给供大家分享

问题:

 原来是自己的spring中的过滤权限的问题,在调用服务的访问路径时,被spring的顾虑器给拦截了,最后返回一个空的XML文件,当然解析不了,就会报

org.xml.sax.SAXException: Bad envelope tag:  htm错误;

解决方法:

 可以在spring的文件中增加一个   <intercept-url pattern="/AxisDeviceServerImpl.jws" filters="none"/>让spring不拦截以这个路径的访问。

 也可在客户端直接增加两行验证代码去过滤掉

 call.getMessageContext().setUsername("module");  //用户名验证
 call.getMessageContext().setPassword("123456");

  客户端调用代码

public class TestAxisDevice {
 
  public void axisDevice() throws Exception{
  String serverURL = "http://127.0.0.1:8080/itzc/AxisDeviceServerImpl.jws?wsdl";
  String serverMethod = "getChangeNoteByYunWei";
  String resString="";
  // 设置WEBSERVICE
  Service service =new Service();
  Call call=(Call)service.createCall();
  call.setTargetEndpointAddress(new java.net.URL(serverURL));
  call.setOperationName(new QName(serverURL,serverMethod));   
//  call.getMessageContext().setUsername("module");  //用户名验证
//  call.getMessageContext().setPassword("123456");

  // 调用远程接口
  String[] aa=new String[]{"123456","2010-04-18","1","1","OK","5","2010-05-04"
  ,"孔祥泽","123456","魏冬华","123456"};
  try {
    resString=(String)call.invoke(aa);
  } catch (AxisFault e) {   
     System.out.println("faultreason---------------"+e.getFaultReason());
  }
  System.out.println("-----------"+resString+"--------------");
  } 

posted on 2011-04-22 14:42  天使龙  阅读(8596)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3