我需要在不创建客户端的情况下调用现有的Web服务。我使用AXIS apache生成如下的动态客户端。
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setEncodingStyle("targetNameSpace");
call.setTargetEndpointAddress(new java.net.URL("WSDLURL"));
call.setOperationName(new QName("targetNameSpace", "runJob"));
call.addParameter("arg0", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
String result = (String) call.invoke(new Object[] {"--context=Tokens"});
log.info("result: {}", result);
if (!result.equals("0")){
throw new MosApplicationError("Job Failed ");
}
} catch (Exception e){
throw new MosApplicationError("Talend job failed", e);
}
对于请求和响应对象,我的wsdl不使用除字符串之外的任何内容。运行此代码时出现以下错误:
11:59:29,424 ERROR [Call] 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:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.nex.mos.job.core.TalendJob.executeJob(TalendJob.java:56)
at com.nex.mos.job.core.BaseJob.execute(BaseJob.java:69)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
11:59:29,496 ERROR [MosErrorHandler] Error processing job in group 'Temporary' implemented by class 'class org.quartz.JobDetail'. Error message: Tal
end job failed
com.nex.mos.common.exception.MosApplicationError: Talend job failed
at com.nex.mos.job.core.TalendJob.executeJob(TalendJob.java:63)
at com.nex.mos.job.core.BaseJob.execute(BaseJob.java:69)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2470)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.nex.mos.job.core.TalendJob.executeJob(TalendJob.java:56)
Caused by: 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:2467)
有没有人有任何想法? Axis版本为1.4和jdk 1.6
提前致谢。
答案 0 :(得分:0)
我发现了问题。以前我无法正确读取WSDL文件。我的wsdl返回一个字符串数组但是在上面的代码中我将返回类型定义为字符串而不是字符串数组。所以添加这两行就解决了我的问题:)
//Return object is array of string
call.setReturnType(Constants.SOAP_ARRAY);
//Added to marshal and de-marshal the array of string
call.registerTypeMapping(String[].class, new QName(talendApplicationName,""), ArraySerializerFactory.class, ArrayDeserializerFactory.class);