Search in sources :

Example 1 with HttpResponse

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;
}
Also used : InputSource(org.xml.sax.InputSource) JSONObjectBuilder(com.openmeap.json.JSONObjectBuilder) WebServiceException(com.openmeap.protocol.WebServiceException) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) Hashtable(java.util.Hashtable) HttpResponse(com.openmeap.http.HttpResponse) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) WebServiceException(com.openmeap.protocol.WebServiceException) IOException(java.io.IOException) HttpRequestException(com.openmeap.http.HttpRequestException) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) Result(com.openmeap.protocol.dto.Result)

Example 2 with HttpResponse

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;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpResponse(com.openmeap.http.HttpResponse)

Example 3 with HttpResponse

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;
}
Also used : JSONObjectBuilder(com.openmeap.json.JSONObjectBuilder) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) Hashtable(java.util.Hashtable) HttpResponse(com.openmeap.http.HttpResponse) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) Result(com.openmeap.protocol.dto.Result)

Example 4 with HttpResponse

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);
}
Also used : HttpResponse(com.openmeap.http.HttpResponse) Application(com.openmeap.model.dto.Application)

Example 5 with HttpResponse

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));
}
Also used : HttpResponse(com.openmeap.http.HttpResponse) ModelManager(com.openmeap.model.ModelManager) Application(com.openmeap.model.dto.Application)

Aggregations

HttpResponse (com.openmeap.http.HttpResponse)9 JSONObjectBuilder (com.openmeap.json.JSONObjectBuilder)3 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)3 Hashtable (java.util.Hashtable)3 HttpRequestException (com.openmeap.http.HttpRequestException)2 Application (com.openmeap.model.dto.Application)2 Result (com.openmeap.protocol.dto.Result)2 IOException (java.io.IOException)2 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)1 ClusterNodeRequest (com.openmeap.cluster.dto.ClusterNodeRequest)1 EventNotificationException (com.openmeap.event.EventNotificationException)1 HttpHeader (com.openmeap.http.HttpHeader)1 HttpRequestExecuter (com.openmeap.http.HttpRequestExecuter)1 ModelManager (com.openmeap.model.ModelManager)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 ModelEntityEvent (com.openmeap.model.event.ModelEntityEvent)1 WebServiceException (com.openmeap.protocol.WebServiceException)1 ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)1 Result (com.openmeap.services.dto.Result)1 LocalStorageException (com.openmeap.thinclient.LocalStorageException)1