2016-09-20 76 views
0

클라이언트를 만들지 않고 기존 웹 서비스를 호출해야합니다. 아래처럼 동적 인 클라이언트를 생성하기 위해 AXIS apache를 사용했습니다.URL 인수가있는 동적 웹 서비스 호출

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) 

아무도 아이디어가 있습니까? 축 버전 1.4 및 JDK 1.6

미리 감사드립니다.

답변

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);