Search in sources :

Example 1 with HTDeploymentConfigDocument

use of org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument in project carbon-business-process by wso2.

the class HumanTaskUploadExecutor method validateHTDeploymentConfigDocument.

/**
 * Validate HT deployment config Document.
 *
 * @param directoryPath Unzipped HumanTask archive directory.
 * @throws Exception
 */
public void validateHTDeploymentConfigDocument(String directoryPath) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Validating HumanTask deployment config.");
    }
    // We have to check whether the htconfig.xml file is in the root level.
    // otherwise we cannot accept this as a valid human task package.
    String htConfigFilePathString = directoryPath + File.separator + HumanTaskUIConstants.FILE_NAMES.HT_CONFIG_NAME;
    File htConfigFile = new File(htConfigFilePathString);
    if (!htConfigFile.exists()) {
        throw new Exception("The uploaded task definition zip file does not contain a htconfig.xml" + "file. Please check the package and re-upload.");
    }
    HTDeploymentConfigDocument hiConf;
    FileInputStream fileInputStream = null;
    try {
        fileInputStream = new FileInputStream(htConfigFile);
        hiConf = HTDeploymentConfigDocument.Factory.parse(fileInputStream);
        if (log.isDebugEnabled()) {
            log.debug("Successfully Validated HumanTask deployment config.");
        }
    } catch (Exception e) {
        String errMsg = "Error occurred while parsing the human interaction configuration " + "file: htconfig.xml";
        throw new Exception(errMsg, e);
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
}
Also used : HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) CarbonException(org.wso2.carbon.CarbonException)

Example 2 with HTDeploymentConfigDocument

use of org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument 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)

Aggregations

HTDeploymentConfigDocument (org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Definition (javax.wsdl.Definition)1 WSDLException (javax.wsdl.WSDLException)1 WSDLReader (javax.wsdl.xml.WSDLReader)1 QName (javax.xml.namespace.QName)1 CarbonException (org.wso2.carbon.CarbonException)1 THTDeploymentConfig (org.wso2.carbon.humantask.core.deployment.config.THTDeploymentConfig)1