use of com.openmeap.http.HttpResponse 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.http.HttpResponse in project OpenMEAP by OpenMEAP.
the class FirstRunCheck method run.
public void run() {
if (config.isDevelopmentMode().equals(Boolean.TRUE)) {
return;
}
if (config.getNotFirstRun() == null) {
config.setNotFirstRun(Boolean.TRUE);
try {
String macWithSalt = macAddress + ".OPENMEAP#$!@3__234";
String hashValue = Utils.hashInputStream("sha1", new ByteArrayInputStream(macWithSalt.getBytes("UTF-8")));
HttpResponse response = executer.get("http://usage.openmeap.com/tracker.gif?hash=" + hashValue);
Utils.consumeInputStream(response.getResponseBody());
} catch (Exception ioe) {
// again, we don't want to be a bother here...let's just bail
return;
}
}
}
use of com.openmeap.http.HttpResponse 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.http.HttpResponse in project OpenMEAP by OpenMEAP.
the class AdminTest method testAddApplication.
public void testAddApplication() throws Exception {
Application app = new Application();
app.setName(APP_NAME);
app.setDescription(APP_DESC);
app.setDeploymentHistoryLength(APP_DEPL_LEN);
app.setVersionAdmins(APP_VERSION_ADMINS);
app.setAdmins(APP_ADMINS);
app.setInitialVersionIdentifier(VERSION_ORIG);
HttpResponse response = helper.postAddModifyApp(app);
Assert.assertTrue(response.getStatusCode() == 200);
String output = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
Assert.assertTrue(output.contains(APP_ADDMODIFY_SUCCESS));
// Now check the database, to make sure everything got in there
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp != null);
helper.assertSame(app, dbApp);
Assert.assertTrue(dbApp.getProxyAuthSalt() != null && dbApp.getProxyAuthSalt().length() == 36);
}
use of com.openmeap.http.HttpResponse in project OpenMEAP by OpenMEAP.
the class AdminTest method testDeleteApplication.
public void testDeleteApplication() throws Exception {
ModelManager modelManager = helper.getModelManager();
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
HttpResponse response = helper.postAddModifyApp_delete(dbApp);
modelManager.getModelService().clearPersistenceContext();
dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp == null);
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_02_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_02_HASH));
}
Aggregations