Overview | Package | Class | Tree | Deprecated | Index | Help
| OracleAS PDK for Java 9.0.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.webdb.utils
Class HTTPUtils

    java.lang.Object
      |
      +--oracle.webdb.utils.HTTPUtils

public class HTTPUtils
extends java.lang.Object

This class contains various utility methods for encoding and decoding URIs `String` using the set of characters allowed in a URI, as defined in RFC 2396 - "Uniform Resource Identifiers (URI): Generic Syntax". The method does not suffer from the limitations of the `java.net.URLEncoder` in that it provides control over the character encoding used for character to byte conversions and is capable of encoding characters that are encoded by a sequence of several bytes.

To convert a `String`, each character is examined in turn:

- The ASCII characters '`a`' through '`z`', '`A`' through '`Z`', and '`0`' through '`9`' remain the same.
- Additional 'mark characters', i.e. '`-`', '`_`', '`.`', '`!`', '`~`', '`*`', '`'`' , '`(`', '`)`', remain the same.
- The space character '`` ' is converted into a plus sign '`+`'.
- All other characters are converted into a sequence of bytes using the specified character encoding, and each of these bytes is then encoded as a string "`%xy`", where xy is the two-digit hexadecimal representation of the byte value.

Constructor Summary
`HTTPUtils()`

Method Summary
`static java.lang.String` | `buildUrlAsString(java.lang.String scheme, java.lang.String host, int port, java.lang.String path)` Build a fully qualified URL from the pieces provided.
`static java.lang.String` | `decode(java.lang.String value, java.lang.String encoding)` Decodes an encoded String.
`static java.lang.String` | `decodeUTF(java.lang.String value)` Decodes an encoded UTF8 String.
`static java.lang.String` | `encode(java.lang.String value, java.lang.String encoding)` Encodes a String using the set of characters allowed in a URI.
`static java.lang.String` | `encodeUTF(java.lang.String value)` Encodes a String using the set of characters allowed in a URI.
`static java.lang.String` | `getCookie(java.lang.String cookieName, java.lang.String cookies)` Extracts a cookie value from a list of cookies based on the name.
`static boolean` | `isErrorStatusCode(int statusCode)` Determines whether the given HTTP status code denotes a client or server error.
`static boolean` | `needsDecoding(java.lang.String token)` Determine if a value needs to be decoded using HTTPUtils.decode() This method assumes that a value is encoded.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HTTPUtils

    public HTTPUtils()

Method Detail

### buildUrlAsString

    public static java.lang.String buildUrlAsString(java.lang.String scheme,
                                                    java.lang.String host,
                                                    int port,
                                                    java.lang.String path)

  Build a fully qualified URL from the pieces provided. This method does not call any encoding methods, so the path argument has to be properly encoded.

  Parameters:
    `scheme` - server protocol.
    `host` - server name.
    `port` - server port.
    `path` - properly encoded relative URL.
  Throws:
    `java.lang.IllegalArgumentException` - if scheme, host or port is null.

### encode

    public static java.lang.String encode(java.lang.String value,
                                          java.lang.String encoding)
                                   throws java.io.UnsupportedEncodingException

  Encodes a String using the set of characters allowed in a URI.

  Parameters:
    `value` - `String` to be translated.
    `encoding` - the Java alias for the character encoding to be used to convert non-ASCII characters into bytes (e.g. `"UTF8"`).
  Returns:
    the translated `String`.
  Throws:
    `java.io.UnsupportedEncodingException` - if the given encoding is not a recognised character encoding.

### encodeUTF

    public static java.lang.String encodeUTF(java.lang.String value)

  Encodes a String using the set of characters allowed in a URI. This method encodes a multibyte string in UTF8

  Parameters:
    `value` - `String` to be translated.
  Returns:
    the translated `String`.

### decode

    public static java.lang.String decode(java.lang.String value,
                                          java.lang.String encoding)
                                   throws java.io.UnsupportedEncodingException

  Decodes an encoded String.

  Parameters:
    `value` - `String` to be translated.
    `encoding` - the Java alias for the character encoding to be used to convert byte sequences into characters(e.g. `"UTF8"`).
  Returns:
    the translated `String`.
  Throws:
    `java.io.UnsupportedEncodingException` - if the given encoding is not a recognised character encoding.

### decodeUTF

    public static java.lang.String decodeUTF(java.lang.String value)

  Decodes an encoded UTF8 String.

  Parameters:
    `value` - `String` to be translated.
  Returns:
    the translated `String`.

### isErrorStatusCode

    public static boolean isErrorStatusCode(int statusCode)

  Determines whether the given HTTP status code denotes a client or server error. According to the HTTP 1.1 spec, the codes have the following categories:
  - 1xx - Informational (new in HTTP/1.1)
  - 2xx - Success
  - 3xx - Redirection
  - 4xx - Client Error
  - 5xx - Server Error

  Parameters:
    `statusCode` - an HTTP response status code
  Returns:
    true if the given status code denotes a client or server error

### needsDecoding

    public static final boolean needsDecoding(java.lang.String token)

  Determine if a value needs to be decoded using HTTPUtils.decode() This method assumes that a value is encoded. As such, the existence of '%' (leading character of an encoded sequence) or '+' (sometimes used to replace characters indicates that decoding IS required.

### getCookie

    public static java.lang.String getCookie(java.lang.String cookieName,
                                             java.lang.String cookies)

  Extracts a cookie value from a list of cookies based on the name.

  Parameters:
    `cookieName` - Name of the cookie to search for.
    `cookies` - List of cookies of the form "name1=value1; name2=value2; ...; nameN=valueN".
  Returns:
    The cookie value stored as a String object. null if cookie not found.

Overview | Package | Class | Tree | Deprecated | Index | Help
| OracleAS PDK for Java 9.0.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2002,2003 Oracle Corporation. All Rights Reserved.