An update -
I want to call a web service from my component. The called web service might have different names, therefore I don't want to use the proxy class way.
I am parsing the WSDL file and obtaining the different parameters. But i am having problem in passing the parameters(receiving as well) to the web service and i am not able to find any good refernce on the internet, i am getting the following exception:
org.xml.sax.SAXException: Invalid element in javax.xml.rpc.namespace.QName - inputsobj
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(Unknown Source)
at org.apache.axis.AxisFault.makeFault(Unknown Source)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(Unknown Source)
at org.apache.axis.message.SAX2EventRecorder.replay(Unknown Source)
at org.apache.axis.message.MessageElement.publishToHandler(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.message.RPCElement.deserialize(Unknown Source)
at org.apache.axis.message.RPCElement.getParams(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at javaapplication17.Invoke.axisInvoke(Invoke.java:639)
at javaapplication17.Invoke.parseWSDL(Invoke.java:423)
at javaapplication17.Invoke.run(Invoke.java:76)
at javaapplication17.Invoke.main(Invoke.java:64)
at org.apache.axis.client.Call.invoke(Unknown Source)
Error invoking service : org.xml.sax.SAXException: Invalid element in javax.xml.rpc.namespace.QName - inputsobj
at javaapplication17.Invoke.axisInvoke(Invoke.java:639)
at javaapplication17.Invoke.parseWSDL(Invoke.java:423)
at javaapplication17.Invoke.run(Invoke.java:76)
at javaapplication17.Invoke.main(Invoke.java:64)
Caused by: org.xml.sax.SAXException: Invalid element in javax.xml.rpc.namespace.QName - inputsobj
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(Unknown Source)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(Unknown Source)
at org.apache.axis.message.SAX2EventRecorder.replay(Unknown Source)
at org.apache.axis.message.MessageElement.publishToHandler(Unknown Source)
at org.apache.axis.message.RPCElement.deserialize(Unknown Source)
at org.apache.axis.message.RPCElement.getParams(Unknown Source)
... 7 more
Following is the code snippet and the passed values to the function:
Parameters passed to the
test function:
targetNamespace = "http://V5_0.testcenter8"
serviceName = "testcenter8_V5_0WebServiceHttpSoap11Endpoint"
portName = "http://V5_0.testcenter8:testcenter8_V5_0WebService"
operationName = "executeRuleset"
arrListParameters; //obtained by parsing the XSD using XMLSchema(XSD created from wsdl types tag)
implURI = "http://192.168.56.89:8080/axis2/services/testcenter8_V5_0WebService?wsdl"
test function:
NOTE:some things have been hardcoded.
public void axisInvoke(
String targetNamespace, String serviceName, String portName,
String operationName, ArrayList<Parameter> arrListParameters, String implURI)
{
try
{
// first, due to a funny Axis idiosyncracy we must strip portName of
// it's target namespace so we can pass it in as targetNamespace, localPart
int index = portName.indexOf(":", portName.indexOf("http://") + new String("http://").length());
String portNamespace = portName.substring(0, index);
portName = portName.substring(index == 0 ? index : index + 1); // to strip the :
javax.xml.rpc.namespace.QName serviceQN = new javax.xml.rpc.namespace.QName(portNamespace, portName);
org.apache.axis.client.Service service = new org.apache.axis.client.Service(new URL(implURI), serviceQN);
javax.xml.rpc.namespace.QName portQN = new javax.xml.rpc.namespace.QName(targetNamespace, serviceName);
// This Call object will be used the invocation
Call call = (Call) service.createCall();
// Now make the call...
System.out.println("Invoking service >> " + serviceName + " <<...");
//call.setOperation(portQN, operationName); //do not work
call.setOperationName(new javax.xml.rpc.namespace.QName("http://V5_0.testcenter8", "executeRuleset"));
call.removeAllParameters();// why there is parameters already added to the list of parameters
//call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
ArrayList<Object> arrListInputParameters = new ArrayList<Object>();
for(int i = 0; i < arrListParameters.size(); i++)
{
String strParamName = arrListParameters.get(i).strParamName;
String strParamType = arrListParameters.get(i).strParamType;
String strNameSpaceURI = arrListParameters.get(i).strParamNameSpaceURI;
if(strNameSpaceURI.compareToIgnoreCase("http://www.w3.org/2001/XMLSchema") == 0)
{
boolean isInParam = true;
if(strParamName.compareToIgnoreCase("cabinetName") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("testcenter8");
}
else if(strParamName.compareToIgnoreCase("loginReqd") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_BOOLEAN, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add(false);
}
else if(strParamName.compareToIgnoreCase("password") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("D@nger0us");
}
else if(strParamName.compareToIgnoreCase("userName") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("sanjeev");
}
else if(strParamName.compareToIgnoreCase("description") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("Change Address");
}
else if(strParamName.compareToIgnoreCase("subject") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("Credit Card");
}
else if(strParamName.compareToIgnoreCase("category") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("");
isInParam = false;
}
else if(strParamName.compareToIgnoreCase("massRequestType") == 0)
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_INTEGER, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add((int) 1);
isInParam = false;
}
else
{
call.addParameter(new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
arrListInputParameters.add("");
isInParam = false;
}
/*if(isInParam)
{
call.addParameter(strParamName, org.apache.axis.Constants.XSD_STRING, ParameterMode.PARAM_MODE_INOUT);
//call.addParameter(strParamName, new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), ParameterMode.PARAM_MODE_INOUT);
}
else
{
call.addParameter(strParamName, new javax.xml.rpc.namespace.QName(strNameSpaceURI, strParamName), ParameterMode.PARAM_MODE_INOUT);
}*/
}
}
/*inputParams = new Object[arrListInputParameters.size() + 1];
inputParams[0] = "";
for(int i = 1; i <= arrListInputParameters.size(); i++)
{
inputParams[i] = arrListInputParameters.get(i - 1);
}*/
inputParams = new Object[arrListInputParameters.size()];
for(int i = 0; i < arrListInputParameters.size(); i++)
{
inputParams[i] = arrListInputParameters.get(i);
}
call.setReturnType(org.apache.axis.Constants.XSD_QNAME);
//call.setReturnType(org.apache.axis.Constants.XSD_ANYTYPE);
call.setTargetEndpointAddress(new URL("http://192.168.56.89:8080/axis2/services/testcenter8_V5_0WebService.testcenter8_V5_0WebServiceHttpSoap11Endpoint"));
Object ret = call.invoke(inputParams);
System.out.println("Result returned from call to " + serviceName + " -- " + ret);
System.out.println("Finished");
}
catch(java.net.MalformedURLException e)
{
System.out.println("Error invoking service : " + e);
e.printStackTrace();
}
catch(javax.xml.rpc.ServiceException e2)
{
System.out.println("Error invoking service : " + e2);
e2.printStackTrace();
}
catch(java.rmi.RemoteException e3)
{
System.out.println("Error invoking service : " + e3);
e3.printStackTrace();
}
}
WSDL file:
WSDL file:
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://V4_0.testcenter8" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax258="http://testcenter8.V4_0.testcenter8/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ax257="http://V4_0.testcenter8/xsd" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://V4_0.testcenter8">
<wsdl:types>
<xs:schema xmlns:ax260="http://V4_0.testcenter8/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://V4_0.testcenter8">
<xs:import namespace="http://V4_0.testcenter8/xsd" />
<xs:element name="executeRuleset">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="param0" nillable="true" type="ax257:testcenter8_V4_0_Req" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="executeRulesetResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax257:testcenter8_V4_0_Resp" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:ax259="http://testcenter8.V4_0.testcenter8/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://V4_0.testcenter8/xsd">
<xs:import namespace="http://testcenter8.V4_0.testcenter8/xsd" />
<xs:complexType name="testcenter8_V4_0_Req">
<xs:sequence>
<xs:element minOccurs="0" name="cabinetName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="inputsobj" nillable="true" type="ax258:Inputs" />
<xs:element minOccurs="0" name="loginReqd" type="xs:boolean" />
<xs:element minOccurs="0" name="outputsobj" nillable="true" type="ax258:Outputs" />
<xs:element minOccurs="0" name="password" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="userName" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="testcenter8_V4_0_Resp">
<xs:sequence>
<xs:element minOccurs="0" name="inputsobj" nillable="true" type="ax258:Inputs" />
<xs:element minOccurs="0" name="outputsobj" nillable="true" type="ax258:Outputs" />
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://testcenter8.V4_0.testcenter8/xsd">
<xs:complexType name="Inputs">
<xs:sequence>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="subject" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Outputs">
<xs:sequence>
<xs:element minOccurs="0" name="category" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="massRequestType" type="xs:int" />
<xs:element minOccurs="0" name="subCategory" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="executeRulesetRequest">
<wsdl:part name="parameters" element="ns:executeRuleset" />
</wsdl:message>
<wsdl:message name="executeRulesetResponse">
<wsdl:part name="parameters" element="ns:executeRulesetResponse" />
</wsdl:message>
<wsdl:portType name="testcenter8_V4_0WebServicePortType">
<wsdl:operation name="executeRuleset">
<wsdl:input message="ns:executeRulesetRequest" wsaw:Action="urn:executeRuleset" />
<wsdl:output message="ns:executeRulesetResponse" wsaw:Action="urn:executeRulesetResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="testcenter8_V4_0WebServiceSoap11Binding" type="ns:testcenter8_V4_0WebServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="executeRuleset">
<soap:operation soapAction="urn:executeRuleset" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="testcenter8_V4_0WebServiceSoap12Binding" type="ns:testcenter8_V4_0WebServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="executeRuleset">
<soap12:operation soapAction="urn:executeRuleset" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="testcenter8_V4_0WebServiceHttpBinding" type="ns:testcenter8_V4_0WebServicePortType">
<http:binding verb="POST" />
<wsdl:operation name="executeRuleset">
<http:operation location="testcenter8_V4_0WebService/executeRuleset" />
<wsdl:input>
<mime:content type="text/xml" part="executeRuleset" />
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="executeRuleset" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="testcenter8_V4_0WebService">
<wsdl:port name="testcenter8_V4_0WebServiceHttpSoap11Endpoint" binding="ns:testcenter8_V4_0WebServiceSoap11Binding">
<soap:address location="http://192.168.56.89:8080/axis2/services/testcenter8_V4_0WebService.testcenter8_V4_0WebServiceHttpSoap11Endpoint/" />
</wsdl:port>
<wsdl:port name="testcenter8_V4_0WebServiceHttpSoap12Endpoint" binding="ns:testcenter8_V4_0WebServiceSoap12Binding">
<soap12:address location="http://192.168.56.89:8080/axis2/services/testcenter8_V4_0WebService.testcenter8_V4_0WebServiceHttpSoap12Endpoint/" />
</wsdl:port>
<wsdl:port name="testcenter8_V4_0WebServiceHttpEndpoint" binding="ns:testcenter8_V4_0WebServiceHttpBinding">
<http:address location="http://192.168.56.89:8080/axis2/services/testcenter8_V4_0WebService.testcenter8_V4_0WebServiceHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>