Search in sources :

Example 1 with ServerException

use of org.apache.hadoop.lib.server.ServerException in project hadoop by apache.

the class ServerWebApp method resolveAuthority.

/**
   * Resolves the host and port InetSocketAddress the
   * web server is listening to.
   * <p>
   * This implementation looks for the following 2 properties:
   * <ul>
   *   <li>#SERVER_NAME#.http.hostname</li>
   *   <li>#SERVER_NAME#.http.port</li>
   * </ul>
   *
   * @return the host and port InetSocketAddress the
   *         web server is listening to.
   * @throws ServerException thrown
   *         if any of the above 2 properties is not defined.
   */
protected InetSocketAddress resolveAuthority() throws ServerException {
    String hostnameKey = getName() + HTTP_HOSTNAME;
    String portKey = getName() + HTTP_PORT;
    String host = System.getProperty(hostnameKey);
    String port = System.getProperty(portKey);
    if (host == null) {
        throw new ServerException(ServerException.ERROR.S13, hostnameKey);
    }
    if (port == null) {
        throw new ServerException(ServerException.ERROR.S13, portKey);
    }
    try {
        InetAddress add = InetAddress.getByName(host);
        int portNum = Integer.parseInt(port);
        return new InetSocketAddress(add, portNum);
    } catch (UnknownHostException ex) {
        throw new ServerException(ServerException.ERROR.S14, ex.toString(), ex);
    }
}
Also used : ServerException(org.apache.hadoop.lib.server.ServerException) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ServerException (org.apache.hadoop.lib.server.ServerException)1