Search in sources :

Example 6 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)

Example 7 with HttpResponse

use of com.openmeap.http.HttpResponse in project OpenMEAP by OpenMEAP.

the class AdminTest method testLogin.

public void testLogin() throws Exception {
    HttpResponse response = helper.getLogin();
    Utils.consumeInputStream(response.getResponseBody());
    response = helper.postLogin(AdminTestHelper.ADMIN_USER, AdminTestHelper.ADMIN_PASS);
    Assert.assertTrue(response.getStatusCode() == 302);
    HttpHeader[] headers = response.getHeaders("Location");
    Assert.assertTrue(headers.length == 1);
    Assert.assertTrue(headers[0].getValue().equals(helper.getAdminUrl()));
    Utils.consumeInputStream(response.getResponseBody());
    // Tomcat will shoot you in the face if you don't follow it's redirects
    response = helper.getRequestExecuter().get(headers[0].getValue());
    Utils.consumeInputStream(response.getResponseBody());
}
Also used : HttpHeader(com.openmeap.http.HttpHeader) HttpResponse(com.openmeap.http.HttpResponse)

Example 8 with HttpResponse

use of com.openmeap.http.HttpResponse in project OpenMEAP by OpenMEAP.

the class ClusterNodeHealthCheckThread method _run.

private void _run() {
    settings = modelManager.getGlobalSettings();
    JSONObjectBuilder builder = new JSONObjectBuilder();
    ClusterNodeRequest request = new ClusterNodeRequest();
    request.setSubject(ClusterNodeRequest.HEALTH_CHECK);
    lastCheckExceptions = new Vector<Exception>();
    while (true) {
        synchronized (this) {
            lastCheckExceptions.clear();
            if (settings.getClusterNodes() != null) {
                for (ClusterNode clusterNode : settings.getClusterNodes()) {
                    try {
                        request.setClusterNode(clusterNode);
                        HttpResponse response = null;
                        try {
                            response = httpRequestExecuter.postContent(clusterNode.getServiceWebUrlPrefix() + "/service-management/?action=" + ClusterNodeRequest.HEALTH_CHECK + "&auth=" + AuthTokenProvider.newAuthToken(settings.getServiceManagementAuthSalt()), builder.toJSON(request).toString(3), FormConstants.CONT_TYPE_JSON);
                        } catch (Exception e) {
                            logger.error(clusterNode.getServiceWebUrlPrefix() + " health check returned exception", e);
                            Throwable t = ExceptionUtils.getRootCause(e);
                            ClusterNode.Status err = null;
                            if (t instanceof ConnectException) {
                                err = ClusterNode.Status.CONNECT_ERROR;
                            } else {
                                err = ClusterNode.Status.ERROR;
                            }
                            synchronized (clusterNode) {
                                clusterNode.setLastStatus(err);
                                clusterNode.setLastStatusMessage(t.getMessage());
                                clusterNode.setLastStatusCheck(new Date());
                            }
                            if (response != null && response.getResponseBody() != null) {
                                Utils.consumeInputStream(response.getResponseBody());
                                response.getResponseBody().close();
                            }
                            continue;
                        }
                        if (response != null && response.getStatusCode() == 200) {
                            String json = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
                            JSONObject jsonObj = new JSONObject(json);
                            Result result = (Result) builder.fromJSON(jsonObj, new Result());
                            response.getResponseBody().close();
                            synchronized (clusterNode) {
                                clusterNode.setLastStatus(result.getStatus() == Result.Status.SUCCESS ? ClusterNode.Status.GOOD : ClusterNode.Status.ERROR);
                                clusterNode.setLastStatusMessage(result.getMessage());
                                clusterNode.setLastStatusCheck(new Date());
                            }
                        } else {
                            synchronized (clusterNode) {
                                clusterNode.setLastStatus(ClusterNode.Status.ERROR);
                                String msg = "Service node " + clusterNode.getServiceWebUrlPrefix() + " returned a non-200 status code " + response.getStatusCode() + " " + Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
                                logger.error(msg);
                                clusterNode.setLastStatusMessage(msg);
                                response.getResponseBody().close();
                                clusterNode.setLastStatusCheck(new Date());
                            }
                        }
                    } catch (Exception e) {
                        logger.error("Exception performing health check", e);
                        lastCheckExceptions.add(e);
                    }
                }
            }
        }
        synchronized (lastCheckExceptions) {
            lastCheckExceptions.notifyAll();
        }
        try {
            Thread.sleep(checkInterval);
        } catch (InterruptedException e) {
            logger.error("Nap interrupted!", e);
        }
    }
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) HttpResponse(com.openmeap.http.HttpResponse) ClusterNodeRequest(com.openmeap.cluster.dto.ClusterNodeRequest) ConnectException(java.net.ConnectException) Date(java.util.Date) Result(com.openmeap.services.dto.Result) JSONObjectBuilder(com.openmeap.json.JSONObjectBuilder) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) ConnectException(java.net.ConnectException)

Example 9 with HttpResponse

use of com.openmeap.http.HttpResponse in project OpenMEAP by OpenMEAP.

the class AbstractModelServiceClusterServiceMgmtNotifier method makeRequest.

@Override
protected void makeRequest(URL url, Event<T> message) throws ClusterNotificationException {
    try {
        ModelEntityEvent event = (ModelEntityEvent) message;
        T modelEntity = (T) event.getPayload();
        String authToken = newAuthToken();
        Hashtable<String, Object> parms = new Hashtable<String, Object>();
        ;
        parms.put(UrlParamConstants.CLUSTERNODE_KEY, url.toString());
        String sendUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/?" + UrlParamConstants.ACTION + "=" + getEventActionName() + "&" + UrlParamConstants.AUTH_TOKEN + "=" + authToken;
        addRequestParameters(modelEntity, parms);
        logger.debug("Notification to {} with params {}", sendUrl, parms);
        HttpResponse response = this.getHttpRequestExecuter().postData(sendUrl, parms);
        int statusCode = response.getStatusCode();
        logger.debug("Notification to {} returned status code {}", sendUrl, statusCode);
        if (statusCode != 200) {
            String responseText = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
            logger.error(responseText);
            throw new ClusterNotificationException(url, String.format("Notification to %s returned status code %s and response text was ", sendUrl, statusCode));
        } else {
            Utils.consumeInputStream(response.getResponseBody());
        }
    } catch (Exception e) {
        throw new ClusterNotificationException(url, e.getMessage(), e);
    }
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) HttpResponse(com.openmeap.http.HttpResponse) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) EventNotificationException(com.openmeap.event.EventNotificationException)

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