Reputation: 81
I am using javax.wsdl package for parsing the wsdl file.
I am not sure how to get the SOAPAction of an operation from the wsdl file.
I am able to get the javax.wsdl.Operation object using the WSDLFactory. But I find no way to get the SOAPAction of that operation.
Anybody has idea on how to get it?
Thanks, Maviswa
Upvotes: 5
Views: 15198
Reputation:
You need to get the ExtensibilityElement
that corresponds to the SOAPOperation
and extract the SOAPAction
from there.
Let's take a simple WSDL as example, from the TempConvert Web Service, and extract the SOAP action from its CelsiusToFahrenheit
operation; I'm going after this part:
<wsdl:binding name="TempConvertSoap" type="tns:TempConvertSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="FahrenheitToCelsius">
<soap:operation soapAction="http://tempuri.org/FahrenheitToCelsius" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CelsiusToFahrenheit">
<soap:operation soapAction="http://tempuri.org/CelsiusToFahrenheit" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
The following code prints the value of the SOAP action for the CelsiusToFahrenheit
operation:
WSDLFactory factory = WSDLFactory.newInstance();
WSDLReader reader = factory.newWSDLReader();
Definition definition = reader.readWSDL("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl");
Binding binding = definition.getBinding(new QName("http://tempuri.org/", "TempConvertSoap"));
BindingOperation operation = binding.getBindingOperation("CelsiusToFahrenheit", null, null);
List extensions = operation.getExtensibilityElements();
if (extensions != null) {
for (int i = 0; i < extensions.size(); i++) {
ExtensibilityElement extElement = (ExtensibilityElement) extensions.get(i);
// ....
if (extElement instanceof SOAPOperation) {
SOAPOperation soapOp = (SOAPOperation) extElement;
System.out.println(soapOp.getSoapActionURI());
}
// ....
}
}
The output is this:
http://tempuri.org/CelsiusToFahrenheit
Upvotes: 10