Search in sources :

Example 16 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class HumanTaskUploadExecutor method saveAndExtractUploadedFile.

public SaveExtractReturn saveAndExtractUploadedFile(FileItem fileItem) throws Exception {
    String serviceUploadDir = getTempUploadDir();
    File servicesDir = new File(serviceUploadDir);
    if (!servicesDir.exists() && !servicesDir.mkdirs()) {
        throw new IOException("Fail to create the directory: " + servicesDir.getAbsolutePath());
    }
    // Writing HumanTask archive to file system
    String fileItemName = getFileName(fileItem.getName());
    File uploadedFile = new File(servicesDir, fileItemName);
    if (log.isDebugEnabled()) {
        log.debug("[HumanTaskUI]HumanTask Archive Path: " + uploadedFile.getAbsolutePath());
    }
    try {
        fileItem.write(uploadedFile);
    } catch (Exception e) {
        log.error("Error occurred while writing file item to file system.", e);
        throw new Exception("Error occurred while writing file item to file system.", e);
    }
    String destinationDir = serviceUploadDir + fileItemName.substring(0, fileItemName.lastIndexOf('.'));
    if (log.isDebugEnabled()) {
        log.debug("[HumanTaskUI]HumanTask package location: " + destinationDir);
    }
    try {
        ArchiveExtractor.extract(uploadedFile, destinationDir);
    } catch (Exception e) {
        log.error("Error extracting archive.", e);
        throw new Exception(e);
    }
    return new SaveExtractReturn(uploadedFile.getAbsolutePath(), destinationDir);
}
Also used : CarbonException(org.wso2.carbon.CarbonException)

Example 17 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPELUploadExecutor method execute.

public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
    String errMsg;
    response.setContentType("text/html; charset=utf-8");
    PrintWriter out = response.getWriter();
    String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
    String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
    String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
    if (fileItemsMap == null || fileItemsMap.isEmpty()) {
        String msg = "File uploading failed.";
        log.error(msg);
        out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
        return true;
    }
    BPELUploaderClient uploaderClient = new BPELUploaderClient(configurationContext, serverURL + "BPELUploader", cookie);
    SaveExtractReturn uploadedFiles = null;
    ArrayList<String> extractedFiles = new ArrayList<String>();
    try {
        for (FileItemData fieldData : fileItemsMap.get("bpelFileName")) {
            String fileName = getFileName(fieldData.getFileItem().getName());
            // Check filename for \ charactors. This cannot be handled at the lower stages.
            if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
                log.error("BPEL Package Validation Failure: one or many of the following illegal characters are " + "in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
                throw new Exception("BPEL Package Validation Failure: one or many of the following illegal " + "characters " + "are in the package. ~!@#$;%^*()+={}[]| \\<>");
            }
            // Check file extension.
            checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
            if (fileName.lastIndexOf('\\') != -1) {
                int indexOfColon = fileName.lastIndexOf('\\') + 1;
                fileName = fileName.substring(indexOfColon, fileName.length());
            }
            if (fieldData.getFileItem().getFieldName().equals("bpelFileName")) {
                uploadedFiles = saveAndExtractUploadedFile(fieldData.getFileItem());
                extractedFiles.add(uploadedFiles.extractedFile);
                validateBPELPackage(uploadedFiles.extractedFile);
                DataSource dataSource = new FileDataSource(uploadedFiles.zipFile);
                uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "zip");
            }
        }
        uploaderClient.uploadFileItems();
        String msg = "Your BPEL package been uploaded successfully. Please refresh this page in a" + " while to see the status of the new process.";
        CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/bpel/process_list.jsp");
        return true;
    } catch (Exception e) {
        errMsg = "File upload failed :" + e.getMessage();
        log.error(errMsg, e);
        CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/bpel/upload_bpel.jsp");
    } finally {
        for (String s : extractedFiles) {
            File extractedFile = new File(s);
            if (log.isDebugEnabled()) {
                log.debug("Cleaning temporarily extracted BPEL artifacts in " + extractedFile.getParent());
            }
            try {
                FileUtils.cleanDirectory(new File(extractedFile.getParent()));
            } catch (IOException ex) {
                log.warn("Failed to clean temporary extractedFile.", ex);
            }
        }
    }
    return false;
}
Also used : FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) IOException(java.io.IOException) CarbonException(org.wso2.carbon.CarbonException) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource) FileDataSource(javax.activation.FileDataSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 18 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPELUploadExecutor method saveAndExtractUploadedFile.

public SaveExtractReturn saveAndExtractUploadedFile(FileItem fileItem) throws Exception {
    String serviceUploadDir = getTempUploadDir();
    File servicesDir = new File(serviceUploadDir);
    if (!servicesDir.exists() && !servicesDir.mkdirs()) {
        throw new IOException("Fail to create the directory: " + servicesDir.getAbsolutePath());
    }
    // Writing BPEL archive to file system
    String fileItemName = getFileName(fileItem.getName());
    File uploadedFile = new File(servicesDir, fileItemName);
    if (log.isDebugEnabled()) {
        log.debug("[BPELUI]BPEL Archive Path: " + uploadedFile.getAbsolutePath());
    }
    try {
        fileItem.write(uploadedFile);
    } catch (Exception e) {
        log.error("Error occurred while writing file item to file system.", e);
        throw new Exception("Erorr occurred while writing file item to file system.", e);
    }
    String destinationDir = serviceUploadDir + File.separator + fileItemName.substring(0, fileItemName.lastIndexOf('.'));
    if (log.isDebugEnabled()) {
        log.debug("[BPELUI]Bpel package location: " + destinationDir);
    }
    try {
        ArchiveExtractor.extract(uploadedFile, destinationDir);
    } catch (Exception e) {
        log.error("Error extracting archive.", e);
        throw new Exception(e);
    }
    // Handling backward compatibility issues. If user upload BPEL archive which follows the BPS 1.0.1 archive
    // format
    // we need to convert it to new format and upload.
    File deployXml = new File(destinationDir, "deploy.xml");
    if (!deployXml.exists()) {
        String depXmlSrc = fileItemName.substring(0, fileItemName.lastIndexOf('.')) + File.separator + "deploy.xml";
        deployXml = new File(destinationDir, depXmlSrc);
        if (deployXml.exists() && onlyOneChildDir(destinationDir, fileItemName.substring(0, fileItemName.lastIndexOf('.')))) {
            String tempUploadDir = getTempUploadDir();
            File tempDir = new File(tempUploadDir);
            if (!tempDir.exists() && !tempDir.mkdirs()) {
                throw new IOException("Fail to create the directory: " + tempDir.getAbsolutePath());
            }
            String filesToZipParent = destinationDir + File.separator + fileItemName.substring(0, fileItemName.lastIndexOf('.'));
            String zipLocation = tempDir.getAbsolutePath() + File.separator + fileItemName;
            try {
                zip(zipLocation, filesToZipParent);
            } catch (Exception e) {
                throw new Exception(e);
            }
            return new SaveExtractReturn(zipLocation, filesToZipParent);
        }
        throw new Exception("BPEL Archive format error.Please confirm that the file being uploaded is a " + "valid BPEL archive.");
    }
    return new SaveExtractReturn(uploadedFile.getAbsolutePath(), destinationDir);
}
Also used : IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) CarbonException(org.wso2.carbon.CarbonException)

