@Test public final void testCallPAP() throws PolicyException { StdPAPPolicy newPAPPolicy = new StdPAPPolicy(); String response = null; response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Config"}, UUID.randomUUID(), "Config"); assertEquals("success", response); }
public Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope) throws PolicyException { String response = null; HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { final String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Basic " + getPAPEncoding()); connection.setRequestProperty("Environment", environment); connection.setRequestProperty("ClientScope", clientScope); connection.setRequestMethod(requestMethod); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy((InputStream) content, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } } else if (content != null) { final ObjectMapper mapper = new ObjectMapper(); if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } } else { LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + requestID.toString()); } connection.connect(); responseCode = connection.getResponseCode(); if (connection.getResponseCode() > 0 || isJunit) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "PAP Response Code : " + connection.getResponseCode()); rotatePAPList(); } } catch (final Exception e) { if (isJunit) { connected = true; break; } LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); if (connection != null) { final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { response = checkResponse(connection, requestID); } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } if (isJunit) { response = SUCCESS; } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } }
PAPServices { public Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope) throws PolicyException { String response = null; HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { final String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Basic " + getPAPEncoding()); connection.setRequestProperty("Environment", environment); connection.setRequestProperty("ClientScope", clientScope); connection.setRequestMethod(requestMethod); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy((InputStream) content, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } } else if (content != null) { final ObjectMapper mapper = new ObjectMapper(); if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } } else { LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + requestID.toString()); } connection.connect(); responseCode = connection.getResponseCode(); if (connection.getResponseCode() > 0 || isJunit) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "PAP Response Code : " + connection.getResponseCode()); rotatePAPList(); } } catch (final Exception e) { if (isJunit) { connected = true; break; } LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); if (connection != null) { final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { response = checkResponse(connection, requestID); } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } if (isJunit) { response = SUCCESS; } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } } }
PAPServices { public Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope) throws PolicyException { String response = null; HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { final String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Basic " + getPAPEncoding()); connection.setRequestProperty("Environment", environment); connection.setRequestProperty("ClientScope", clientScope); connection.setRequestMethod(requestMethod); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy((InputStream) content, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } } else if (content != null) { final ObjectMapper mapper = new ObjectMapper(); if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } } else { LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + requestID.toString()); } connection.connect(); responseCode = connection.getResponseCode(); if (connection.getResponseCode() > 0 || isJunit) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "PAP Response Code : " + connection.getResponseCode()); rotatePAPList(); } } catch (final Exception e) { if (isJunit) { connected = true; break; } LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); if (connection != null) { final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { response = checkResponse(connection, requestID); } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } if (isJunit) { response = SUCCESS; } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } } PAPServices(); }
PAPServices { public Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope) throws PolicyException { String response = null; HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { final String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Basic " + getPAPEncoding()); connection.setRequestProperty("Environment", environment); connection.setRequestProperty("ClientScope", clientScope); connection.setRequestMethod(requestMethod); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy((InputStream) content, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } } else if (content != null) { final ObjectMapper mapper = new ObjectMapper(); if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } } else { LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + requestID.toString()); } connection.connect(); responseCode = connection.getResponseCode(); if (connection.getResponseCode() > 0 || isJunit) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "PAP Response Code : " + connection.getResponseCode()); rotatePAPList(); } } catch (final Exception e) { if (isJunit) { connected = true; break; } LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); if (connection != null) { final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { response = checkResponse(connection, requestID); } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } if (isJunit) { response = SUCCESS; } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } } PAPServices(); static void setJunit(final boolean isJunit); static void setPaps(final List<String> paps); int getResponseCode(); Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope); String getActiveVersion(final String policyScope, final String filePrefix, final String policyName,
            final String clientScope, final UUID requestID); StdPDPPolicy pushPolicy(final String policyScope, final String filePrefix, final String policyName,
            final String clientScope, final String pdpGroup, UUID requestID); }
PAPServices { public Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope) throws PolicyException { String response = null; HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { final String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Basic " + getPAPEncoding()); connection.setRequestProperty("Environment", environment); connection.setRequestProperty("ClientScope", clientScope); connection.setRequestMethod(requestMethod); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy((InputStream) content, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } } else if (content != null) { final ObjectMapper mapper = new ObjectMapper(); if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } } else { LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + requestID.toString()); } connection.connect(); responseCode = connection.getResponseCode(); if (connection.getResponseCode() > 0 || isJunit) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "PAP Response Code : " + connection.getResponseCode()); rotatePAPList(); } } catch (final Exception e) { if (isJunit) { connected = true; break; } LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); if (connection != null) { final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { response = checkResponse(connection, requestID); } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } if (isJunit) { response = SUCCESS; } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } } PAPServices(); static void setJunit(final boolean isJunit); static void setPaps(final List<String> paps); int getResponseCode(); Object callPAP(final Object content, final String[] parameters, UUID requestID, final String clientScope); String getActiveVersion(final String policyScope, final String filePrefix, final String policyName,
            final String clientScope, final UUID requestID); StdPDPPolicy pushPolicy(final String policyScope, final String filePrefix, final String policyName,
            final String clientScope, final String pdpGroup, UUID requestID);  }