public class ContentHelper extends Object
| Constructor and Description |
|---|
ContentHelper(LoggerFacade logger) |
| Modifier and Type | Method and Description |
|---|---|
Optional<org.json.JSONObject> |
asJson(org.apache.http.HttpEntity entity)
converts the provided HttpEntity to a JSONObject
|
Optional<Map<String,String>> |
asMapOfStringToString(String key,
String value,
Optional<org.json.JSONObject> optionalJsonObject)
extracts the key/value pairs from JSONObject and returns them as a Map{String, String}
|
org.apache.http.entity.StringEntity |
entityFrom(org.json.JSONObject jsonObject)
builds a StringEntity using the string provided by jsonObject.toString()
|
org.apache.http.entity.StringEntity |
entityFrom(org.apache.http.NameValuePair... pairs)
simple wrapper around entityFrom(JSONObject) that uses jsonFrom to build the JSONObject
|
Optional<org.json.JSONArray> |
getArrayFrom(org.json.JSONObject jsonObject,
String key)
returns JSONArray from jsonObject matching key
|
Optional<InputStream> |
getInputStream(org.apache.http.HttpEntity entity)
returns InputStream for the content of entity
|
Optional<String> |
getTextHtmlOrXmlContent(org.apache.http.HttpEntity entity)
returns text/html or text/html content from enttity if found; otherwise Optional.empty()
|
org.json.JSONObject |
jsonFrom(org.apache.http.NameValuePair... pairs)
builds a simple JSON object from name value pairs
|
org.apache.http.NameValuePair |
pairFrom(String key,
String value)
simple wrapper around BasicNameValuePair constructor provided to shorten syntax
|
Optional<org.json.JSONObject> |
responseToJSONObject(org.apache.http.HttpResponse response,
String path)
extracts the response content into a JSONObject
|
public ContentHelper(LoggerFacade logger)
public Optional<org.json.JSONArray> getArrayFrom(org.json.JSONObject jsonObject, String key)
jsonObject - JSONObject containing JSONArray using keykey - key of the JSONArray within jsonObjectpublic org.json.JSONObject jsonFrom(org.apache.http.NameValuePair... pairs)
pairs - name value pairs to add to the new JSON Objectpublic org.apache.http.entity.StringEntity entityFrom(org.json.JSONObject jsonObject)
jsonObject - jsonObject which provides String via toStringpublic org.apache.http.entity.StringEntity entityFrom(org.apache.http.NameValuePair... pairs)
throws UnsupportedEncodingException
pairs - passed to jsonFromUnsupportedEncodingException - thrown from entityFrom(JSONObject)public org.apache.http.NameValuePair pairFrom(String key, String value)
key - key of the new NameValuePairvalue - value of the new NameValuePairpublic Optional<org.json.JSONObject> responseToJSONObject(org.apache.http.HttpResponse response, String path)
response - response to extract JSONObject frompath - the path used for diagnostic purposes, this is the path to the
request which can be logged in the event of failurepublic Optional<org.json.JSONObject> asJson(org.apache.http.HttpEntity entity)
entity - entity to convertpublic Optional<Map<String,String>> asMapOfStringToString(String key, String value, Optional<org.json.JSONObject> optionalJsonObject)
key - key in the json object to serve as key in the mapvalue - value in the json object to serve as value in the mapoptionalJsonObject - Optional{JSONObject} to extract key/value pairs from if presentpublic Optional<String> getTextHtmlOrXmlContent(org.apache.http.HttpEntity entity)
entity - entity containing the String content to returnpublic Optional<InputStream> getInputStream(org.apache.http.HttpEntity entity)
entity - entity to return InputStream of content forCopyright © 2016–2021. All rights reserved.