@Test public void testParse_QueryInBody() throws BodyParseException { RequestBodyParser parser = new JsonRequestBodyParser(); RequestBody body = parser.parse(serviceJsonWithQuery).iterator().next(); Set<NamedPropertySet> setProps = body.getNamedPropertySets(); assertEquals(1, setProps.size()); Map<String, Object> mapExpected = new HashMap<String, Object>(); mapExpected.put(PropertyHelper.getPropertyId("Services", "service_name"), "HDFS"); mapExpected.put(PropertyHelper.getPropertyId("Services", "display_name"), "HDFS"); mapExpected.put(PropertyHelper.getPropertyId("ServiceInfo", "cluster_name"), "tbmetrictest"); mapExpected.put(PropertyHelper.getPropertyId("Services", "description"), "Apache Hadoop Distributed File System"); mapExpected.put(PropertyHelper.getPropertyId("ServiceInfo", "state"), "STARTED"); mapExpected.put(PropertyHelper.getPropertyId("OuterCategory", "propName"), "100"); mapExpected.put(PropertyHelper.getPropertyId("OuterCategory/nested1/nested2", "innerPropName"), "innerPropValue"); mapExpected.put(PropertyHelper.getPropertyId(null, "topLevelProp"), "value"); assertEquals(mapExpected, setProps.iterator().next().getProperties()); assertEquals("foo=bar", body.getQueryString()); String b = body.getBody(); body = parser.parse(b).iterator().next(); Set<NamedPropertySet> setProps2 = body.getNamedPropertySets(); assertEquals(mapExpected, setProps2.iterator().next().getProperties()); }
@Override public Set<RequestBody> parse(String body) throws BodyParseException { Set<RequestBody> requestBodySet = new HashSet<RequestBody>(); RequestBody rootBody = new RequestBody(); rootBody.setBody(body); if (body != null && body.length() != 0) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(ensureArrayFormat(body)); Iterator<JsonNode> iterator = root.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); Map<String, Object> mapProperties = new HashMap<String, Object>(); Map<String, String> requestInfoProps = new HashMap<String, String>(); NamedPropertySet propertySet = new NamedPropertySet("", mapProperties); processNode(node, "", propertySet, requestInfoProps); if (!requestInfoProps.isEmpty()) { RequestBody requestBody = new RequestBody(); requestBody.setBody(body); for (Map.Entry<String, String> entry : requestInfoProps.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); requestBody.addRequestInfoProperty(key, value); if (key.equals(QUERY_FIELD_NAME)) { requestBody.setQueryString(value); } } if (!propertySet.getProperties().isEmpty()) { requestBody.addPropertySet(propertySet); } requestBodySet.add(requestBody); } else { if (!propertySet.getProperties().isEmpty()) { rootBody.addPropertySet(propertySet); } requestBodySet.add(rootBody); } } } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Caught exception parsing msg body."); LOG.debug("Message Body: " + body, e); } throw new BodyParseException(e); } } if (requestBodySet.isEmpty()) { requestBodySet.add(rootBody); } return requestBodySet; }
JsonRequestBodyParser implements RequestBodyParser { @Override public Set<RequestBody> parse(String body) throws BodyParseException { Set<RequestBody> requestBodySet = new HashSet<RequestBody>(); RequestBody rootBody = new RequestBody(); rootBody.setBody(body); if (body != null && body.length() != 0) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(ensureArrayFormat(body)); Iterator<JsonNode> iterator = root.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); Map<String, Object> mapProperties = new HashMap<String, Object>(); Map<String, String> requestInfoProps = new HashMap<String, String>(); NamedPropertySet propertySet = new NamedPropertySet("", mapProperties); processNode(node, "", propertySet, requestInfoProps); if (!requestInfoProps.isEmpty()) { RequestBody requestBody = new RequestBody(); requestBody.setBody(body); for (Map.Entry<String, String> entry : requestInfoProps.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); requestBody.addRequestInfoProperty(key, value); if (key.equals(QUERY_FIELD_NAME)) { requestBody.setQueryString(value); } } if (!propertySet.getProperties().isEmpty()) { requestBody.addPropertySet(propertySet); } requestBodySet.add(requestBody); } else { if (!propertySet.getProperties().isEmpty()) { rootBody.addPropertySet(propertySet); } requestBodySet.add(rootBody); } } } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Caught exception parsing msg body."); LOG.debug("Message Body: " + body, e); } throw new BodyParseException(e); } } if (requestBodySet.isEmpty()) { requestBodySet.add(rootBody); } return requestBodySet; } }
JsonRequestBodyParser implements RequestBodyParser { @Override public Set<RequestBody> parse(String body) throws BodyParseException { Set<RequestBody> requestBodySet = new HashSet<RequestBody>(); RequestBody rootBody = new RequestBody(); rootBody.setBody(body); if (body != null && body.length() != 0) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(ensureArrayFormat(body)); Iterator<JsonNode> iterator = root.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); Map<String, Object> mapProperties = new HashMap<String, Object>(); Map<String, String> requestInfoProps = new HashMap<String, String>(); NamedPropertySet propertySet = new NamedPropertySet("", mapProperties); processNode(node, "", propertySet, requestInfoProps); if (!requestInfoProps.isEmpty()) { RequestBody requestBody = new RequestBody(); requestBody.setBody(body); for (Map.Entry<String, String> entry : requestInfoProps.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); requestBody.addRequestInfoProperty(key, value); if (key.equals(QUERY_FIELD_NAME)) { requestBody.setQueryString(value); } } if (!propertySet.getProperties().isEmpty()) { requestBody.addPropertySet(propertySet); } requestBodySet.add(requestBody); } else { if (!propertySet.getProperties().isEmpty()) { rootBody.addPropertySet(propertySet); } requestBodySet.add(rootBody); } } } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Caught exception parsing msg body."); LOG.debug("Message Body: " + body, e); } throw new BodyParseException(e); } } if (requestBodySet.isEmpty()) { requestBodySet.add(rootBody); } return requestBodySet; }  }
JsonRequestBodyParser implements RequestBodyParser { @Override public Set<RequestBody> parse(String body) throws BodyParseException { Set<RequestBody> requestBodySet = new HashSet<RequestBody>(); RequestBody rootBody = new RequestBody(); rootBody.setBody(body); if (body != null && body.length() != 0) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(ensureArrayFormat(body)); Iterator<JsonNode> iterator = root.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); Map<String, Object> mapProperties = new HashMap<String, Object>(); Map<String, String> requestInfoProps = new HashMap<String, String>(); NamedPropertySet propertySet = new NamedPropertySet("", mapProperties); processNode(node, "", propertySet, requestInfoProps); if (!requestInfoProps.isEmpty()) { RequestBody requestBody = new RequestBody(); requestBody.setBody(body); for (Map.Entry<String, String> entry : requestInfoProps.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); requestBody.addRequestInfoProperty(key, value); if (key.equals(QUERY_FIELD_NAME)) { requestBody.setQueryString(value); } } if (!propertySet.getProperties().isEmpty()) { requestBody.addPropertySet(propertySet); } requestBodySet.add(requestBody); } else { if (!propertySet.getProperties().isEmpty()) { rootBody.addPropertySet(propertySet); } requestBodySet.add(rootBody); } } } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Caught exception parsing msg body."); LOG.debug("Message Body: " + body, e); } throw new BodyParseException(e); } } if (requestBodySet.isEmpty()) { requestBodySet.add(rootBody); } return requestBodySet; }  @Override Set<RequestBody> parse(String body); }
JsonRequestBodyParser implements RequestBodyParser { @Override public Set<RequestBody> parse(String body) throws BodyParseException { Set<RequestBody> requestBodySet = new HashSet<RequestBody>(); RequestBody rootBody = new RequestBody(); rootBody.setBody(body); if (body != null && body.length() != 0) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(ensureArrayFormat(body)); Iterator<JsonNode> iterator = root.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); Map<String, Object> mapProperties = new HashMap<String, Object>(); Map<String, String> requestInfoProps = new HashMap<String, String>(); NamedPropertySet propertySet = new NamedPropertySet("", mapProperties); processNode(node, "", propertySet, requestInfoProps); if (!requestInfoProps.isEmpty()) { RequestBody requestBody = new RequestBody(); requestBody.setBody(body); for (Map.Entry<String, String> entry : requestInfoProps.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); requestBody.addRequestInfoProperty(key, value); if (key.equals(QUERY_FIELD_NAME)) { requestBody.setQueryString(value); } } if (!propertySet.getProperties().isEmpty()) { requestBody.addPropertySet(propertySet); } requestBodySet.add(requestBody); } else { if (!propertySet.getProperties().isEmpty()) { rootBody.addPropertySet(propertySet); } requestBodySet.add(rootBody); } } } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Caught exception parsing msg body."); LOG.debug("Message Body: " + body, e); } throw new BodyParseException(e); } } if (requestBodySet.isEmpty()) { requestBodySet.add(rootBody); } return requestBodySet; }  @Override Set<RequestBody> parse(String body);  }