+
+ private void sendCurrPolicyConfig(String method, final HttpURLConnection connection, InputStream contentObj) {
+ try {
+ //
+ // Send our current policy configuration
+ //
+ try (OutputStream os = connection.getOutputStream()) {
+ int count = IOUtils.copy(contentObj, os);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("copied to output, bytes=" + count);
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to write content in '" + method + "'", e);
+ }
+ }
+
+ private String getJsonString(final HttpURLConnection connection) throws IOException {
+ String json;
+ // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
+ try (java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream())) {
+ scanner.useDelimiter("\\A");
+ json = scanner.hasNext() ? scanner.next() : "";
+ } catch (Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to read inputStream from connection: " + e,
+ e);
+ throw e;
+ }
+ LOGGER.info("JSON response from PAP: " + json);
+ return json;
+ }
+
+ // these may be overridden by junit tests
+
+ protected URLConnection makeConnection(String fullUrl) throws IOException {
+ return new URL(fullUrl).openConnection();
+ }