/** * Execute http response. * * @param url the url * @param method the method * @param basicAuthUsername the basic auth username * @param basicAuthPassword the basic auth password * @param parameters the parameters * @param headers the headers * @return the http response */ public static HttpResponse execute(final String url, final String method, final String basicAuthUsername, final String basicAuthPassword, final Map<String, Object> parameters, final Map<String, Object> headers) { return execute(url, method, basicAuthUsername, basicAuthPassword, parameters, headers, null); }
/** * Fetch metadata http response. * * @param metadataLocation the metadata location * @return the http response */ protected HttpResponse fetchMetadata(final String metadataLocation) { LOGGER.debug("Fetching metadata from [{}]", metadataLocation); return HttpUtils.executeGet(metadataLocation, new LinkedHashMap<>()); }
/** * Execute post http response. * * @param url the url * @param entity the json entity * @param parameters the parameters * @return the http response */ public static HttpResponse executePost(final String url, final String entity, final Map<String, Object> parameters) { return executePost(url, null, null, entity, parameters); }
@Override @SneakyThrows public void decorate(final RequestContext requestContext, final ApplicationContext applicationContext) { HttpResponse response = null; try { response = HttpUtils.execute(restProperties.getUrl(), restProperties.getUrl(), restProperties.getBasicAuthUsername(), restProperties.getBasicAuthPassword()); val statusCode = response.getStatusLine().getStatusCode(); if (response != null && HttpStatus.valueOf(statusCode).is2xxSuccessful()) { val jsonObject = MAPPER.readValue(response.getEntity().getContent(), Map.class); requestContext.getFlowScope().put("decoration", jsonObject); } } finally { HttpUtils.close(response); } } }
val redirectUrl = encoder.getRedirectUrl(); LOGGER.trace("Final logout redirect URL is [{}]", redirectUrl); response = HttpUtils.executeGet(redirectUrl); } else { val payload = SerializeSupport.nodeToString(XMLObjectSupport.marshall(logoutRequest)); LOGGER.trace("Logout message encoded in base64 is [{}]", message); response = HttpUtils.executePost(msg.getUrl().toExternalForm(), CollectionUtils.wrap("SAMLRequest", message), CollectionUtils.wrap("Content-Type", msg.getContentType())); LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response);
HttpResponse response = null; try { response = HttpUtils.executeGet(url); if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); HttpUtils.close(response);
@Override public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) { HttpResponse response = null; try (val writer = new StringWriter()) { MAPPER.writer(new MinimalPrettyPrinter()).writeValue(writer, attributes); response = HttpUtils.executePost(this.endpoint, writer.toString(), CollectionUtils.wrap("principal", principal.getId(), "service", service.getServiceId())); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return MAPPER.readValue(response.getEntity().getContent(), new TypeReference<Map<String, Object>>() { }); } } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response); } return new HashMap<>(0); }
@Override public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service) { HttpResponse response = null; try { val metadataLocation = getMetadataLocationForService(service); LOGGER.info("Loading SAML metadata from [{}]", metadataLocation); val metadataResource = new UrlResource(metadataLocation); val backupFile = getMetadataBackupFile(metadataResource, service); val canonicalPath = backupFile.getCanonicalPath(); LOGGER.debug("Metadata backup file will be at [{}]", canonicalPath); FileUtils.forceMkdirParent(backupFile); response = fetchMetadata(metadataLocation); cleanUpExpiredBackupMetadataFilesFor(metadataResource, service); if (response != null) { val status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); if (shouldHttpResponseStatusBeProcessed(status)) { val metadataProvider = getMetadataResolverFromResponse(response, backupFile); configureAndInitializeSingleMetadataResolver(metadataProvider, service); return CollectionUtils.wrap(metadataProvider); } } } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response); } return new ArrayList<>(0); }
val url = resource.getURL().toExternalForm(); LOGGER.debug("Executing URL [{}] to determine theme for [{}]", url, service.getId()); response = HttpUtils.executeGet(url, CollectionUtils.wrap("service", service.getId())); if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response);
@Override public boolean send(final String from, final String to, final String message) { HttpResponse response = null; try { val parameters = new HashMap<String, Object>(); val holder = ClientInfoHolder.getClientInfo(); if (holder != null) { parameters.put("clientIpAddress", holder.getClientIpAddress()); parameters.put("serverIpAddress", holder.getServerIpAddress()); } parameters.put("from", from); parameters.put("to", to); response = HttpUtils.executePost(restProperties.getUrl(), restProperties.getBasicAuthUsername(), restProperties.getBasicAuthPassword(), message, parameters); if (response != null) { val status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); return status.is2xxSuccessful(); } } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response); } return false; } }
response = HttpUtils.execute(rest.getUrl(), rest.getMethod(), rest.getBasicAuthUsername(), rest.getBasicAuthPassword(), headers); val statusCode = response.getStatusLine().getStatusCode(); if (response != null && HttpStatus.valueOf(statusCode).is2xxSuccessful()) { LOGGER.error(e.getMessage(), e); } finally { HttpUtils.close(response);
/** * Execute http response. * * @param url the url * @param method the method * @param headers the headers * @return the http response */ public static HttpResponse execute(final String url, final String method, final Map<String, Object> headers) { return execute(url, method, null, null, new HashMap<>(), headers); }
/** * Execute get http response. * * @param url the url * @param parameters the parameters * @return the http response */ public static HttpResponse executeGet(final String url, final Map<String, Object> parameters) { try { return executeGet(url, null, null, parameters); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return null; }
/** * Execute post http response. * * @param url the url * @param basicAuthUsername the basic auth username * @param basicAuthPassword the basic auth password * @param entity the json entity * @return the http response */ public static HttpResponse executePost(final String url, final String basicAuthUsername, final String basicAuthPassword, final String entity) { return executePost(url, basicAuthUsername, basicAuthPassword, entity, new HashMap<>()); }
/** * Execute http response. * * @param url the url * @param method the method * @param basicAuthUsername the basic auth username * @param basicAuthPassword the basic auth password * @param headers the headers * @return the http response */ public static HttpResponse execute(final String url, final String method, final String basicAuthUsername, final String basicAuthPassword, final Map<String, Object> headers) { return execute(url, method, basicAuthUsername, basicAuthPassword, new HashMap<>(), headers); }
/** * Execute get http response. * * @param url the url * @return the http response */ public static HttpResponse executeGet(final String url) { try { return executeGet(url, null, null, new LinkedHashMap<>()); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return null; }
/** * Execute post http response. * * @param url the url * @param basicAuthUsername the basic auth username * @param basicAuthPassword the basic auth password * @param entity the json entity * @param parameters the parameters * @return the http response */ public static HttpResponse executePost(final String url, final String basicAuthUsername, final String basicAuthPassword, final String entity, final Map<String, Object> parameters) { try { return executePost(url, basicAuthUsername, basicAuthPassword, entity, parameters, new HashMap<>()); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return null; }