/** * 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); }
/** * 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 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; }
@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 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; } }
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()));