Search in sources :

Example 1 with WSDL4JWrapper

use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.

the class ServiceDescriptionImpl method setWSDLDefinitionOnDBC.

/**
 * This method accepts a location of a WSDL document and attempts to
 * load and set the WSDL definition on the DBC object.
 * @param wsdlLocation
 */
private void setWSDLDefinitionOnDBC(String wsdlLocation) {
    if (log.isDebugEnabled()) {
        log.debug("Attempting to load WSDL file from location specified in annotation: " + wsdlLocation);
    }
    if (composite.getClassLoader() == null) {
        if (log.isDebugEnabled()) {
            log.debug("A classloader could not be found for class: " + composite.getClassName() + ". The WSDL file: " + wsdlLocation + " will not be " + "processed, and the ServiceDescription will be built from " + "annotations");
        }
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("Attempting to read WSDL: " + wsdlLocation + " for web " + "service endpoint: " + composite.getClassName());
        }
        if (log.isDebugEnabled()) {
            if (configContext != null) {
                log.debug("new WSDL4JWrapper-ConfigContext not null5");
            } else {
                log.debug("new WSDL4JWrapper-ConfigContext null5");
            }
        }
        URL url = getWSDLURL(wsdlLocation);
        ConfigurationContext cc = composite.getConfigurationContext();
        if (cc != null) {
            this.wsdlWrapper = new WSDL4JWrapper(url, cc, this.catalogManager);
        } else {
            // Probably shouldn't get here.  But if we do, use a memory sensitive
            // wsdl wrapper
            this.wsdlWrapper = new WSDL4JWrapper(url, this.catalogManager, true, 2);
        }
        composite.setWsdlDefinition(wsdlWrapper.getDefinition());
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("The WSDL file: " + wsdlLocation + " for class: " + composite.getClassName() + "could not be processed. The ServiceDescription will be built from " + "annotations");
        }
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) ConnectException(java.net.ConnectException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) WSDLException(javax.wsdl.WSDLException) WebServiceException(javax.xml.ws.WebServiceException)

Example 2 with WSDL4JWrapper

use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.

the class Axis2EndpointReferenceFactoryImpl method createEndpointReference.

/*
     *  (non-Javadoc)
     * @see org.apache.axis2.jaxws.addressing.factory.Axis2EndpointReferenceFactory#createEndpointReference(java.lang.String, javax.xml.namespace.QName, javax.xml.namespace.QName, java.lang.String, java.lang.String)
     */
