use of org.wso2.carbon.utils.ArchiveManipulator 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;
}
Aggregations