@Test public final void testGetActiveVersion() { String activeVersion = papServices.getActiveVersion("test", "Config_", "test.testpolicy", "Config", UUID.randomUUID()); assertNull(activeVersion); }
public String getActiveVersion(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final UUID requestID) { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); if (parameters != null && parameters.length > 0) { String queryString = ""; for (final String p : parameters) { queryString += "&" + p; } fullURL += "?" + queryString.substring(1); } final URL url = new URL(fullURL); 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("GET"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); connection.connect(); if (connection.getResponseCode() > 0) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); } } catch (final Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { if (connection.getResponseCode() == 200) { version = connection.getHeaderField("version"); LOGGER.debug("ActiveVersion from the Header: " + version); } else if (connection.getResponseCode() == 403) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); version = "pe100"; } else if (connection.getResponseCode() == 404) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. " + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); } } else { LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); } } return version; }
PAPServices { public String getActiveVersion(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final UUID requestID) { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); if (parameters != null && parameters.length > 0) { String queryString = ""; for (final String p : parameters) { queryString += "&" + p; } fullURL += "?" + queryString.substring(1); } final URL url = new URL(fullURL); 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("GET"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); connection.connect(); if (connection.getResponseCode() > 0) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); } } catch (final Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { if (connection.getResponseCode() == 200) { version = connection.getHeaderField("version"); LOGGER.debug("ActiveVersion from the Header: " + version); } else if (connection.getResponseCode() == 403) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); version = "pe100"; } else if (connection.getResponseCode() == 404) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. " + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); } } else { LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); } } return version; } }
PAPServices { public String getActiveVersion(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final UUID requestID) { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); if (parameters != null && parameters.length > 0) { String queryString = ""; for (final String p : parameters) { queryString += "&" + p; } fullURL += "?" + queryString.substring(1); } final URL url = new URL(fullURL); 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("GET"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); connection.connect(); if (connection.getResponseCode() > 0) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); } } catch (final Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { if (connection.getResponseCode() == 200) { version = connection.getHeaderField("version"); LOGGER.debug("ActiveVersion from the Header: " + version); } else if (connection.getResponseCode() == 403) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); version = "pe100"; } else if (connection.getResponseCode() == 404) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. " + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); } } else { LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); } } return version; } PAPServices(); }
PAPServices { public String getActiveVersion(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final UUID requestID) { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); if (parameters != null && parameters.length > 0) { String queryString = ""; for (final String p : parameters) { queryString += "&" + p; } fullURL += "?" + queryString.substring(1); } final URL url = new URL(fullURL); 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("GET"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); connection.connect(); if (connection.getResponseCode() > 0) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); } } catch (final Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { if (connection.getResponseCode() == 200) { version = connection.getHeaderField("version"); LOGGER.debug("ActiveVersion from the Header: " + version); } else if (connection.getResponseCode() == 403) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); version = "pe100"; } else if (connection.getResponseCode() == 404) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. " + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); } } else { LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); } } return version; } 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 String getActiveVersion(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final UUID requestID) { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { int papsCount = 0; boolean connected = false; while (papsCount < paps.size()) { try { String fullURL = getPAP(); if (parameters != null && parameters.length > 0) { String queryString = ""; for (final String p : parameters) { queryString += "&" + p; } fullURL += "?" + queryString.substring(1); } final URL url = new URL(fullURL); 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("GET"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); connection.connect(); if (connection.getResponseCode() > 0) { connected = true; break; } else { LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); } } catch (final Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); rotatePAPList(); } papsCount++; } if (connected) { LOGGER.debug("connected to the PAP : " + getPAP()); LOGGER.debug("--- Response: ---"); final Map<String, List<String>> headers = connection.getHeaderFields(); for (final String key : headers.keySet()) { LOGGER.debug("Header :" + key + " Value: " + headers.get(key)); } try { if (connection.getResponseCode() == 200) { version = connection.getHeaderField("version"); LOGGER.debug("ActiveVersion from the Header: " + version); } else if (connection.getResponseCode() == 403) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); version = "pe100"; } else if (connection.getResponseCode() == 404) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. " + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); } } else { LOGGER.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); } } return version; } 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);  }