ConsoleAndApiService { public void doAcGet(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { try { String parameterDefault = request.getParameter("default"); String pdpId = request.getParameter(PDP_ID); String pdpGroup = request.getParameter("getPDPGroup"); if ("".equals(groupId)) { if (parameterDefault != null) { loggingContext.setServiceName("AC:PAP.getDefaultGroup"); OnapPDPGroup group = papEngine.getDefaultGroup(); mapperWriteValue(new ObjectMapper(), response, group); if (LOGGER.isDebugEnabled()) { LOGGER.debug("GET Default group req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { LOGGER.error(e); } loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); return; } else if (pdpId != null) { if (pdpGroup == null) { loggingContext.setServiceName("AC:PAP.getPDP"); OnapPDP pdp = null; try { pdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } mapperWriteValue(new ObjectMapper(), response, pdp); if (LOGGER.isDebugEnabled()) { LOGGER.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { LOGGER.error(e); } loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); return; } else { loggingContext.setServiceName("AC:PAP.getGroupForPDP"); OnapPDPGroup group = null; try { OnapPDP pdp = papEngine.getPDP(pdpId); group = papEngine.getPDPGroup(pdp); } catch (PAPException e) { LOGGER.error(e); } mapperWriteValue(new ObjectMapper(), response, group); if (LOGGER.isDebugEnabled()) { LOGGER.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { LOGGER.error(e); } loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); return; } } else { loggingContext.setServiceName("AC:PAP.getAllGroups"); Set<OnapPDPGroup> groups = null; try { groups = papEngine.getOnapPDPGroups(); } catch (PAPException e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC Get exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return; } mapperWriteValue(new ObjectMapper(), response, groups); if (LOGGER.isDebugEnabled()) { LOGGER.debug("GET All groups req"); } response.setStatus(HttpServletResponse.SC_OK); response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { LOGGER.error(e); } loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); return; } } OnapPDPGroup group = null; try { group = papEngine.getGroup(groupId); } catch (PAPException e) { LOGGER.error(e); } if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; if (!message.matches(REGEX)) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.addHeader(ERROR, ADD_GROUP_ERROR); response.addHeader(MESSAGE, "Group Id is not valid"); return; } PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); return; } String policyId = request.getParameter(POLICYID); if (policyId != null) { loggingContext.setServiceName("AC:PAP.getPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " GET Policy not implemented"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "GET Policy not implemented"); } else { loggingContext.setServiceName("AC:PAP.getGroup"); mapperWriteValue(new ObjectMapper(), response, group); if (LOGGER.isDebugEnabled()) { LOGGER.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { LOGGER.error(e); } loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); return; } PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " UNIMPLEMENTED "); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); } catch (PAPException e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC Get exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }  void doAcPost(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcGet(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcDelete(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine);  }
@Test public void testGet() throws Exception { stdEngine = new StdEngine(Paths.get("src", "test", "resources", "pdps")); dbd.setPapEngine(stdEngine); Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL); Mockito.when(httpServletRequest.getMethod()).thenReturn("GET"); Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2); Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API); Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn("http: Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(""); consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine); assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus()); httpServletResponse = new MockHttpServletResponse(); Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(DEFAULT); consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine); assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus()); Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn(null); Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(null); consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine); assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus()); Mockito.when(httpServletRequest.getParameter("getPDPGroup")).thenReturn(TESTGROUP2); Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGROUP2); consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, TESTGROUP2, logContext, stdEngine); assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus()); }