Thursday, February 3, 2011

How to get the operation list from a given WSDL Uri

Today i needed to list the operation of a given WSDL uri. I went through the axis2 source code.. and  just found some code block in the CodeGenerationEngine class. Following is the java code that modified.. You want to have the axis2 and wsdl4j jars in your class path...

import org.apache.axis2.AxisFault;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
import org.apache.axis2.wsdl.codegen.CodeGenerationEngine;
import org.apache.axis2.wsdl.codegen.CodeGenerationException;

import java.util.Iterator;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;

public class WSDLToOperation {


    public static void main(String args[]) throws CodeGenerationException, WSDLException, AxisFault {

        String wsdlUri = "http://10.100.1.162:9764/services/echo?wsdl";

        CodeGenConfiguration codeGenConfiguration = null;

        CodeGenerationEngine codeGenerationEngine  = new CodeGenerationEngine(codeGenConfiguration);
        Definition wsdl4jDef = codeGenerationEngine.readInTheWSDLFile(wsdlUri);

        WSDL11ToAxisServiceBuilder wsdl11ToAxisServiceBuilder = new
                WSDL11ToAxisServiceBuilder(wsdl4jDef, null, null, false);

        AxisService axisService = wsdl11ToAxisServiceBuilder.populateService();

        Iterator iterator = axisService.getOperations();

        while (iterator.hasNext()) {
            AxisOperation operation  =  (AxisOperation) iterator.next();
            System.out.println(operation.getName().getLocalPart());
        }

    }
}




No comments:

Post a Comment