How to get SOAPAction from WSDL using Java

I am using the javax.wsdl package to parse a wsdl file.

I am not sure how to get the SOAPAction operation from the wsdl file.

I can get the javax.wsdl.Operation object using WSDLFactory. But I did not find a way to get the SOAPAction of this operation.

Does anyone have an idea on how to get it?

Thanks, Maviswa

+4
source share
1 answer

You need to get ExtensibilityElement that matches SOAPOperation and extract SOAPAction from it.

Take a simple WSDL example from the TempConvert web service and extract the SOAP action from its CelsiusToFahrenheit operation; I will go 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 a SOAP action for a 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()); } // .... } } 

Output:

 http://tempuri.org/CelsiusToFahrenheit 
+9
source

Source: https://habr.com/ru/post/1379768/


All Articles