@Test public void testConfigMicroserviceParameterHandling() throws Exception { PolicyParameters parameters = createParametersObject(); parameters.setPolicyConfigType(PolicyConfigType.MicroService); PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper(); assertNull(wrapper.populateRequestParameters((parameters))); parameters.setConfigBody("{\"someParameter\": \"someValue\"}"); PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters)); assertEquals("Micro Service", adapter.getConfigPolicyType()); parameters.setConfigBody("{\"service\": \"MyService\"}"); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("MyService", adapter.getServiceType()); parameters.setConfigBody("{\"content\": \"{}\"}"); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("\"{}\"", adapter.getPolicyJSON().toString()); parameters.setConfigBody("{\"content\": {hess:}}"); assertNull(wrapper.populateRequestParameters((parameters))); }
public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; } }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters); }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters);  }