Class ManUrlExt
- java.lang.Object
-
- manifold.json.rt.extensions.java.net.URL.ManUrlExt
-
public class ManUrlExt extends Object
Adds extension methods to URL for handling JSON, plain text, and binary content.
-
-
Constructor Summary
Constructors Constructor Description ManUrlExt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringencode(String urlPart)Convenience method to encode a URL string and not have to handle the UnsupportedEncodingException.static byte[]getBinaryContent(URL thiz)static ObjectgetCsvContent(URL thiz)static ObjectgetJsonContent(URL thiz)static StringgetTextContent(URL thiz)static ObjectgetXmlContent(URL thiz)static ObjectgetYamlContent(URL thiz)static URLmakeUrl(String url, Object jsonValue)Make a JSON-compatible URL with the arguments from thejsonValue.static ObjectsendCsvRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a CSV response.static ObjectsendCsvRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static ObjectsendJsonRequest(URL url, String httpMethod, Object jsonValue)Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a JSON response.static ObjectsendJsonRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static ObjectsendJsonRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static StringsendPlainTextRequest(URL url, String httpMethod, Object jsonValue)Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a plain text response.static StringsendPlainTextRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static StringsendPlainTextRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static ObjectsendXmlRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a XML response.static ObjectsendXmlRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static ObjectsendYamlRequest(URL url, String httpMethod, Object jsonValue)Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a YAML response.static ObjectsendYamlRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)static ObjectsendYamlRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
-
-
Method Detail
-
makeUrl
public static URL makeUrl(String url, Object jsonValue)
Make a JSON-compatible URL with the arguments from thejsonValue. Encodes the arguments in UTF-8 and appends them to the list using standard URL query delimiters. If an individual argument is aBindingsor aList, it is transformed to JSON. Otherwise, the argument is coerced to a String and URL encoded.
-
encode
public static String encode(String urlPart)
Convenience method to encode a URL string and not have to handle the UnsupportedEncodingException.
-
sendJsonRequest
public static Object sendJsonRequest(URL url, String httpMethod, Object jsonValue)
Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a JSON response.- Parameters:
httpMethod- The HTTP method to use: "GET", "POST", "PUT", or "PATCH"jsonValue- A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)- Returns:
- A JSON value parsed from the JSON response.
- See Also:
sendRequest(URL, String, Object, Map, int)
-
sendJsonRequest
public static Object sendJsonRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendJsonRequest
public static Object sendJsonRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendYamlRequest
public static Object sendYamlRequest(URL url, String httpMethod, Object jsonValue)
Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a YAML response.- Parameters:
httpMethod- The HTTP method to use: "GET", "POST", "PUT", or "PATCH"jsonValue- A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)- Returns:
- A JSON value parsed from the YAML response.
- See Also:
sendRequest(URL, String, Object, Map, int)
-
sendYamlRequest
public static Object sendYamlRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendYamlRequest
public static Object sendYamlRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendXmlRequest
public static Object sendXmlRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a XML response.- Parameters:
httpMethod- The HTTP method to use: "GET", "POST", "PUT", or "PATCH"jsonValue- A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)- Returns:
- A JSON bindings value parsed from the XML response.
- See Also:
sendRequest(URL, String, Object, Map, int)
-
sendXmlRequest
public static Object sendXmlRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendCsvRequest
public static Object sendCsvRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a CSV response.- Parameters:
httpMethod- The HTTP method to use: "GET", "POST", "PUT", or "PATCH"jsonValue- A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)- Returns:
- A JSON bindings value parsed from the CSV response.
- See Also:
sendRequest(URL, String, Object, Map, int)
-
sendCsvRequest
public static Object sendCsvRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendPlainTextRequest
public static String sendPlainTextRequest(URL url, String httpMethod, Object jsonValue)
Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a plain text response.- Parameters:
httpMethod- The HTTP method to use: "GET", "POST", "PUT", or "PATCH"jsonValue- A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)- Returns:
- The raw response body as plain text
- See Also:
sendRequest(URL, String, Object, Map, int)
-
sendPlainTextRequest
public static String sendPlainTextRequest(URL url, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
sendPlainTextRequest
public static String sendPlainTextRequest(URL url, Proxy proxy, String httpMethod, Object jsonValue, Map<String,String> headers, int timeout)
-
getTextContent
public static String getTextContent(URL thiz)
- Returns:
- The full text content of this URL's stream.
-
getBinaryContent
public static byte[] getBinaryContent(URL thiz)
- Returns:
- The full binary content of this URL's stream.
-
getJsonContent
public static Object getJsonContent(URL thiz)
- Returns:
- A JSON object reflecting the contents of this URL, otherwise a
RuntimeExceptionresults if the content is not a JSON document.
-
getYamlContent
public static Object getYamlContent(URL thiz)
- Returns:
- A YAML object reflecting the contents of this URL, otherwise a
RuntimeExceptionresults if the content is not a YAML document.
-
getXmlContent
public static Object getXmlContent(URL thiz)
- Returns:
- An XML object reflecting the contents of this URL, otherwise a
RuntimeExceptionresults if the content is not a XML document.
-
getCsvContent
public static Object getCsvContent(URL thiz)
- Returns:
- An CSV object reflecting the contents of this URL, otherwise a
RuntimeExceptionresults if the content is not a CSV document.
-
-