public static void getHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'GET' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode != 200) { throw new IOException("Unsucessful response code " + responseCode); } }
protected void pushToController(String releaseId, String containerId, String alias) throws Exception { String[] gav = releaseId.split(":"); String jsonPayload = CONTAINER_SPEC_JSON .replaceFirst("#1@", containerId) .replaceFirst("#2@", alias) .replaceFirst("#3@", gav[0]) .replaceFirst("#4@", gav[1]) .replaceFirst("#5@", gav[2]); HttpUtils.putHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId, jsonPayload); log.infof("Added %s container into controller at %s ", containerId, CONTROLLER); }
protected void dropFromController(String containerId) throws Exception { HttpUtils.deleteHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId); log.infof("Removed %s container from controller at %s ", containerId, CONTROLLER); }
HttpUtils.getHttpCall(fHost.getServerUrl()); log.info("Server at " + fHost.getServerUrl() + " is back online"); failedHostsReconnects.cancel(false);
protected void disconnectToController() { if (CONTROLLER == null) { return; } try { HttpUtils.deleteHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId() + "/?location=" + URLEncoder.encode(KieServerInfoHandler.getLocationUrl(), "UTF-8")); log.infof("KieServerRouter disconnected from controller at " + CONTROLLER); } catch (Exception e) { log.error("Error when disconnecting from controller at " + CONTROLLER, e); } }
HttpUtils.getHttpCall(fHost.getServerUrl()); log.info("Server at " + fHost.getServerUrl() + " is back online"); failedHostsReconnects.cancel(false);
public static void deleteHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("DELETE"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'DELETE' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 204) { throw new IOException("Unsucessful response code " + responseCode); } }
protected void pushToController(String releaseId, String containerId, String alias) throws Exception { String[] gav = releaseId.split(":"); String jsonPayload = CONTAINER_SPEC_JSON .replaceFirst("#1@", containerId) .replaceFirst("#2@", alias) .replaceFirst("#3@", gav[0]) .replaceFirst("#4@", gav[1]) .replaceFirst("#5@", gav[2]); HttpUtils.putHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId, jsonPayload); log.infof("Added %s container into controller at %s ", containerId, CONTROLLER); }
protected void disconnectToController() { if (CONTROLLER == null) { return; } try { HttpUtils.deleteHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId() + "/?location=" + URLEncoder.encode(KieServerInfoHandler.getLocationUrl(), "UTF-8")); log.infof("KieServerRouter disconnected from controller at " + CONTROLLER); } catch (Exception e) { log.error("Error when disconnecting from controller at " + CONTROLLER, e); } }
public static void deleteHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("DELETE"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'DELETE' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 204) { throw new IOException("Unsucessful response code " + responseCode); } }
String jsonResponse = HttpUtils.putHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId(), SERVER_INFO_JSON); log.debugf("Controller response :: ", String jsonResponse = HttpUtils.putHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId(), SERVER_INFO_JSON); log.debugf("Controller response :: ",
protected void dropFromController(String containerId) throws Exception { HttpUtils.deleteHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId); log.infof("Removed %s container from controller at %s ", containerId, CONTROLLER); }
public static void getHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'GET' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode != 200) { throw new IOException("Unsucessful response code " + responseCode); } }
String jsonResponse = HttpUtils.putHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId(), SERVER_INFO_JSON); log.debugf("Controller response :: ", String jsonResponse = HttpUtils.putHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId(), SERVER_INFO_JSON); log.debugf("Controller response :: ",
public static String putHttpCall(String url, String body) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("PUT"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); if (body != null) { con.getOutputStream().write(body.getBytes("UTF-8")); } log.debugf("Sending 'PUT' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 201) { throw new IOException("Unsucessful response code " + responseCode); } BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); }
public static String putHttpCall(String url, String body) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("PUT"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); if (body != null) { con.getOutputStream().write(body.getBytes("UTF-8")); } log.debugf("Sending 'PUT' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 201) { throw new IOException("Unsucessful response code " + responseCode); } BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); }