Example 19 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPELUploadExecutor method validateBPELPackage.

public void validateBPELPackage(String directoryPath) throws Exception {
    DeploymentUnitDir du;
    try {
        du = new DeploymentUnitDir(new File(directoryPath));
    } catch (IllegalArgumentException iae) {
        log.error("BPEL Package Validation Failure.", iae);
        throw new Exception("BPEL Package Validation Failure.", iae);
    }
    // check package for illegal charactors which registry does not support. (~!@#$;%^*()+={}[]|\<>)
    List<File> packageFiles = du.allFiles();
    for (File packageFile : packageFiles) {
        if (!packageFile.getName().matches("[^\\~\\!\\@\\#\\$\\;\\%\\^\\*\\(\\)\\+ " + "/\\=\\{\\}\\[\\]\\\\|\\<\\>\"\\'\\`]+")) {
            log.error("BPEL Package Validation Failure: one or many of the following illegal characters are in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>\"'`");
            throw new Exception("BPEL Package Validation Failure: one or many of the following illegal characters" + " " + "are in the package. ~!@#$;%^*()+={}[]| \\<>\"'`");
        }
    }
    try {
        du.compile();
    } catch (RuntimeException ce) {
        log.error("BPEL Process Compilation Failure.", ce);
        throw new Exception("BPEL Compilation Failure!", ce);
    } catch (Exception e) {
        log.error("BPEL Process Compilation Failure.", e);
        throw new Exception("BPEL Compilation Failure!", e);
    }
    du.scan();
    DeployDocument dd = du.getDeploymentDescriptor();
    for (TDeployment.Process processDD : dd.getDeploy().getProcessList()) {
        QName processType = processDD.getType() != null ? processDD.getType() : processDD.getName();
        DeploymentUnitDir.CBPInfo cbpInfo = du.getCBPInfo(processType);
        if (cbpInfo == null) {
            // removeDeploymentArtifacts(deploymentContext, du);
            String logMessage = "Aborting deployment. Cannot find Process definition for type " + processType + ".";
            log.error(logMessage);
            throw new Exception(logMessage);
        }
        for (TProvide tProvide : processDD.getProvideList()) {
            if (tProvide.getService() == null) {
                String errMsg = "Service element missing for the provide element in deploy.xml";
                log.error(errMsg);
                throw new Exception(errMsg);
            }
        }
        for (TInvoke tInvoke : processDD.getInvokeList()) {
            if (tInvoke.getService() == null) {
                String errMsg = "Service element missing for the invoke element in deploy.xml";
                log.error(errMsg);
                throw new Exception(errMsg);
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) DeploymentUnitDir(org.apache.ode.store.DeploymentUnitDir) IOException(java.io.IOException) CarbonException(org.wso2.carbon.CarbonException) TDeployment(org.apache.ode.bpel.dd.TDeployment) TInvoke(org.apache.ode.bpel.dd.TInvoke) DeployDocument(org.apache.ode.bpel.dd.DeployDocument) TProvide(org.apache.ode.bpel.dd.TProvide) File(java.io.File)

Example 20 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class HumanTaskStore method createAxisService.

// Creates the AxisService object from the provided ServiceBuilder object.
private AxisService createAxisService(WSDL11ToAxisServiceBuilder serviceBuilder, HumanTaskBaseConfiguration config) throws AxisFault {
    AxisService axisService;
    axisService = serviceBuilder.populateService();
    axisService.setParent(getTenantAxisConfig());
    axisService.setWsdlFound(true);
    axisService.setCustomWsdl(true);
    // axisService.setFileName(new URL(taskConfig.getWsdlDefLocation()));
    axisService.setClassLoader(getTenantAxisConfig().getServiceClassLoader());
    Utils.setEndpointsToAllUsedBindings(axisService);
    axisService.addParameter(new Parameter("modifyUserWSDLPortAddress", "true"));
    /* Setting service type to use in service management*/
    axisService.addParameter(ServerConstants.SERVICE_TYPE, "humantask");
    /* Fix for losing of security configuration  when updating human-task package*/
    axisService.addParameter(new Parameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM, "true"));
    Iterator operations = axisService.getOperations();
    AxisHumanTaskMessageReceiver msgReceiver = new AxisHumanTaskMessageReceiver();
    msgReceiver.setHumanTaskEngine(HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine());
    // Setting the task configuration to the message receiver. Hence no need to search for task configuration, when
    // the actual task invocation happens, we will already have the task configuration attached to the message receiver
    // itself
    msgReceiver.setTaskBaseConfiguration(config);
    while (operations.hasNext()) {
        AxisOperation operation = (AxisOperation) operations.next();
        // Setting Message Receiver even if operation has a message receiver specified.
        // This is to fix the issue when build service configuration using services.xml(Always RPCMessageReceiver
        // is set to operations).
        operation.setMessageReceiver(msgReceiver);
        getTenantAxisConfig().getPhasesInfo().setOperationPhases(operation);
    }
    Set<String> exposedTransports = getTenantAxisConfig().getTransportsIn().keySet();
    // Add the transports to axis2 service by reading from the tenant transport config
    for (String transport : exposedTransports) {
        axisService.addExposedTransport(transport);
    }
    if (HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().isHtCoordinationEnabled() && HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().isTaskRegistrationEnabled() && config.getConfigurationType() == HumanTaskBaseConfiguration.ConfigurationType.TASK) {
        // Only Engage coordination module in-case of Tasks. Coordination module is not required for notifications
        axisService.engageModule(getConfigContext().getAxisConfiguration().getModule("htcoordination"));
    }
    return axisService;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) Iterator(java.util.Iterator) Parameter(org.apache.axis2.description.Parameter) AxisHumanTaskMessageReceiver(org.wso2.carbon.humantask.core.integration.AxisHumanTaskMessageReceiver)

Aggregations

BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)49 ArrayList (java.util.ArrayList)34 Test (org.testng.annotations.Test)29 Page (org.ballerinalang.docgen.model.Page)18 File (java.io.File)16 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)16 IOException (java.io.IOException)15 Path (java.nio.file.Path)13 List (java.util.List)13 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)11 PackageID (org.ballerinalang.model.elements.PackageID)10 Compiler (org.wso2.ballerinalang.compiler.Compiler)10 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)10 Collectors (java.util.stream.Collectors)9 Arrays (java.util.Arrays)8 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)7 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)6 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)6