use of com.openmeap.model.dto.ApplicationArchive in project OpenMEAP by OpenMEAP.
the class WebViewServlet method service.
@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.trace("in service");
ModelManager mgr = getModelManager();
GlobalSettings settings = mgr.getGlobalSettings();
String validTempPath = settings.validateTemporaryStoragePath();
if (validTempPath != null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, validTempPath);
}
String pathInfo = request.getPathInfo();
String[] pathParts = pathInfo.split("[/]");
if (pathParts.length < 4) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
String remove = pathParts[1] + "/" + pathParts[2] + "/" + pathParts[3];
String fileRelative = pathInfo.replace(remove, "");
String applicationNameString = URLDecoder.decode(pathParts[APP_NAME_INDEX], FormConstants.CHAR_ENC_DEFAULT);
String archiveHash = URLDecoder.decode(pathParts[APP_VER_INDEX], FormConstants.CHAR_ENC_DEFAULT);
Application app = mgr.getModelService().findApplicationByName(applicationNameString);
ApplicationArchive arch = mgr.getModelService().findApplicationArchiveByHashAndAlgorithm(app, archiveHash, "MD5");
String authSalt = app.getProxyAuthSalt();
String authToken = URLDecoder.decode(pathParts[AUTH_TOKEN_INDEX], FormConstants.CHAR_ENC_DEFAULT);
try {
if (!AuthTokenProvider.validateAuthToken(authSalt, authToken)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
} catch (DigestException e1) {
throw new GenericRuntimeException(e1);
}
File fileFull = new File(arch.getExplodedPath(settings.getTemporaryStoragePath()).getAbsolutePath() + "/" + fileRelative);
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(fileFull.toURL().toString());
response.setContentType(mimeType);
response.setContentLength(Long.valueOf(fileFull.length()).intValue());
InputStream inputStream = null;
OutputStream outputStream = null;
try {
//response.setStatus(HttpServletResponse.SC_FOUND);
inputStream = new FileInputStream(fileFull);
outputStream = response.getOutputStream();
Utils.pipeInputStreamIntoOutputStream(inputStream, outputStream);
} finally {
if (inputStream != null) {
inputStream.close();
}
response.getOutputStream().flush();
response.getOutputStream().close();
}
} catch (FileNotFoundException e) {
logger.error("Exception {}", e);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException ioe) {
logger.error("Exception {}", ioe);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of com.openmeap.model.dto.ApplicationArchive in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationVersionBacking method fillInApplicationVersionFromParameters.
private void fillInApplicationVersionFromParameters(Application app, ApplicationVersion version, List<ProcessingEvent> events, Map<Object, Object> parameterMap) {
version.setIdentifier(firstValue("identifier", parameterMap));
if (version.getArchive() == null) {
version.setArchive(new ApplicationArchive());
version.getArchive().setApplication(app);
}
version.setApplication(app);
version.setNotes(firstValue("notes", parameterMap));
Boolean archiveUncreated = true;
// if there was an uploadArchive, then attempt to auto-assemble the rest of parameters
if (parameterMap.get("uploadArchive") != null) {
if (!(parameterMap.get("uploadArchive") instanceof FileItem)) {
events.add(new MessagesEvent("Uploaded file not processed! Is the archive storage path set in settings?"));
} else {
FileItem item = (FileItem) parameterMap.get("uploadArchive");
Long size = item.getSize();
if (size > 0) {
try {
File tempFile = ServletUtils.tempFileFromFileItem(modelManager.getGlobalSettings().getTemporaryStoragePath(), item);
ApplicationArchive archive = version.getArchive();
archive.setNewFileUploaded(tempFile.getAbsolutePath());
archiveUncreated = false;
} catch (Exception ioe) {
logger.error("An error transpired creating an uploadArchive temp file: {}", ioe);
events.add(new MessagesEvent(ioe.getMessage()));
return;
} finally {
item.delete();
}
} else {
events.add(new MessagesEvent("Uploaded file not processed! Is the archive storage path set in settings?"));
}
}
}
// else there was no zip archive uploaded
if (archiveUncreated) {
ApplicationArchive archive = version.getArchive();
archive.setHashAlgorithm(firstValue("hashType", parameterMap));
archive.setHash(firstValue("hash", parameterMap));
ApplicationArchive arch = modelManager.getModelService().findApplicationArchiveByHashAndAlgorithm(app, archive.getHash(), archive.getHashAlgorithm());
if (arch != null) {
version.setArchive(arch);
archive = arch;
}
archive.setUrl(firstValue("url", parameterMap));
if (notEmpty("bytesLength", parameterMap)) {
archive.setBytesLength(Integer.valueOf(firstValue("bytesLength", parameterMap)));
}
if (notEmpty("bytesLengthUncompressed", parameterMap)) {
archive.setBytesLengthUncompressed(Integer.valueOf(firstValue("bytesLengthUncompressed", parameterMap)));
}
}
}
use of com.openmeap.model.dto.ApplicationArchive in project OpenMEAP by OpenMEAP.
the class DeploymentAddModifyNotifier method addRequestParameters.
@Override
protected void addRequestParameters(ModelEntity modelEntity, Map<String, Object> parms) {
ApplicationArchive archive = (ApplicationArchive) (((Deployment) modelEntity).getApplicationArchive());
parms.put(UrlParamConstants.APPARCH_FILE, archive.getFile(getModelManager().getGlobalSettings().getTemporaryStoragePath()));
super.addRequestParameters(archive, parms);
}
use of com.openmeap.model.dto.ApplicationArchive in project OpenMEAP by OpenMEAP.
the class ModelServiceRefreshNotifier method makeRequest.
/**
* This MUST remain state-less
*
* @param <T>
* @param thisUrl
* @param obj
*/
@Override
protected void makeRequest(final URL url, final Event<ModelEntity> mesg) throws ClusterNotificationException {
com.openmeap.http.HttpResponse httpResponse = null;
String simpleName = null;
String thisUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/";
ModelEntity obj = mesg.getPayload();
// I am not using obj.getClass().getSimpleName() because of Hibernate Proxy object wrapping
if (obj instanceof Application)
simpleName = "Application";
else if (obj instanceof ApplicationVersion)
simpleName = "ApplicationVersion";
else if (obj instanceof ApplicationArchive)
simpleName = "ApplicationArchive";
else if (obj instanceof ApplicationInstallation)
simpleName = "ApplicationInstallation";
else if (obj instanceof GlobalSettings)
simpleName = "GlobalSettings";
else
return;
Hashtable<String, Object> parms = new Hashtable<String, Object>();
parms.put(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
parms.put(UrlParamConstants.AUTH_TOKEN, newAuthToken());
parms.put(UrlParamConstants.REFRESH_TYPE, simpleName);
parms.put(UrlParamConstants.REFRESH_OBJ_PKID, obj.getPk());
try {
logger.debug("Refresh post to {} for {} with id {}", new Object[] { thisUrl, simpleName, obj.getPk() });
httpResponse = getHttpRequestExecuter().postData(thisUrl, parms);
Utils.consumeInputStream(httpResponse.getResponseBody());
int statusCode = httpResponse.getStatusCode();
if (statusCode != 200) {
String exMesg = "HTTP " + statusCode + " returned for refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk();
logger.error(exMesg);
throw new ClusterNotificationException(url, exMesg);
}
} catch (Exception e) {
String exMesg = "Refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk() + " threw an exception";
logger.error(exMesg, e);
throw new ClusterNotificationException(url, exMesg, e);
}
}
use of com.openmeap.model.dto.ApplicationArchive in project OpenMEAP by OpenMEAP.
the class ModelServiceImpl method findApplicationArchiveByHashAndAlgorithm.
@Override
public ApplicationArchive findApplicationArchiveByHashAndAlgorithm(Application app, String hash, String hashAlgorithm) {
Query q = entityManager.createQuery("select distinct ar " + "from ApplicationArchive ar " + "join fetch ar.application app " + "where ar.hash=:hash " + "and ar.hashAlgorithm=:hashAlgorithm " + "and app.id=:appId");
q.setParameter("hash", hash);
q.setParameter("hashAlgorithm", hashAlgorithm);
q.setParameter("appId", app.getId());
q.setMaxResults(1);
try {
ApplicationArchive o = (ApplicationArchive) q.getSingleResult();
return (ApplicationArchive) o;
} catch (NoResultException nre) {
return null;
}
}
Aggregations