Recently, our clients provided a web service which was implemented by RCP way using SOAP1.1 protocol. Everything was smooth before we invoked service. I used WSDL2Java togenerate STUB, SEI, Locator and entity. Then I did unit test for testingservice was available or not. I got below strackTrace:
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: JAXRPCTIE01: caught exception while handling request: deserialization error: deserialization error: java.lang.NumberFormatException: For input string: ""
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:JAXRPCTIE01: caught exception while handling request: deserialization error: deserialization error: java.lang.NumberFormatException: For input string: ""
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1528)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
You can see all Axis error has almost same stack trace, you do not know what has happened. Then I began my Google journey(Here I want to complain Baidu, search result is bullshit), On internet I found a lot of same error have exact same strack trace, no one answered this why. So have no idea, only thing I can do is to debug by myself using source code downloading from Apache. After I debugged, I found a funny thing all the Integer node had been translated as a reference node, like this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:changeAListByB soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://A/webservices">
<in0 soapenc:arrayType="ns2:ChangeAParameters[1]" xsi:type="soapenc:Array" xmlns:ns2="http://A/input" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<in0 href="#id0"/>
</in0>
</ns1:changeAListByB>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ChangeAParameters" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns3="http://input">
<parameters1 xsi:type="xsd:string">123</parameters1>
<parameters2 xsi:type="xsd:int" xsi:nil="true"/>
<parameters3 xsi:type="xsd:string">123</parameters3>
<parameters4 href="#id1"/>
<parameters5 xsi:type="xsd:string">RCPGR</parameters5>
<parameters6 xsi:type="xsd:string">12/12/1982</parameters6>
<parameters7 xsi:type="xsd:int" xsi:nil="true"/>
</multiRef>
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">12345</multiRef>
</soapenv:Body>
</soapenv:Envelope>
We know that int is primitive, so Axis should not recognized this as reference, Then I went to Apache site, found this is a defect.
https://issues.apache.org/jira/browse/AXIS-1886
https://issues.apache.org/jira/browse/AXIS-2077
Solutions:
Change method isPrimitive of org.apache.axis.encoding.SerializationContext
if (javaType.isPrimitive()) return true;
if (javaType == String.class) return true;
<strong>if (javaType == Integer.class)return true; // change like this, others are similar</strong>
if (Calendar.class.isAssignableFrom(javaType)) return true;
if (Date.class.isAssignableFrom(javaType)) return true;
if (HexBinary.class.isAssignableFrom(javaType)) return true;
if (Element.class.isAssignableFrom(javaType)) return true;
if (javaType == byte[].class) return true;