Search in sources :

Example 1 with WebappUploadData

use of org.wso2.carbon.webapp.mgt.WebappUploadData in project jaggery by wso2.

the class WarFileUploadExecutor method execute.

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "FILE_UPLOAD_FILENAME", "FILE_UPLOAD_FILENAME" })
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
    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 = "Jaggery application uploading failed. No file specified.";
        log.error(msg);
        CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.ERROR, request, response, "../" + webContext + "/jaggeryapp-mgt/uploadjaggeryapp.jsp");
        return false;
    }
    JaggeryAdminClient client = new JaggeryAdminClient(cookie, serverURL, configurationContext, request.getLocale());
    String msg;
    List<FileItemData> tempDataList = fileItemsMap.get("warFileName");
    if (tempDataList == null) {
        return false;
    }
    List<WebappUploadData> webappUploadDataList = new ArrayList<WebappUploadData>();
    try {
        for (FileItemData filedata : tempDataList) {
            WebappUploadData tempData = new WebappUploadData();
            checkServiceFileExtensionValidity(getFileName(filedata.getFileItem().getName()), ALLOWED_FILE_EXTENSIONS);
            tempData.setFileName(getFileName(filedata.getFileItem().getName()));
            tempData.setDataHandler(filedata.getDataHandler());
            webappUploadDataList.add(tempData);
        }
        client.uploadWebapp(webappUploadDataList.toArray(new WebappUploadData[webappUploadDataList.size()]));
        response.setContentType("text/html; charset=utf-8");
        if (tempDataList.size() > 1) {
            msg = "Jaggery applications have been uploaded " + "successfully. Please refresh this page in a while to see " + "the status of the running Jaggery apps.";
        } else {
            msg = "Jaggery application has been uploaded " + "successfully. Please refresh this page in a while to see " + "the status of the running Jaggery apps.";
        }
        CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, "../" + webContext + "/webapp-list/index.jsp");
        return true;
    } catch (Exception e) {
        msg = "Jaggery application upload failed. " + e.getMessage();
        log.error(msg, e);
        CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.ERROR, request, response, "../" + webContext + "/jaggeryapp-mgt/uploadjaggeryapp.jsp");
    }
    return false;
}
Also used : FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) WebappUploadData(org.jaggeryjs.jaggery.app.mgt.stub.types.carbon.WebappUploadData) IOException(java.io.IOException) CarbonException(org.wso2.carbon.CarbonException)

Example 2 with WebappUploadData

use of org.wso2.carbon.webapp.mgt.WebappUploadData in project jaggery by wso2.

the class JaggeryAppAdmin method uploadWebapp.

/**
     * Upload a webapp
     *
     * @param webappUploadDataList Array of data representing the webapps that are to be uploaded
     * @return true - if upload was successful
     * @throws org.apache.axis2.AxisFault If an error occurrs while uploading
     */
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
public boolean uploadWebapp(WebappUploadData[] webappUploadDataList) throws AxisFault {
    AxisConfiguration axisConfig = getAxisConfig();
    String repoPath = axisConfig.getRepository().getPath();
    String jaggeryAppsPath = getWebappDeploymentDirPath();
    for (WebappUploadData uploadData : webappUploadDataList) {
        String fName = uploadData.getFileName();
        if (fName.contains(".")) {
            fName = fName.split("\\.")[0];
        }
        File webappsDir = new File(jaggeryAppsPath + File.separator + fName);
        File jaggeryAppsFile = new File(jaggeryAppsPath);
        if (webappsDir.exists()) {
            String msg = "Jaggery app with the same name already exists";
            log.error(msg);
            throw new AxisFault(msg);
        } else if (!jaggeryAppsFile.exists()) {
            //if deployment directory is not there we create it
            if (!jaggeryAppsFile.mkdir()) {
                String error = "Jaggery deployment directory not found and cannot be created when uploading";
                log.error(error);
                throw new AxisFault(error);
            }
        }
        ArchiveManipulator archiveManipulator = new ArchiveManipulator();
        try {
            archiveManipulator.extractFromStream(uploadData.getDataHandler().getInputStream(), jaggeryAppsPath + File.separator + fName);
        } catch (IOException e) {
            log.error("Could not unzip the Jaggery App Archive", e);
            throw new AxisFault(e.getMessage(), e);
        }
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ArchiveManipulator(org.wso2.carbon.utils.ArchiveManipulator) WebappUploadData(org.wso2.carbon.webapp.mgt.WebappUploadData) IOException(java.io.IOException) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

IOException (java.io.IOException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AxisFault (org.apache.axis2.AxisFault)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 WebappUploadData (org.jaggeryjs.jaggery.app.mgt.stub.types.carbon.WebappUploadData)1 CarbonException (org.wso2.carbon.CarbonException)1 ArchiveManipulator (org.wso2.carbon.utils.ArchiveManipulator)1 FileItemData (org.wso2.carbon.utils.FileItemData)1 WebappUploadData (org.wso2.carbon.webapp.mgt.WebappUploadData)1