Search in sources :

Example 31 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project carbon-business-process by wso2.

the class ArchiveBasedHumanTaskDeploymentUnitBuilder method buildWSDLs.

@Override
public void buildWSDLs() throws HumanTaskDeploymentException {
    HashSet<Definition> tmpWsdlDefinitions = new HashSet<>();
    URI baseUri = humantaskDir.toURI();
    for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) {
        try {
            URI uri = baseUri.relativize(file.toURI());
            if (!uri.isAbsolute()) {
                File f = new File(baseUri.getPath() + File.separator + uri.getPath());
                URI abUri = f.toURI();
                if (abUri.isAbsolute()) {
                    uri = abUri;
                }
            }
            WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
            reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
            reader.setFeature("javax.wsdl.importDocuments", true);
            Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri));
            if (definition != null) {
                tmpWsdlDefinitions.add(definition);
            }
        } catch (WSDLException e) {
            log.error("Error processing wsdl " + file.getName());
            throw new HumanTaskDeploymentException(" Error processing wsdl ", e);
        } catch (URISyntaxException e) {
            log.error("Invalid uri in reading wsdl ", e);
            throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e);
        }
    }
    // Optimizing WSDLs imports. Using HashSet to avoid duplicate entices.
    HashSet<Definition> optimizedDefinitions = new HashSet<>();
    HTDeploymentConfigDocument htDeploymentConfigDocument = getHTDeploymentConfigDocument();
    // Iterating Tasks.
    THTDeploymentConfig.Task[] taskArray = htDeploymentConfigDocument.getHTDeploymentConfig().getTaskArray();
    if (taskArray != null) {
        for (THTDeploymentConfig.Task task : taskArray) {
            QName taskService = task.getPublish().getService().getName();
            Definition taskServiceDefinition = getDefinition(taskService, tmpWsdlDefinitions);
            if (log.isDebugEnabled()) {
                log.debug("Optimizing WSDL import for Task : " + task.getName());
            }
            if (taskServiceDefinition != null) {
                optimizedDefinitions.add(taskServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + task.getName() + ", Service : " + taskService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Task" + task.getName() + ", Service: " + taskService);
            }
            QName callbackService = task.getCallback().getService().getName();
            Definition callbackServiceDefinition = getDefinition(callbackService, tmpWsdlDefinitions);
            if (callbackServiceDefinition != null) {
                optimizedDefinitions.add(callbackServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + task.getName() + ", Callback Service : " + callbackService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Task : " + task.getName() + ", Callback Service" + callbackService);
            }
        }
    }
    // Iterating Notifications.
    THTDeploymentConfig.Notification[] notificationsArray = htDeploymentConfigDocument.getHTDeploymentConfig().getNotificationArray();
    if (notificationsArray != null) {
        for (THTDeploymentConfig.Notification notification : notificationsArray) {
            QName notificationService = notification.getPublish().getService().getName();
            Definition notificationServiceDefinition = getDefinition(notificationService, tmpWsdlDefinitions);
            if (notificationServiceDefinition != null) {
                optimizedDefinitions.add(notificationServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + notification.getName() + ", Callback Service : " + notificationService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Notification " + notification.getName() + ", Service: " + notificationService);
            }
        }
    }
    // Converting HashSet to ArrayList.
    wsdlDefinitions = new ArrayList<>(optimizedDefinitions);
    if (log.isDebugEnabled()) {
        log.debug("Optimized Imported/Total definition : " + wsdlDefinitions.size() + "/" + tmpWsdlDefinitions.size());
    }
}
Also used : WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) THTDeploymentConfig(org.wso2.carbon.humantask.core.deployment.config.THTDeploymentConfig) HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 32 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project components by Talend.

the class JAXBConfigGen method run.

public void run(String... args) throws Exception {
    String wsdlUrl = args[0];
    String apiVersionPackageSuffix = args[1];
    String apiVersionPackage = args[2];
    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    Definition def = wsdlReader.readWSDL(wsdlUrl);
    Collection<String> namespaceList = new HashSet<>();
    processSchemas(def, namespaceList);
    System.out.println("Found namespaces: " + namespaceList.size());
    for (String namespaceUri : namespaceList) {
        System.out.println(namespaceUri);
    }
    List<Map<String, String>> entries = new ArrayList<>();
    for (String namespaceUri : namespaceList) {
        // split "urn:<ns>"
        String[] parts1 = namespaceUri.split("\\:");
        String namespace = parts1[1].replace(apiVersionPackageSuffix, "");
        String[] parts2 = namespace.split("\\.");
        List<String> nameParts = Arrays.asList(parts2);
        Collections.reverse(nameParts);
        StringBuilder sb = new StringBuilder();
        for (String namePart : nameParts) {
            if (sb.length() != 0) {
                sb.append(".");
            }
            sb.append(namePart);
        }
        String packageName = sb.toString().replace("com.netsuite.webservices.", "com.netsuite.webservices." + apiVersionPackage + ".");
        Map<String, String> entry = new HashMap<>();
        entry.put("uri", namespaceUri);
        entry.put("package", packageName);
        entries.add(entry);
    }
    System.out.println();
    System.out.println("JAXB binding customization samples: ");
    System.out.println();
    String template = "<bindings scd=\"x-schema::tns\" xmlns:tns=\"${namespace}\">\n" + "    <schemaBindings>\n" + "        <package name=\"${package}\"/>\n" + "    </schemaBindings>\n" + "</bindings>";
    for (Map<String, String> nsEntry : entries) {
        String namespaceUri = nsEntry.get("uri");
        String packageName = nsEntry.get("package");
        String result = template.replace("${namespace}", namespaceUri).replace("${package}", packageName);
        System.out.println(result);
    }
    System.out.println();
    System.out.println("Done.");
}
Also used : HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) WSDLReader(javax.wsdl.xml.WSDLReader) HashSet(java.util.HashSet)

