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));
}
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());
}
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);
}
}
}
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);
}
}
Aggregations