PAPServices { public StdPDPPolicy pushPolicy(final String policyScope, final String filePrefix, final String policyName, final String clientScope, final String pdpGroup, UUID requestID) throws PolicyException { final String json = "{ " + "\"apiflag\": \"api\"," + "\"policyScope\": \"" + policyScope + "\"," + "\"filePrefix\": \"" + filePrefix + "\"," + "\"policyName\": \"" + policyName + "\"," + "\"clientScope\": \"" + clientScope + "\"," + "\"pdpGroup\": \"" + pdpGroup + "\"}"; 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 = (fullURL.endsWith("/")) ? fullURL + "onap/pushPolicy" : fullURL + "/onap/pushPolicy"; final URL url = new URL(fullURL); LOGGER.debug("--- Sending Request to PAP : " + url.toString() + " ---"); 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("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); if (requestID == null) { requestID = UUID.randomUUID(); LOGGER.info("No request ID provided, sending generated ID: " + requestID.toString()); } else { LOGGER.info("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); try (OutputStream os = connection.getOutputStream()) { final int count = IOUtils.copy(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes=" + count); } } 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 { if (responseCode == 202) { final StdPDPPolicy policy = (StdPDPPolicy) new ObjectInputStream(connection.getInputStream()).readObject(); return policy; } } catch (IOException | ClassNotFoundException e) { LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); throw new PolicyException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Decoding the result ", e); } } return null; } else { return null; } } 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);  }
@Test public final void testPushPolicy() throws PolicyException { StdPDPPolicy selectedPolicy = papServices.pushPolicy("test", "Config_", "test.testpolicy", "Config", "default", UUID.randomUUID()); assertNull(selectedPolicy); }