public EndpointReference createEndpointReference(String address, QName serviceName, QName portName, String wsdlDocumentLocation, String addressingNamespace) {
    EndpointReference axis2EPR = null;
    if (address != null) {
        if (serviceName == null && portName != null) {
            throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr", portName.toString()));
        }
        axis2EPR = createEndpointReference(address);
    } else if (serviceName != null && portName != null) {
        axis2EPR = createEndpointReference(serviceName, portName);
    } else {
        throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr2"));
    }
    // should simply use those.
    try {
        // This code is locate here instead of in the createEndpointReference(QName, QName)
        // method so that if the address is also specified the EPR metadata will still be
        // filled in correctly.
        EndpointReferenceUtils.addService(axis2EPR, serviceName, portName, addressingNamespace);
        if (wsdlDocumentLocation != null) {
            URL wsdlURL;
            try {
                wsdlURL = new URL(wsdlDocumentLocation);
            } catch (MalformedURLException e) {
                // just to keep it clean:
                if (axis2EPR.getAddress().endsWith("/") && wsdlDocumentLocation.startsWith("/")) {
                    wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation.substring(1);
                } else if (axis2EPR.getAddress().endsWith("/")) {
                    String eprAddress = axis2EPR.getAddress();
                    wsdlDocumentLocation = eprAddress.substring(0, eprAddress.length() - 1) + wsdlDocumentLocation;
                } else {
                    wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation;
                }
            }
            wsdlURL = new URL(wsdlDocumentLocation);
            // This is a temporary usage, so use a memory sensitive wrapper
            WSDLWrapper wrapper = new WSDL4JWrapper(wsdlURL, true, 2);
            if (serviceName != null) {
                QName serviceNameNoTrailingSlash = new QName("");
                // TODO: why in the world would we have to do this?
                if (serviceName.getNamespaceURI().endsWith("/")) {
                    String ns = serviceName.getNamespaceURI();
                    serviceNameNoTrailingSlash = new QName(ns.substring(0, ns.length() - 1), serviceName.getLocalPart());
                }
                if ((wrapper.getService(serviceName) == null) && (wrapper.getService(serviceNameNoTrailingSlash) == null)) {
                    throw new IllegalStateException(Messages.getMessage("MissingServiceName", serviceName.toString(), wsdlDocumentLocation));
                }
                if (portName != null) {
                    String[] ports = wrapper.getPorts(serviceName);
                    // search the other name.  TODO: again, why do we have to do this?
                    if (ports == null) {
                        ports = wrapper.getPorts(serviceNameNoTrailingSlash);
                    }
                    String portLocalName = portName.getLocalPart();
                    boolean found = false;
                    if (ports != null) {
                        for (String port : ports) {
                            // TODO: axis2 perhaps is deploying with "TypeImplPort" appended, but not reading/honoring the WSDL?
                            if (port.equals(portLocalName) || (port + "TypeImplPort").equals(portLocalName)) {
                                log.debug("found port: " + port);
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found) {
                        throw new IllegalStateException(Messages.getMessage("MissingPortName", portName.toString(), wsdlDocumentLocation));
                    }
                    log.debug("Setting wsdlDocumentLocation to " + wsdlDocumentLocation + " for EndpointReference at port " + portName);
                    EndpointReferenceUtils.addLocation(axis2EPR, portName.getNamespaceURI(), wsdlDocumentLocation, addressingNamespace);
                }
            }
        }
    } catch (IllegalStateException ise) {
        throw ise;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointRefCreationError"), e);
    }
    return axis2EPR;
}
Also used : MalformedURLException(java.net.MalformedURLException) WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) QName(javax.xml.namespace.QName) URL(java.net.URL) WSDLWrapper(org.apache.axis2.jaxws.util.WSDLWrapper) MalformedURLException(java.net.MalformedURLException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with WSDL4JWrapper

use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.

the class SchemaReaderTests method testSchemaReader.

public void testSchemaReader() {
    SchemaReaderImpl sri = new SchemaReaderImpl();
    String wsdlLocation = "/test-resources/wsdl/shapes.wsdl";
    URL url = null;
    try {
        try {
            String baseDir = new File(System.getProperty("basedir", ".")).getCanonicalPath();
            wsdlLocation = new File(baseDir + wsdlLocation).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
        File file = new File(wsdlLocation);
        url = file.toURI().toURL();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
    try {
        WSDL4JWrapper w4j = new WSDL4JWrapper(url);
        Definition wsdlDef = w4j.getDefinition();
        assertNotNull(wsdlDef);
        Set<String> pkg = sri.readPackagesFromSchema(wsdlDef);
        TestLogger.logger.debug("Packages:");
        for (String pkgName : pkg) {
            TestLogger.logger.debug(pkgName);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : SchemaReaderImpl(org.apache.axis2.jaxws.wsdl.impl.SchemaReaderImpl) MalformedURLException(java.net.MalformedURLException) WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) Definition(javax.wsdl.Definition) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 4 with WSDL4JWrapper

use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.

the class DescriptionBuilderComposite method setWsdlDefinition.

/**
 * @param wsdlDefinition The wsdlDefinition to set.
 */
public void setWsdlDefinition(Definition wsdlDef) {
    Definition def = null;
    if (wsdlDef != null) {
        if (wsdlDef instanceof WSDL4JWrapper) {
            wsdlWrapper = (WSDL4JWrapper) wsdlDef;
            def = wsdlWrapper.getDefinition();
        } else {
            try {
                if (myConfigContext != null) {
                    // Construct WSDL4JWrapper with configuration information
                    wsdlWrapper = new WSDL4JWrapper(wsdlDef, myConfigContext);
                } else {
                    // If there is no configuration, default to using a
                    // memory sensitive wrapper
                    wsdlWrapper = new WSDL4JWrapper(wsdlDef, true, 2);
                }
                def = wsdlWrapper.getDefinition();
            } catch (Exception ex) {
            // absorb
            }
        }
        if (def != null) {
            String wsdlDefinitionBaseURI = def.getDocumentBaseURI();
            if ((wsdlDefinitionBaseURI != null) && (wsdlURL == null)) {
                try {
                    wsdlURL = new URL(wsdlDefinitionBaseURI);
                } catch (Exception e) {
                    if (log.isDebugEnabled()) {
                        log.debug("DescriptionBuilderComposite:setWsdlDefinition(): " + "Caught exception creating WSDL URL :" + wsdlDefinitionBaseURI + "; exception: " + e.toString(), e);
                    }
                }
            }
        }
    }
}
Also used : WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) Definition(javax.wsdl.Definition) URL(java.net.URL)

Example 5 with WSDL4JWrapper

use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.

the class MultiRedirectionCatalogTest method verifySuccess.

/**
 * Ensure that the catalog is used to locate imported resources.
 */
private void verifySuccess(String wsdlLocation, String catalogFile) {
    URL url = getURLFromLocation(wsdlLocation);
    try {
        OASISCatalogManager catalogManager = new OASISCatalogManager();
        catalogManager.setCatalogFiles(getURLFromLocation(catalogFile).toString());
        WSDL4JWrapper w4j = new WSDL4JWrapper(url, catalogManager, false, 0);
        Definition wsdlDef = w4j.getDefinition();
        assertNotNull(wsdlDef);
        QName portTypeName = new QName("http://www.example.com/test/calculator", "CalculatorService", "");
        PortType portType = wsdlDef.getPortType(portTypeName);
        assertNotNull(portType);
        Operation clearOp = portType.getOperation("clear", null, null);
        assertNotNull(clearOp);
        Input clearOpInput = clearOp.getInput();
        assertNotNull(clearOpInput);
        Message msg = clearOpInput.getMessage();
        assertNotNull(msg);
        Part expectedPart = msg.getPart("part1");
        assertNotNull(expectedPart);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) WSDL4JWrapper(org.apache.axis2.jaxws.util.WSDL4JWrapper) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) OASISCatalogManager(org.apache.axis2.jaxws.catalog.impl.OASISCatalogManager) Definition(javax.wsdl.Definition) Operation(javax.wsdl.Operation) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) WSDLException(javax.wsdl.WSDLException) PortType(javax.wsdl.PortType)

Aggregations

WSDL4JWrapper (org.apache.axis2.jaxws.util.WSDL4JWrapper)16 URL (java.net.URL)15 Definition (javax.wsdl.Definition)7 File (java.io.File)5 MalformedURLException (java.net.MalformedURLException)5 WSDLException (javax.wsdl.WSDLException)5 DescriptionBuilderComposite (org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite)5 QName (javax.xml.namespace.QName)4 ServiceDescription (org.apache.axis2.jaxws.description.ServiceDescription)4 JavaClassToDBCConverter (org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter)4 WSDLWrapper (org.apache.axis2.jaxws.util.WSDLWrapper)4 IOException (java.io.IOException)3 PrivilegedActionException (java.security.PrivilegedActionException)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 SchemaReaderImpl (org.apache.axis2.jaxws.wsdl.impl.SchemaReaderImpl)3 FileNotFoundException (java.io.FileNotFoundException)2 ConnectException (java.net.ConnectException)2 UnknownHostException (java.net.UnknownHostException)2 OASISCatalogManager (org.apache.axis2.jaxws.catalog.impl.OASISCatalogManager)2 EndpointDescription (org.apache.axis2.jaxws.description.EndpointDescription)2