Class GetUrlContent
- java.lang.Object
-
- org.epics.archiverappliance.utils.ui.GetUrlContent
-
public class GetUrlContent extends Object
Small utility for getting the contents of an URL as various things- Author:
- mshankar
-
-
Field Summary
Fields Modifier and Type Field Description static String
ARCHAPPL_COMPONENT
-
Constructor Summary
Constructors Constructor Description GetUrlContent()
-
Method Summary
Modifier and Type Method Description static boolean
checkURL(String urlStr)
Check if we get a valid response from this URLstatic void
combineJSONArrays(LinkedList<Map<String,String>> dest, org.json.simple.JSONArray additionalDetails)
A static utilty method to combine JSON objectsstatic org.json.simple.JSONArray
combineJSONArrays(List<String> urlStrs)
Combine JSON arrays from multiple URL's in sequence and return a JSON Array.static void
combineJSONArraysAndPrintln(List<String> urlStrs, PrintWriter out)
Combine JSON arrays of JSON objects from multiple URL's in sequence and sends them to the writer..static void
combineJSONObjects(HashMap<String,String> dest, org.json.simple.JSONObject additionalDetails)
A static utilty method to combine JSON objectsstatic void
combineJSONObjectsWithArrays(HashMap<String,Object> dest, org.json.simple.JSONObject additionalDetails)
static String
getURLContent(String urlStr)
Small utility method for getting the content of an URL as a string Returns null in case of an exception.static org.json.simple.JSONArray
getURLContentAsJSONArray(String urlStr)
static org.json.simple.JSONArray
getURLContentAsJSONArray(String urlStr, boolean logErrors)
Given a URL, get the contents as a JSON Arraystatic org.json.simple.JSONObject
getURLContentAsJSONObject(String urlStr)
Given an URL, get the contents as a JSON Objectstatic org.json.simple.JSONObject
getURLContentAsJSONObject(String urlStr, boolean logErrors)
Given an URL, get the contents as a JSON Object; control logging.static InputStream
getURLContentAsStream(String serverURL)
static org.json.simple.JSONArray
postDataAndGetContentAsJSONArray(String url, LinkedList<org.json.simple.JSONObject> array)
Post a JSONArray to a remote server and get the response as a JSON object.static org.json.simple.JSONObject
postDataAndGetContentAsJSONArray(String url, org.json.simple.JSONArray array)
Post a JSONArray to a remote server and get the response as a JSON object.static org.json.simple.JSONObject
postDataAndGetContentAsJSONObject(String url, LinkedList<org.json.simple.JSONObject> array)
Post a JSONArray to a remote server and get the response as a JSON object.static org.json.simple.JSONObject
postObjectAndGetContentAsJSONObject(String url, org.json.simple.JSONObject object)
Post a JSONObject to a remote server and get the response as a JSON object.static <T> T
postStringListAndGetJSON(String url, String paramName, LinkedList<String> params)
Post a list of strings to the remove server as a CSV and return the results as a array of JSONObjectsstatic void
proxyURL(String redirectURIStr, javax.servlet.http.HttpServletResponse resp)
Get the contents of a redirect URL and use as reponse for the provided HttpServletResponse.
-
-
-
Field Detail
-
ARCHAPPL_COMPONENT
public static final String ARCHAPPL_COMPONENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getURLContent
public static String getURLContent(String urlStr)
Small utility method for getting the content of an URL as a string Returns null in case of an exception.- Parameters:
urlStr
- URL- Returns:
- URL content
-
getURLContentAsJSONArray
public static org.json.simple.JSONArray getURLContentAsJSONArray(String urlStr)
-
getURLContentAsJSONArray
public static org.json.simple.JSONArray getURLContentAsJSONArray(String urlStr, boolean logErrors)
Given a URL, get the contents as a JSON Array- Parameters:
urlStr
- URLlogErrors
- If false, do not log any exceptions (they are expected)- Returns:
- URL content as JSONArray
-
getURLContentAsJSONObject
public static org.json.simple.JSONObject getURLContentAsJSONObject(String urlStr)
Given an URL, get the contents as a JSON Object- Parameters:
urlStr
- URL- Returns:
- URL content as a JSON Object
-
getURLContentAsJSONObject
public static org.json.simple.JSONObject getURLContentAsJSONObject(String urlStr, boolean logErrors)
Given an URL, get the contents as a JSON Object; control logging.- Parameters:
urlStr
- URLlogErrors
- If false, do not log any exceptions (they are expected)- Returns:
- URL content as a JSON Object
-
combineJSONArrays
public static org.json.simple.JSONArray combineJSONArrays(List<String> urlStrs)
Combine JSON arrays from multiple URL's in sequence and return a JSON Array. We need the supress warnings here as JSONArray is a raw collection.- Parameters:
urlStrs
- multiple URLs- Returns:
- Combined JSON arrays
-
combineJSONArraysAndPrintln
public static void combineJSONArraysAndPrintln(List<String> urlStrs, PrintWriter out)
Combine JSON arrays of JSON objects from multiple URL's in sequence and sends them to the writer.. The difference from combineJSONArrays is that inserts a newline after each element.- Parameters:
urlStrs
- multiple URLsout
- PrintWriter
-
combineJSONObjects
public static void combineJSONObjects(HashMap<String,String> dest, org.json.simple.JSONObject additionalDetails)
A static utilty method to combine JSON objects- Parameters:
dest
- Details from additionalDetails are added to this.additionalDetails
- JSONObject
-
combineJSONArrays
public static void combineJSONArrays(LinkedList<Map<String,String>> dest, org.json.simple.JSONArray additionalDetails)
A static utilty method to combine JSON objects- Parameters:
dest
- Details from additionalDetails are added to this.additionalDetails
- JSONArray
-
combineJSONObjectsWithArrays
public static void combineJSONObjectsWithArrays(HashMap<String,Object> dest, org.json.simple.JSONObject additionalDetails)
-
postDataAndGetContentAsJSONObject
public static org.json.simple.JSONObject postDataAndGetContentAsJSONObject(String url, LinkedList<org.json.simple.JSONObject> array) throws IOException
Post a JSONArray to a remote server and get the response as a JSON object.- Parameters:
url
- URLarray
- JSONObject Array- Returns:
- JSONObject
- Throws:
IOException
-
-
postDataAndGetContentAsJSONArray
public static org.json.simple.JSONArray postDataAndGetContentAsJSONArray(String url, LinkedList<org.json.simple.JSONObject> array) throws IOException
Post a JSONArray to a remote server and get the response as a JSON object.- Parameters:
url
- URLarray
- JSONObject Array- Returns:
- JSONArray
- Throws:
IOException
-
-
postDataAndGetContentAsJSONArray
public static org.json.simple.JSONObject postDataAndGetContentAsJSONArray(String url, org.json.simple.JSONArray array) throws IOException
Post a JSONArray to a remote server and get the response as a JSON object.- Parameters:
url
- URLarray
- JSONArray Array- Returns:
- JSONArray
- Throws:
IOException
-
-
postObjectAndGetContentAsJSONObject
public static org.json.simple.JSONObject postObjectAndGetContentAsJSONObject(String url, org.json.simple.JSONObject object) throws IOException
Post a JSONObject to a remote server and get the response as a JSON object.- Parameters:
url
- URLobject
- A JSONObject- Returns:
- JSONObject
- Throws:
IOException
-
-
postStringListAndGetJSON
public static <T> T postStringListAndGetJSON(String url, String paramName, LinkedList<String> params) throws IOException
Post a list of strings to the remove server as a CSV and return the results as a array of JSONObjects- Parameters:
url
- URLparamName
-params
- a list of strings- Returns:
- JSONArray
- Throws:
IOException
-
-
checkURL
public static boolean checkURL(String urlStr)
Check if we get a valid response from this URL- Parameters:
urlStr
- URL- Returns:
- boolean True or False
-
getURLContentAsStream
public static InputStream getURLContentAsStream(String serverURL) throws IOException
- Throws:
IOException
-
proxyURL
public static void proxyURL(String redirectURIStr, javax.servlet.http.HttpServletResponse resp) throws IOException
Get the contents of a redirect URL and use as reponse for the provided HttpServletResponse. If possible, pass in error responses as well.- Parameters:
redirectURIStr
-resp
- HttpServletResponse- Throws:
IOException
-
-
-