问题描述:
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 -> 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>
<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;
}
}
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!输出:
我了个去