Example 33 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project tomee by apache.

the class WsDeployer method readWsdl.

// don't put it in ReadDescriptors to respect classloader dependencies (wsdl4j is optional)
public static Definition readWsdl(final URL url) throws OpenEJBException {
    final Definition definition;
    try {
        final WSDLFactory factory = WSDLFactory.newInstance();
        final WSDLReader reader = factory.newWSDLReader();
        reader.setFeature("javax.wsdl.verbose", true);
        reader.setFeature("javax.wsdl.importDocuments", true);
        final WsdlResolver wsdlResolver = new WsdlResolver(new URL(url, ".").toExternalForm(), new InputSource(IO.read(url)));
        definition = reader.readWSDL(wsdlResolver);
    } catch (final IOException e) {
        throw new OpenEJBException("Cannot read the wsdl file: " + url.toExternalForm(), e);
    } catch (final Exception e) {
        throw new OpenEJBException("Encountered unknown error parsing the wsdl file: " + url.toExternalForm(), e);
    }
    return definition;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) InputSource(org.xml.sax.InputSource) WSDLFactory(javax.wsdl.factory.WSDLFactory) WsdlResolver(org.apache.openejb.core.webservices.WsdlResolver) Definition(javax.wsdl.Definition) IOException(java.io.IOException) WSDLReader(javax.wsdl.xml.WSDLReader) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException)

Example 34 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project tomee by apache.

the class CommonsSchemaLoader method readWsdl.

private Definition readWsdl(URI wsdlURI) throws OpenEJBException {
    Definition definition;
    WSDLFactory wsdlFactory;
    try {
        wsdlFactory = WSDLFactory.newInstance();
    } catch (WSDLException e) {
        throw new OpenEJBException("Could not create WSDLFactory", e);
    }
    WSDLReader wsdlReaderNoImport = wsdlFactory.newWSDLReader();
    wsdlReaderNoImport.setFeature("javax.wsdl.importDocuments", false);
    ExtensionRegistry extensionRegistry = new PopulatedExtensionRegistry();
    extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999, UnknownExtensibilityElement.class);
    extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, extensionRegistry.getDefaultDeserializer());
    extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, extensionRegistry.getDefaultSerializer());
    extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000, UnknownExtensibilityElement.class);
    extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, extensionRegistry.getDefaultDeserializer());
    extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, extensionRegistry.getDefaultSerializer());
    extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001, UnknownExtensibilityElement.class);
    extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, extensionRegistry.getDefaultDeserializer());
    extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, extensionRegistry.getDefaultSerializer());
    wsdlReaderNoImport.setExtensionRegistry(extensionRegistry);
    JarWSDLLocator wsdlLocator = new JarWSDLLocator(wsdlURI);
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    Thread thread = Thread.currentThread();
    ClassLoader oldCl = thread.getContextClassLoader();
    thread.setContextClassLoader(this.getClass().getClassLoader());
    try {
        try {
            definition = wsdlReader.readWSDL(wsdlLocator);
        } catch (WSDLException e) {
            throw new OpenEJBException("Failed to read wsdl document", e);
        } catch (RuntimeException e) {
            throw new OpenEJBException(e.getMessage(), e);
        }
    } finally {
        thread.setContextClassLoader(oldCl);
    }
    return definition;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) PopulatedExtensionRegistry(com.ibm.wsdl.extensions.PopulatedExtensionRegistry) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) WSDLReader(javax.wsdl.xml.WSDLReader) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) PopulatedExtensionRegistry(com.ibm.wsdl.extensions.PopulatedExtensionRegistry)

Example 35 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method init.

@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(url.toString(), getSecuredParsedDocumentFromURL(url));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Aggregations

WSDLReader (javax.wsdl.xml.WSDLReader)60 Definition (javax.wsdl.Definition)35 WSDLFactory (javax.wsdl.factory.WSDLFactory)25 WSDLException (javax.wsdl.WSDLException)16 URL (java.net.URL)15 Test (org.junit.Test)13 Service (javax.wsdl.Service)8 File (java.io.File)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 JBossWSTest (org.jboss.wsf.test.JBossWSTest)7 Document (org.w3c.dom.Document)7 QName (javax.xml.namespace.QName)6 InputSource (org.xml.sax.InputSource)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bus (org.apache.cxf.Bus)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4