Find Some sample examples for parsing of wsdl url using wsdl4j

4.9k Views Asked by At

Please somebody help me to find some sample examples for parsing for wsdl url using wsdl4j API.

Thanks

1

There are 1 best solutions below

1
Ratha On

Try like this;

public Definition readWSDLFile() throws  WSDLException {
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        // switch off the verbose mode
        reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        reader.setFeature("javax.wsdl.importDocuments", true);

        Definition wsdlDefinition;
        if (log.isDebugEnabled()) {
            log.debug("Reading  the WSDL. Base uri is " + baseURI);
        }
        wsdlDefinition = reader.readWSDL(baseURI);
        return wsdlDefinition;

    }

Using the Definition you can access the operation, service objects.. to access a service address location;

private void setServiceDefinition(Definition definition) throws Exception {

        Map serviceMap = definition.getAllServices();
        Iterator serviceItr = serviceMap.entrySet().iterator();
        URL addressURI = null;
        try {
            while (serviceItr.hasNext()) {
                Map.Entry svcEntry = (Map.Entry) serviceItr.next();
                Service svc = (Service) svcEntry.getValue();
                Map portMap = svc.getPorts();
                Iterator portItr = portMap.entrySet().iterator();
                while (portItr.hasNext()) {
                    Map.Entry portEntry = (Map.Entry) portItr.next();
                    Port port = (Port) portEntry.getValue();
                    ExtensibilityElement extensibilityElement = (ExtensibilityElement) port.getExtensibilityElements()
                                                                                           .get(0);

                    addressURI = new URL(getAddressUrl(extensibilityElement));

                }
            }

Here is a sample i have written, May be useful to you.