@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Unexpected response '").append(response.getStatusCode()).append("' with message '"); sb.append(response.getStatusText()).append("'"); return sb.toString(); } }
private void callSyncHandler(String addonKey, final boolean addonUsesJwtAuthentication, URI callbackUri, String jsonEventData, Optional<String> authHeader) throws LifecycleCallbackException { // try distributing prod shared secrets over http (note the lack of "s") and it shall be rejected if (!systemPropertyService.isDevMode() && !systemPropertyService.isHttpAllowedMode() && addonUsesJwtAuthentication && !callbackUri.getScheme().toLowerCase().startsWith("https")) { String message = String.format("Cannot issue callback except via HTTPS. Current URL = '%s'", callbackUri); throw new LifecycleCallbackException(message, "connect.remote.upm.install.exception"); } Response response = getSyncHandlerResponse(addonKey, callbackUri, jsonEventData, authHeader); final int statusCode = response.getStatusCode(); // a selection of 2xx response codes both indicate success and are semantically valid for this callback if (!OK_INSTALL_HTTP_CODES.contains(statusCode)) { String statusText = response.getStatusText(); String responseEntity = response.getEntity(); // calling response.getEntity() multiple times results in IllegalStateException("Entity may only be accessed once") log.error("Error contacting remote application at " + callbackUri + " " + statusCode + ":[" + statusText + "]:" + responseEntity); String message = "Error contacting remote application " + statusCode + ":[" + statusText + "]:" + responseEntity; throw new LifecycleCallbackHttpCodeException(message, findI18nKeyForHttpErrorCode(statusCode), statusCode); } }
private void callSyncHandler(String addonKey, final boolean addonUsesJwtAuthentication, URI callbackUri, String jsonEventData, Optional<String> authHeader) throws LifecycleCallbackException { // try distributing prod shared secrets over http (note the lack of "s") and it shall be rejected if (!systemPropertyService.isDevMode() && !systemPropertyService.isHttpAllowedMode() && addonUsesJwtAuthentication && !callbackUri.getScheme().toLowerCase().startsWith("https")) { String message = String.format("Cannot issue callback except via HTTPS. Current URL = '%s'", callbackUri); throw new LifecycleCallbackException(message, "connect.remote.upm.install.exception"); } Response response = getSyncHandlerResponse(addonKey, callbackUri, jsonEventData, authHeader); final int statusCode = response.getStatusCode(); // a selection of 2xx response codes both indicate success and are semantically valid for this callback if (!OK_INSTALL_HTTP_CODES.contains(statusCode)) { String statusText = response.getStatusText(); String responseEntity = response.getEntity(); // calling response.getEntity() multiple times results in IllegalStateException("Entity may only be accessed once") log.error("Error contacting remote application at " + callbackUri + " " + statusCode + ":[" + statusText + "]:" + responseEntity); String message = "Error contacting remote application " + statusCode + ":[" + statusText + "]:" + responseEntity; throw new LifecycleCallbackHttpCodeException(message, findI18nKeyForHttpErrorCode(statusCode), statusCode); } }