use of com.openmeap.protocol.dto.Result in project OpenMEAP by OpenMEAP.
the class RESTAppMgmtClient method connectionOpen.
public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
ConnectionOpenResponse response = null;
Hashtable postData = new Hashtable();
postData.put(UrlParamConstants.ACTION, "connection-open-request");
postData.put(UrlParamConstants.DEVICE_UUID, request.getApplication().getInstallation().getUuid());
postData.put(UrlParamConstants.APP_NAME, request.getApplication().getName());
postData.put(UrlParamConstants.APP_VERSION, request.getApplication().getVersionId());
postData.put(UrlParamConstants.APPARCH_HASH, StringUtils.orEmpty(request.getApplication().getHashValue()));
postData.put(UrlParamConstants.SLIC_VERSION, request.getSlic().getVersionId());
HttpResponse httpResponse = null;
InputSource responseInputSource = null;
String responseText = null;
try {
httpResponse = requester.postData(serviceUrl, postData);
if (httpResponse.getStatusCode() != 200) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, "Posting to the service resulted in a " + httpResponse.getStatusCode() + " status code");
}
responseText = Utils.readInputStream(httpResponse.getResponseBody(), "UTF-8");
} catch (Exception e) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, StringUtils.isEmpty(e.getMessage()) ? e.getMessage() : "There's a problem connecting. Check your network or try again later", e);
}
// now we parse the response into a ConnectionOpenResponse object
if (responseText != null) {
Result result = new Result();
JSONObjectBuilder builder = new JSONObjectBuilder();
try {
result = (Result) builder.fromJSON(new JSONObject(responseText), result);
if (result.getError() != null) {
throw new WebServiceException(WebServiceException.TypeEnum.fromValue(result.getError().getCode().value()), result.getError().getMessage());
}
} catch (JSONException e) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, "Unable to parse service response content.");
}
response = result.getConnectionOpenResponse();
}
return response;
}
use of com.openmeap.protocol.dto.Result in project OpenMEAP by OpenMEAP.
the class AdminTest method testUpdateApplicationVersion.
public void testUpdateApplicationVersion() throws Exception {
GlobalSettings settings = modelManager.getGlobalSettings();
// validate that an unused archive is deleted
// update version update
// and that it is recreated when reuploaded
ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
String response = Utils.readInputStream(helper.postAddModifyAppVer(version1, new File(this.getClass().getResource(VERSION_02_ZIP).getFile())).getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
modelManager.getModelService().clearPersistenceContext();
version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
Assert.assertTrue(version1.getArchive().getHash().equals(VERSION_02_HASH));
Assert.assertTrue(version2.getArchive().getHash().equals(VERSION_02_HASH));
Assert.assertSame(version2.getArchive(), version1.getArchive());
// now restore the archive of version1
// and validate that version2's archive is not erroneously updated.
response = Utils.readInputStream(helper.postAddModifyAppVer(version1, new File(this.getClass().getResource(VERSION_01_ZIP).getFile())).getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
modelManager.getModelService().clearPersistenceContext();
version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
Assert.assertTrue(version1.getArchive().getHash().equals(VERSION_01_HASH));
Assert.assertTrue(version1.getArchive().getFile(settings.getTemporaryStoragePath()).exists());
Assert.assertTrue(version2.getArchive().getHash().equals(VERSION_02_HASH));
Assert.assertTrue(version2.getArchive().getFile(settings.getTemporaryStoragePath()).exists());
Assert.assertNotSame(version2.getArchive(), version1.getArchive());
Result result = helper.getConnectionOpen(version1, SLIC_VERSION);
Assert.assertTrue(result.getConnectionOpenResponse().getUpdate() == null);
Assert.assertTrue(AuthTokenProvider.validateAuthToken(version1.getApplication().getProxyAuthSalt(), result.getConnectionOpenResponse().getAuthToken()));
}
use of com.openmeap.protocol.dto.Result in project OpenMEAP by OpenMEAP.
the class AdminTest method testCreateDeployments.
public void testCreateDeployments() throws Exception {
Result result = null;
ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
UpdateHeader update = null;
_createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
modelManager.getModelService().clearPersistenceContext();
Application app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 1);
result = helper.getConnectionOpen(version2, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
_createDeployment(VERSION_02, Deployment.Type.REQUIRED);
modelManager.getModelService().clearPersistenceContext();
app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 2);
result = helper.getConnectionOpen(version1, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.REQUIRED.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_02));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_02_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH + VERSION_02_BYTES_LENGTH));
_createDeployment(VERSION_02, Deployment.Type.REQUIRED);
Assert.assertTrue("as this deployment is created, the archive for version01 should be removed from the deployed location", !_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
_createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
Assert.assertTrue("as this deployment is created, the archive for version01 should be in the deployed location", _isVersionArchiveInDeployedLocation(VERSION_01_HASH));
result = helper.getConnectionOpen(version2, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
modelManager.getModelService().clearPersistenceContext();
app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 2);
Assert.assertTrue(app.getDeployments().get(0).getVersionIdentifier().equals(VERSION_02));
Assert.assertTrue(app.getDeployments().get(1).getVersionIdentifier().equals(VERSION_01));
}
use of com.openmeap.protocol.dto.Result in project OpenMEAP by OpenMEAP.
the class AdminTestHelper method getConnectionOpen.
/*
* Connection open
*/
public Result getConnectionOpen(ApplicationVersion version, String slicVersion) throws HttpRequestException, IOException, JSONException {
Hashtable<String, Object> postData = new Hashtable<String, Object>();
postData.put(UrlParamConstants.ACTION, "connection-open-request");
postData.put(UrlParamConstants.DEVICE_UUID, UUID.randomUUID());
postData.put(UrlParamConstants.APP_NAME, version.getApplication().getName());
postData.put(UrlParamConstants.APP_VERSION, version.getIdentifier());
postData.put(UrlParamConstants.APPARCH_HASH, version.getArchive().getHash());
postData.put(UrlParamConstants.SLIC_VERSION, slicVersion);
HttpResponse response = requestExecuter.postData(APP_MGMT_WEB_URL, postData);
String responseText = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
JSONObjectBuilder job = new JSONObjectBuilder();
Result result = (Result) job.fromJSON(new JSONObject(responseText), new Result());
return result;
}
use of com.openmeap.protocol.dto.Result in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServlet method service.
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Result result = new Result();
Error err = new Error();
String action = req.getParameter(UrlParamConstants.ACTION);
if (action == null)
action = "";
if (action.equals("connection-open-request")) {
result = connectionOpenRequest(req);
} else if (action.equals("archiveDownload")) {
result = handleArchiveDownload(req, resp);
if (result == null) {
return;
}
} else {
err.setCode(ErrorCode.MISSING_PARAMETER);
err.setMessage("The \"action\" parameter is not recognized, missing, or empty.");
result.setError(err);
}
try {
JSONObjectBuilder builder = new JSONObjectBuilder();
resp.setContentType("text/javascript");
JSONObject jsonResult = builder.toJSON(result);
resp.getOutputStream().write(jsonResult.toString().getBytes());
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
Aggregations