Java Code Examples for java.net.UnknownHostException#toString()

The following examples show how to use java.net.UnknownHostException#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerWebApp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 2
Source File: ServerWebApp.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 3
Source File: BindingRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    String name = context.getCurrentAddressValue();
    ServiceName svcName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    if (controller != null) {
        // We didn't remove it, we just set reloadRequired
        context.revertReloadRequired();
    } else {
        try {
            BindingAddHandler.installBindingService(context, model, name);
        }catch (UnknownHostException e) {
            throw new OperationFailedException(e.toString());
        }
    }
}
 
Example 4
Source File: NetworkUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Get InetAddress masked with prefixLength.  Will never return null.
 * @param address the IP address to mask with
 * @param prefixLength the prefixLength used to mask the IP
 */
public static InetAddress getNetworkPart(InetAddress address, int prefixLength) {
    byte[] array = address.getAddress();
    maskRawAddress(array, prefixLength);

    InetAddress netPart = null;
    try {
        netPart = InetAddress.getByAddress(array);
    } catch (UnknownHostException e) {
        throw new RuntimeException("getNetworkPart error - " + e.toString());
    }
    return netPart;
}
 
Example 5
Source File: HostConfigurableSocketFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setHost(String host)
{
    try
    {
        InetAddress hostAddress = InetAddress.getByName(host);
        if (!hostAddress.isAnyLocalAddress())
        {
            this.host = hostAddress;
        }
    }
    catch (UnknownHostException e)
    {
        throw new RuntimeException(e.toString());
    }
}
 
Example 6
Source File: NTLMAuthenticator.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public void configure(String name, Properties props, NameSpace nameSpace)
		throws LDAPException {
	this.name = name;
	this.host = props.getProperty("host");
	try {
		addr = UniAddress.getByName(host);
	} catch (UnknownHostException e) {
		throw new LDAPException("Could not lookup host : " + e.toString(),
				LDAPException.OPERATIONS_ERROR, "");
	}
	
	base = nameSpace.getBase().getDN().toString();
}
 
Example 7
Source File: NTLMAuthenticator.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public void configure(String name, Properties props, NameSpace nameSpace)
		throws LDAPException {
	this.name = name;
	this.host = props.getProperty("host");
	try {
		addr = UniAddress.getByName(host);
	} catch (UnknownHostException e) {
		throw new LDAPException("Could not lookup host : " + e.toString(),
				LDAPException.OPERATIONS_ERROR, "");
	}
	
	base = nameSpace.getBase().getDN().toString();
}
 
Example 8
Source File: AbstractBindingWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void handleBindingReinstall(OperationContext context, String bindingName, ModelNode bindingModel, ServiceName serviceName) throws OperationFailedException {
    context.removeService(serviceName);
    try {
        BindingAddHandler.installBindingService(context, bindingModel, bindingName);
    } catch (UnknownHostException e) {
        throw new OperationFailedException(e.toString());
    }
}
 
Example 9
Source File: BindingAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    String name = address.getLastElement().getValue();

    try {
        installBindingService(context, model, name);
    } catch (UnknownHostException e) {
        throw new OperationFailedException(e.toString());
    }

}
 
Example 10
Source File: MongoDBUtils.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 * Connect to MongoDB Host.
 *
 * @throws DBException
 */
public void connect() throws DBException {
    try {
        LOGGER.debug("Initializing MongoDB client");
        mongoClient = new MongoClient(this.host, this.port);
    } catch (UnknownHostException e) {
        throw new DBException(e.toString());

    }
}
 
Example 11
Source File: SuccessWhaleExceptionTest.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@Test
public void itMakesFriendlyErrorForHostNotFound () throws Exception {
	final UnknownHostException uhe = new UnknownHostException("Unable to resolve host \"successwhale-api.herokuapp.com\": No address associated with hostname");
	final SuccessWhaleException swe = new SuccessWhaleException("Failed to fetch feed 'somefeed' from 'someurl': " + uhe.toString(), uhe);
	assertEquals("Network error: Unable to resolve host \"successwhale-api.herokuapp.com\": No address associated with hostname",
			swe.friendlyMessage());
}