I write a cxf dynamic client to get data from wsdl url, belowing is my client:
public static String invoke(String wsdlUrl, String operationName, Object inputParams) {
try {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdlUrl);
Object[] result = client.invoke(operationName, inputParams);
return (String) result[0];
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
webservice document says the service should receive a param with xml-form string like:
<startDate>2023-11-10</startDate>
<endDate>2023-11-01</endDate>
<accessID>XXXX</accessID>
<accessPasswords>XXXXX</accessPasswords>
<customID>1</customID>
params when i invoke the service like belowing:
String salesResult = WebServiceClient.invoke(url, salesOperation, paramForSales);
url: http://59.41.111.229:9000/vendorService?wsdl
salesOperation: getSaleInfo
paramForSales: String like this
<startDate>2023-11-10</startDate><endDate>2023-11-01</endDate><accessID>XXXX</accessID><accessPasswords>XXXXX</accessPasswords><customID>1</customID>
an error occurs like:
org.apache.cxf.interceptor.Fault: Index: 1, Size: 1
at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:107)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:442)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:316)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:302)
at org.oval.ddi.ws.ws_client.WebServiceClient.invoke(WebServiceClient.java:22)
at org.oval.ddi.ws.data.GuoKongGuangZhouFetcher.execute(GuoKongGuangZhouFetcher.java:70)
at org.oval.ddi.ws.process.GuoKongGuangZhouConcreteProcess.execute(GuoKongGuangZhouConcreteProcess.java:30)
at org.oval.ddi.ws.WebServiceBootStrap.main(WebServiceBootStrap.java:43)
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.get(ArrayList.java:435)
at com.sinopharm_gz.vendorddi.GetSaleInfo_WrapperTypeHelper1.createWrapperObject(Unknown Source)
at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:91)
... 11 more
this webservice should return a xml-formed string, but null returned actually.
btw, where should i revise to make my webservice client more universal for all webservice?
im a java new learner, if you need more information of this problem, please ask me directly.
sincerely thanks to all developers' time!