Package org.glassfish.common.util
Class HttpParser
java.lang.Object
org.glassfish.common.util.HttpParser
HTTP helper class for parsing HTTP headers, content types, reading responses.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CharsetgetCharset(String charset) Parses the parameter.static CharsetgetCharsetFromHeader(String header) Parse the character encoding from the specified content type, authorization header or any header using same rules when they contain ie.static UserNameAndPasswordparseBasicAuthorizationHeader(String authorization) static StringreadResponseErrorStream(HttpURLConnection connection) Reads response error input stream from the connection to a String value.static StringreadResponseInputStream(URLConnection connection) Reads response input stream from the connection to a String value.
-
Method Details
-
readResponseErrorStream
Reads response error input stream from the connection to a String value. Respects charset from content type header, if not set, usesUTF-8.- Parameters:
connection-- Returns:
- String parsed from
HttpURLConnection.getErrorStream() - Throws:
IOException
-
readResponseInputStream
Reads response input stream from the connection to a String value. Respects charset from content type header, if not set, usesUTF-8.- Parameters:
connection-- Returns:
- String parsed from
URLConnection.getInputStream() - Throws:
IOException
-
parseBasicAuthorizationHeader
public static UserNameAndPassword parseBasicAuthorizationHeader(String authorization) throws CharacterCodingException - Parameters:
authorization- Value of the Authorization HTTP header.- Returns:
UserNameAndPasswordif the header starts with Basic and can be parsed to username and password. Null otherwise.- Throws:
CharacterCodingException
-
getCharsetFromHeader
Parse the character encoding from the specified content type, authorization header or any header using same rules when they contain ie.header="value"; charset=utf-8. If the header is null, or there is no explicit character encoding,UTF-8is returned.- Parameters:
header- a content type header- Returns:
Charsetor UTF-8 if the charset is null, empty string or unknown.- Throws:
CharacterCodingException- if the charset is not supported.
-
getCharset
Parses the parameter. If it is null or empty string, returnsStandardCharsets.UTF_8.- Parameters:
charset-- Returns:
- specified
Charsetor UTF-8 if the charset is null, empty string or unknown. - Throws:
CharacterCodingException- if the charset is not supported.
-