“org.xml.sax.SAXException:SimpleDeserializer 遇到一个子元素,这不是预期的......”在 java 中调用 webservice 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13724200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:47:26  来源:igfitidea点击:

"org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected..." error while calling webservice in java

javaweb-servicesexceptionsaxruntime-error

提问by Shirish Herwade

I'm trying to call a web-service of opentaps from eclipse in java. I have the code

我正在尝试从 java 中的 eclipse 调用 opentaps 的 Web 服务。我有代码

Service service = new Service();
        Call call = (Call) service.createCall();

        call.setTargetEndpointAddress(new java.net.URL("url"));
        call.setOperationName(new QName("quickCreateCustomer", "quickCreateCustomer"));

        call.addParameter("emailAddress", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter("firstName", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter("lastName", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter("login.password", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter("login.username", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

        call.setReturnType(org.apache.axis.Constants.XSD_STRING);

        Object responseWS = call.invoke(new Object[] { "mail_id", "s", "h", "pwd", "user_name" });

        System.out.println("ReceivingResponse: " + (String) responseWS);

        output = call.getOutputParams();

but its giving run-time error,

但它给出了运行时错误,

- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
- Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT  expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2448)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at TriongleJava.main(TriongleJava.java:36)
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.

on the line

在线上

Object responseWS = call.invoke(new Object[] { "mail_id", "s", "h", "pwd", "user_name" });

As I'm new to Java, I don't know how to remove it and even I don't know cause of the error.

由于我是 Java 新手,我不知道如何删除它,甚至我也不知道错误的原因。

回答by Nisanth

Our team faced the same error while accessing webservices using axis 1.4.1 and issue was due to a higher version of JRE ie JRE 1.6.0_37.While using JRE 1.6.0 it started working in both Eclipse java project & Jetty web app.

我们的团队在使用轴 1.4.1 访问网络服务时遇到了同样的错误,问题是由于更高版本的 JRE,即 JRE 1.6.0_37。虽然使用 JRE 1.6.0,但它开始在 Eclipse java 项目和 Jetty Web 应用程序中工作。

Cheers, Nisanth

干杯,尼桑斯

回答by David Bullock

Seems like you're missing a runtime dependency on the JavaMailpackage (mail.jarand activation.jar).

似乎您缺少对JavaMail包(mail.jaractivation.jar)的运行时依赖项。