zoukankan      html  css  js  c++  java
  • 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+"--------------");
      } 

  • 相关阅读:
    MSXML应用总结
    MsXml创建和解析XML示例
    解决IAR无法跳转的问题
    总结4
    1012
    1010
    acm学习总结
    1005
    1004
    1006
  • 原文地址:https://www.cnblogs.com/loughofdragon/p/webservice.html
Copyright © 2011-2022 走看看