webservice wsdd发布调试报错org.xml.sax.SAXException问题解决

问题描述:
Axis采用wsdd方式暴露接口时,由于服务端入参为Hashmap,客户端使用soapui调试时报错:<faultstring>org.xml.sax.SAXException: No deserializer for { http://www.w3.org/2001/XMLSchema}anyType</faultstring>
客户端采用代码方式报错:
AxisFault
faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Bad types (class java.lang.String -&gt; class java.util.HashMap)
faultActor:
faultNode:
faultDetail:
{ http://xml.apache.org/axis/}hostname:我的主机名
 
org.xml.sax.SAXException: Bad types (class java.lang.String -> class java.util.HashMap)
 
解决:报错原因客户端入参类型和服务端暴露接口入参类型不匹配

Soapui:

<item xsi:type="x-:mapItem">
               <key xsi:type="xsd:anyType">woqu</key>
               <value xsi:type="xsd:anyType">第三方</value>
            </item
改为

<item xsi:type="x-:mapItem">
               <key>woqu</key>
               <value>第三方</value>
            </item>
即可!

客户端代码:

Map reqmap = new HashMap();
reqmap.put("woqu", "我了个去");
String result=(String)call.invoke(new Object[]{reqmap});

即可!
 
下面介绍wsdd方式发布流程:

1:引入jar-maven方式
<!-- Axis -->
<dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-saaj</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.4</version>
        </dependency>


2:web.xml配置service拦截
<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
    <load-on-startup>15</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

3:配置wsdd文件放在WEB-INF下面
server-config.wsdd
<?xml version="1.0" encoding="UTF-8"?>
 
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  <!-- 对外公布有关权限的服务 --> 
  <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/> 
  <transport name="http">
    <requestFlow>
      <handler type="URLMapper"/>
    </requestFlow>
  </transport> 
 
  <service name="ardo" provider="java:RPC">
     <parameter name="className" value="com.code.core.service.impl.Ardo"/>
     <parameter name="allowedMethods" value="*"/>    
<namespace>http://10.143.1.2:8080/PRO/services/ardo</namespace>
  </service>
 
</deployment>
其中className指向接口实现类。
 
4:编写接口实现类
public class Ardo implements Serializable {
private static final long serialVersionUID = 1L;
 
public String test(HashMap changeInfo)  {
System.out.println("----------test---");
String result = changeInfo.get("woqu").toString();
return result;
}
}


5:客户端测试类
import java.util.HashMap;
import java.util.Map;
 
import javax.xml.namespace.QName;
 
import org.apache.axis.client.Call; 
import org.apache.axis.client.Service; 
 
public class AxisTest {
public static void main(String[] args) { 
        try { 
String endpoint = " http://10.143.1.2:8080/PRO/services/ardo " ;
            Service service = new Service() ; 
             
            Call call = (Call) service.createCall() ; 
            call.setTargetEndpointAddress(endpoint) ; 
            call.setOperationName(new QName(null,"test")) ;//ws方法名 
            //一个输入参数,如果方法有多个参数,复制多条该代码即可,参数传入下面new Object后面 
            call.addParameter("woqu",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN) ; 
            //call.addParameter("parameter2",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN) ; 
            //call.setReturnType(XMLType.XSD_STRING) ; 
            call.setUseSOAPAction(true) ; 
// call.setSOAPActionURI("http://172.20.35.123:6110/cea-ws/services/ChangeMemberPinService");
            //String result = (String) call.invoke(new Object[]{str,"Parameter two"}) ;
            Map reqmap = new HashMap();
            reqmap.put("woqu", "我了个去");
            String result=(String)call.invoke(new Object[]{reqmap}); 
             
            System.out.println(result); 
             
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    }
}

6:测试结果
OK!输出:
我了个去







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值