use of com.openmeap.model.dto.GlobalSettings 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.GlobalSettings in project OpenMEAP by OpenMEAP.
the class ModelManagerImplTest method testGlobalSettings.
@Test
public void testGlobalSettings() throws Exception {
GlobalSettings settings = new GlobalSettings();
Boolean ipeThrown = false;
try {
modelManager.begin().addModify(settings, null);
modelManager.commit();
} catch (InvalidPropertiesException ipe) {
modelManager.rollback();
ipeThrown = true;
}
Assert.assertTrue(ipeThrown);
settings = modelManager.getGlobalSettings();
Assert.assertTrue(settings.getId().equals(Long.valueOf(1)));
ClusterNode node = new ClusterNode();
node.setServiceWebUrlPrefix("http://test");
node.setFileSystemStoragePathPrefix("/");
settings.addClusterNode(node);
try {
settings = modelManager.begin().addModify(settings, null);
modelManager.commit();
} catch (Exception e) {
modelManager.rollback();
throw new Exception(e);
}
settings = modelManager.getGlobalSettings();
Assert.assertTrue(settings.getClusterNodes().size() == 3);
Assert.assertTrue(settings.getClusterNode("http://test") != null);
}
use of com.openmeap.model.dto.GlobalSettings in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServlet method handleArchiveDownload.
private Result handleArchiveDownload(HttpServletRequest request, HttpServletResponse response) {
Result res = new Result();
Error err = new Error();
res.setError(err);
GlobalSettings settings = modelManager.getGlobalSettings();
Map properties = this.getServicesWebProperties();
String nodeKey = (String) properties.get("clusterNodeUrlPrefix");
ClusterNode clusterNode = settings.getClusterNode(nodeKey);
if (nodeKey == null || clusterNode == null) {
// TODO: create a configuration error code
err.setCode(ErrorCode.UNDEFINED);
err.setMessage("A configuration is missing. Please consult the error logs.");
logger.error("For each node in the cluster, the property or environment variable OPENMEAP_CLUSTER_NODE_URL_PREFIX must match the \"Service Url Prefix\" value configured in the administrative interface. This value is currently " + nodeKey + ".");
return res;
}
String pathValidation = clusterNode.validateFileSystemStoragePathPrefix();
if (pathValidation != null) {
err.setCode(ErrorCode.UNDEFINED);
err.setMessage("A configuration is missing. Please consult the error logs.");
logger.error("There is an issue with the location at \"File-system Storage Prefix\". " + pathValidation);
return res;
}
String hash = request.getParameter(UrlParamConstants.APPARCH_HASH);
String hashAlg = request.getParameter(UrlParamConstants.APPARCH_HASH_ALG);
String fileName = null;
if (hash == null || hashAlg == null) {
// look in the apps directory for the archive specified
String appName = request.getParameter(UrlParamConstants.APP_NAME);
String versionId = request.getParameter(UrlParamConstants.APP_VERSION);
ApplicationVersion appVersion = modelManager.getModelService().findAppVersionByNameAndId(appName, versionId);
if (appVersion == null) {
String mesg = "The application version " + versionId + " was not found for application " + appName;
err.setCode(ErrorCode.APPLICATION_VERSION_NOTFOUND);
err.setMessage(mesg);
logger.warn(mesg);
return res;
}
String auth = request.getParameter(UrlParamConstants.AUTH_TOKEN);
com.openmeap.model.dto.Application app = appVersion.getApplication();
try {
if (auth == null || !AuthTokenProvider.validateAuthToken(app.getProxyAuthSalt(), auth)) {
err.setCode(ErrorCode.AUTHENTICATION_FAILURE);
err.setMessage("The \"auth\" token presented is not recognized, missing, or empty.");
return res;
}
} catch (DigestException e) {
throw new GenericRuntimeException(e);
}
hash = appVersion.getArchive().getHash();
hashAlg = appVersion.getArchive().getHashAlgorithm();
fileName = app.getName() + " - " + appVersion.getIdentifier();
} else {
fileName = hashAlg + "-" + hash;
}
File file = ApplicationArchive.getFile(clusterNode.getFileSystemStoragePathPrefix(), hashAlg, hash);
if (!file.exists()) {
String mesg = "The application archive with " + hashAlg + " hash " + hash + " was not found.";
// TODO: create an enumeration for this error
err.setCode(ErrorCode.UNDEFINED);
err.setMessage(mesg);
logger.warn(mesg);
return res;
}
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(file.toURL().toString());
response.setContentType(mimeType);
response.setContentLength(Long.valueOf(file.length()).intValue());
URLCodec codec = new URLCodec();
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".zip\";");
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
outputStream = response.getOutputStream();
Utils.pipeInputStreamIntoOutputStream(inputStream, outputStream);
} finally {
if (inputStream != null) {
inputStream.close();
}
//if(outputStream!=null) {outputStream.close();}
}
response.flushBuffer();
} catch (FileNotFoundException e) {
logger.error("Exception {}", e);
} catch (IOException ioe) {
logger.error("Exception {}", ioe);
}
return null;
}
use of com.openmeap.model.dto.GlobalSettings in project OpenMEAP by OpenMEAP.
the class ApplicationVersionListingsBacking method createVersionsDisplayLists.
private void createVersionsDisplayLists(Application app, Map<Object, Object> templateVariables) {
templateVariables.put("versions", app.getVersions());
GlobalSettings settings = modelManager.getGlobalSettings();
Map<String, String> downloadUrls = new HashMap<String, String>();
Map<String, String> viewUrls = new HashMap<String, String>();
for (ApplicationVersion version : app.getVersions().values()) {
if (version.getArchive() == null) {
viewUrls.put(version.getIdentifier(), "");
} else {
downloadUrls.put(version.getIdentifier(), version.getArchive().getDownloadUrl(settings));
File exploded = version.getArchive().getExplodedPath(settings.getTemporaryStoragePath());
if (exploded != null && exploded.exists()) {
viewUrls.put(version.getIdentifier(), version.getArchive().getViewUrl(settings));
}
}
}
templateVariables.put("downloadUrls", downloadUrls);
templateVariables.put("viewUrls", viewUrls);
}
use of com.openmeap.model.dto.GlobalSettings in project OpenMEAP by OpenMEAP.
the class AdminServlet method service.
@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
logger.trace("Entering service()");
try {
DocumentProcessor documentProcessor = null;
logger.debug("Request uri: {}", request.getRequestURI());
logger.debug("Request url: {}", request.getRequestURL());
logger.debug("Query string: {}", request.getQueryString());
if (logger.isDebugEnabled()) {
logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap()));
}
if (request.getParameter("logout") != null) {
logger.trace("Executing logout");
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + "/interface/");
}
if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) {
logger.trace("Refreshing context");
((AbstractApplicationContext) context).refresh();
}
// support for clearing the persistence context
if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) {
logger.trace("Clearing the persistence context");
ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context).getBean("modelService");
ms.clearPersistenceContext();
}
// default to the mainOptionPage, unless otherwise specified
String pageBean = null;
if (request.getParameter(FormConstants.PAGE_BEAN) != null)
pageBean = request.getParameter(FormConstants.PAGE_BEAN);
else
pageBean = FormConstants.PAGE_BEAN_MAIN;
logger.debug("Using page bean: {}", pageBean);
documentProcessor = (DocumentProcessor) context.getBean(pageBean);
ModelManager mgr = getModelManager();
Map<Object, Object> map = new HashMap<Object, Object>();
// TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope
if (documentProcessor.getProcessesFormData()) {
GlobalSettings settings = mgr.getGlobalSettings();
map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), settings.getTemporaryStoragePath(), request);
map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() });
AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer");
authorizer.setRequest(request);
}
response.setContentType(FormConstants.CONT_TYPE_HTML);
Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>();
defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper()));
documentProcessor.setTemplateVariables(defaultTemplateVars);
documentProcessor.handleProcessAndRender(map, response.getWriter());
response.getWriter().flush();
response.getWriter().close();
} catch (IOException te) {
throw new RuntimeException(te);
}
logger.trace("Leaving service()");
}
Aggregations