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

The following examples show how to use java.net.UnknownHostException#getLocalizedMessage() . 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: Tivo.java    From archivo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new Tivo object from a JSON String.
 *
 * @param json String containing the Tivo object in JSON
 * @param mak  Media access key to use for the resulting Tivo
 * @return A new Tivo object
 * @throws IllegalArgumentException on invalid address
 */
public static Tivo fromJSON(final String json, final String mak) throws IllegalArgumentException {
    JSONObject jo = new JSONObject(json);
    String name = jo.getString(JSON_NAME);
    String tsn = jo.getString(JSON_TSN);
    int port = jo.getInt(JSON_PORT);
    JSONArray jsonAddresses = jo.getJSONArray(JSON_ADDRESSES);
    Set<InetAddress> addresses = new HashSet<>();
    Base64.Decoder decoder = Base64.getDecoder();
    for (int i = 0; i < jsonAddresses.length(); i++) {
        try {
            addresses.add(InetAddress.getByAddress(decoder.decode(jsonAddresses.getString(i))));
        } catch (UnknownHostException e) {
            throw new IllegalArgumentException("TiVo address in invalid: " + e.getLocalizedMessage());
        }
    }

    return new Builder().name(name).tsn(tsn).port(port).addresses(addresses).mak(mak).build();
}
 
Example 2
Source File: PersistenceModule.java    From EDDI with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public MongoDatabase provideMongoDB(@Named("mongodb.hosts") String hosts,
                                    @Named("mongodb.port") Integer port,
                                    @Named("mongodb.database") String database,
                                    @Named("mongodb.source") String source,
                                    @Named("mongodb.username") String username,
                                    @Named("mongodb.password") String password,
                                    @Named("mongodb.connectionsPerHost") Integer connectionsPerHost,
                                    @Named("mongodb.connectTimeout") Integer connectTimeout,
                                    @Named("mongodb.heartbeatConnectTimeout") Integer heartbeatConnectTimeout,
                                    @Named("mongodb.heartbeatFrequency") Integer heartbeatFrequency,
                                    @Named("mongodb.heartbeatSocketTimeout") Integer heartbeatSocketTimeout,
                                    @Named("mongodb.localThreshold") Integer localThreshold,
                                    @Named("mongodb.maxConnectionIdleTime") Integer maxConnectionIdleTime,
                                    @Named("mongodb.maxConnectionLifeTime") Integer maxConnectionLifeTime,
                                    @Named("mongodb.maxWaitTime") Integer maxWaitTime,
                                    @Named("mongodb.minConnectionsPerHost") Integer minConnectionsPerHost,
                                    @Named("mongodb.minHeartbeatFrequency") Integer minHeartbeatFrequency,
                                    @Named("mongodb.requiredReplicaSetName") String requiredReplicaSetName,
                                    @Named("mongodb.serverSelectionTimeout") Integer serverSelectionTimeout,
                                    @Named("mongodb.socketTimeout") Integer socketTimeout,
                                    @Named("mongodb.sslEnabled") Boolean sslEnabled,
                                    @Named("mongodb.threadsAllowedToBlockForConnectionMultiplier") Integer threadsAllowedToBlockForConnectionMultiplier,
                                    BsonFactory bsonFactory) {
    try {

        List<ServerAddress> seeds = hostsToServerAddress(hosts, port);

        MongoClient mongoClient;
        MongoClientOptions mongoClientOptions = buildMongoClientOptions(
                ReadPreference.nearest(), connectionsPerHost, connectTimeout,
                heartbeatConnectTimeout, heartbeatFrequency, heartbeatSocketTimeout,
                localThreshold, maxConnectionIdleTime, maxConnectionLifeTime, maxWaitTime,
                minConnectionsPerHost, minHeartbeatFrequency, requiredReplicaSetName,
                serverSelectionTimeout, socketTimeout, sslEnabled,
                threadsAllowedToBlockForConnectionMultiplier, bsonFactory);
        if ("".equals(username) || "".equals(password)) {
            mongoClient = new MongoClient(seeds, mongoClientOptions);
        } else {
            MongoCredential credential = MongoCredential.createCredential(username, source, password.toCharArray());
            mongoClient = new MongoClient(seeds, credential, mongoClientOptions);
        }

        registerMongoClientShutdownHook(mongoClient);

        return mongoClient.getDatabase(database);
    } catch (UnknownHostException e) {
        throw new RuntimeException(e.getLocalizedMessage(), e);
    }
}
 
Example 3
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(String host, int port, Properties props, UsageOptions opts, boolean secure)
                        throws ConfigException, ConnectionException {
        super.init(host, port, props, opts, secure);
        try {
    			this.cmdMapArgs = new HashMap<String, Object>();
    			this.cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, "");
                this.relaxCmdNameValidationChecks = RpcPropertyDefs.getPropertyAsBoolean(props,
                                                        RpcPropertyDefs.RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
                this.applicationName = RpcPropertyDefs.getProperty(props,
                        								RpcPropertyDefs.RPC_APPLICATION_NAME_NICK, null);
                if (this.getUsageOptions().getHostName() != null) {
                        // This had better reflect reality...
                        this.localHostName = this.getUsageOptions().getHostName();
                } else {
                        this.localHostName = java.net.InetAddress.getLocalHost().getHostName();
                }
                if (this.localHostName == null) {
                        throw new NullPointerError("Null client host name in RPC connection init");
                }
                if (!this.useAuthMemoryStore) {
                  // Search properties for ticket file path, fix for job035376
                  this.ticketsFilePath = this.props.getProperty(PropertyDefs.TICKET_PATH_KEY_SHORT_FORM,
                                                       this.props.getProperty(PropertyDefs.TICKET_PATH_KEY));
                  // Search environment variable
                  if (this.ticketsFilePath == null) {
                  		this.ticketsFilePath = PerforceEnvironment.getP4Tickets();
                  }
                  // Search standard OS location
                  if (this.ticketsFilePath == null) {
                  		this.ticketsFilePath = getDefaultP4TicketsFile();
                  }
                  
                  // Search properties for trust file path
                  this.trustFilePath = this.props.getProperty(PropertyDefs.TRUST_PATH_KEY_SHORT_FORM,
                                                     this.props.getProperty(PropertyDefs.TRUST_PATH_KEY));
                  // Search environment variable
                  if (this.trustFilePath == null) {
                          this.trustFilePath = PerforceEnvironment.getP4Trust();

                  }
                  // Search standard OS location
                  if (this.trustFilePath == null) {
                          this.trustFilePath = getDefaultP4TrustFile();
                  }
                }
                this.serverStats = new ServerStats();
                // Auth file lock handling properties
                this.authFileLockTry = PropertiesHelper.getPropertyAsInt(props,
                		new String[] {PropertyDefs.AUTH_FILE_LOCK_TRY_KEY_SHORT_FORM,
                				PropertyDefs.AUTH_FILE_LOCK_TRY_KEY},
                		AbstractAuthHelper.DEFAULT_LOCK_TRY);
                this.authFileLockDelay = PropertiesHelper.getPropertyAsLong(props,
                		new String[] {PropertyDefs.AUTH_FILE_LOCK_DELAY_KEY_SHORT_FORM,
                				PropertyDefs.AUTH_FILE_LOCK_DELAY_KEY},
                		AbstractAuthHelper.DEFAULT_LOCK_DELAY);
                this.authFileLockWait = PropertiesHelper.getPropertyAsLong(props,
                		new String[] {PropertyDefs.AUTH_FILE_LOCK_WAIT_KEY_SHORT_FORM,
                				PropertyDefs.AUTH_FILE_LOCK_WAIT_KEY},
                		AbstractAuthHelper.DEFAULT_LOCK_WAIT);
        } catch (UnknownHostException uhe) {
                throw new ConfigException("Unable to determine client host name: "
                                + uhe.getLocalizedMessage());
        }

        // Initialize client trust
        clientTrust = new ClientTrust(this);
        
        return status;
}
 
Example 4
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(final String host, final int port, final Properties properties,
                         final UsageOptions opts, final boolean secure)
        throws ConfigException, ConnectionException {

    super.init(host, port, properties, opts, secure);
    try {
        cmdMapArgs = new HashMap<>();
        cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, EMPTY);
        relaxCmdNameValidationChecks = getPropertyAsBoolean(properties,
                RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
        applicationName = RpcPropertyDefs.getProperty(properties, RPC_APPLICATION_NAME_NICK);
        if (isNotBlank(getUsageOptions().getHostName())) {
            localHostName = getUsageOptions().getHostName();
        } else {
            localHostName = InetAddress.getLocalHost().getHostName();
        }

        Validate.notBlank(localHostName,
                "Null or empty client host name in RPC connection init");

        if (!useAuthMemoryStore) {
            // Search properties for ticket file path, fix for job035376
            ticketsFilePath = getPropertyByKeys(props, TICKET_PATH_KEY_SHORT_FORM,
                    TICKET_PATH_KEY);
            // Search environment variable
            if (isBlank(ticketsFilePath)) {
                ticketsFilePath = PerforceEnvironment.getP4Tickets();
            }
            // Search standard OS location
            if (isBlank(ticketsFilePath)) {
                ticketsFilePath = getDefaultP4TicketsFile();
            }

            // Search properties for trust file path
            trustFilePath = getPropertyByKeys(props, TRUST_PATH_KEY_SHORT_FORM, TRUST_PATH_KEY);
            // Search environment variable
            if (isBlank(trustFilePath)) {
                trustFilePath = PerforceEnvironment.getP4Trust();
            }
            // Search standard OS location
            if (isBlank(trustFilePath)) {
                trustFilePath = getDefaultP4TrustFile();
            }
        }
        serverStats = new ServerStats();
        // Auth file lock handling properties
        authFileLockTry = getPropertyAsInt(properties,
                new String[]{AUTH_FILE_LOCK_TRY_KEY_SHORT_FORM, AUTH_FILE_LOCK_TRY_KEY},
                AbstractAuthHelper.DEFAULT_LOCK_TRY);

        authFileLockDelay = getPropertyAsLong(properties,
                new String[]{AUTH_FILE_LOCK_DELAY_KEY_SHORT_FORM, AUTH_FILE_LOCK_DELAY_KEY},
                AbstractAuthHelper.DEFAULT_LOCK_DELAY);

        authFileLockWait = getPropertyAsLong(properties,
                new String[]{AUTH_FILE_LOCK_WAIT_KEY_SHORT_FORM, AUTH_FILE_LOCK_WAIT_KEY},
                AbstractAuthHelper.DEFAULT_LOCK_WAIT);
    } catch (UnknownHostException uhe) {
        throw new ConfigException(
                "Unable to determine client host name: %s" + uhe.getLocalizedMessage());
    }

    // Initialize client trust
    clientTrust = new ClientTrust(this);
    return status;
}
 
Example 5
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(final String host, final int port, final Properties properties,
                         final UsageOptions opts, final boolean secure)
		throws ConfigException, ConnectionException {

	super.init(host, port, properties, opts, secure);
	try {
		cmdMapArgs = new HashMap<>();
		cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, EMPTY);
		relaxCmdNameValidationChecks = getPropertyAsBoolean(properties,
				RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
		applicationName = RpcPropertyDefs.getProperty(properties, RPC_APPLICATION_NAME_NICK);
		if (isNotBlank(getUsageOptions().getHostName())) {
			localHostName = getUsageOptions().getHostName();
		} else {
			localHostName = InetAddress.getLocalHost().getHostName();
		}

		Validate.notBlank(localHostName,
				"Null or empty client host name in RPC connection init");

		if (!useAuthMemoryStore) {
			// Search properties for ticket file path, fix for job035376
			ticketsFilePath = getPropertyByKeys(props, TICKET_PATH_KEY_SHORT_FORM,
					TICKET_PATH_KEY);
			// Search environment variable
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = PerforceEnvironment.getP4Tickets();
			}
			// Search standard OS location
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = getDefaultP4TicketsFile();
			}

			// Search properties for trust file path
			trustFilePath = getPropertyByKeys(props, TRUST_PATH_KEY_SHORT_FORM, TRUST_PATH_KEY);
			// Search environment variable
			if (isBlank(trustFilePath)) {
				trustFilePath = PerforceEnvironment.getP4Trust();
			}
			// Search standard OS location
			if (isBlank(trustFilePath)) {
				trustFilePath = getDefaultP4TrustFile();
			}
		}
		serverStats = new ServerStats();
		// Auth file lock handling properties
		authFileLockTry = getPropertyAsInt(properties,
				new String[]{AUTH_FILE_LOCK_TRY_KEY_SHORT_FORM, AUTH_FILE_LOCK_TRY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_TRY);

		authFileLockDelay = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_DELAY_KEY_SHORT_FORM, AUTH_FILE_LOCK_DELAY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_DELAY);

		authFileLockWait = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_WAIT_KEY_SHORT_FORM, AUTH_FILE_LOCK_WAIT_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_WAIT);
	} catch (UnknownHostException uhe) {
		throw new ConfigException(
				"Unable to determine client host name: %s" + uhe.getLocalizedMessage());
	}

	// Initialize client trust
	clientTrust = new ClientTrust(this);
	return status;
}
 
Example 6
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(final String host, final int port, final Properties properties,
                         final UsageOptions opts, final boolean secure)
		throws ConfigException, ConnectionException {

	super.init(host, port, properties, opts, secure);
	try {
		cmdMapArgs = new HashMap<>();
		cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, EMPTY);
		relaxCmdNameValidationChecks = getPropertyAsBoolean(properties,
				RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
		applicationName = RpcPropertyDefs.getProperty(properties, RPC_APPLICATION_NAME_NICK);
		if (isNotBlank(getUsageOptions().getHostName())) {
			localHostName = getUsageOptions().getHostName();
		} else {
			localHostName = InetAddress.getLocalHost().getHostName();
		}

		Validate.notBlank(localHostName,
				"Null or empty client host name in RPC connection init");

		if (!useAuthMemoryStore) {
			// Search properties for ticket file path, fix for job035376
			ticketsFilePath = getPropertyByKeys(props, TICKET_PATH_KEY_SHORT_FORM,
					TICKET_PATH_KEY);
			// Search environment variable
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = PerforceEnvironment.getP4Tickets();
			}
			// Search standard OS location
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = getDefaultP4TicketsFile();
			}

			// Search properties for trust file path
			trustFilePath = getPropertyByKeys(props, TRUST_PATH_KEY_SHORT_FORM, TRUST_PATH_KEY);
			// Search environment variable
			if (isBlank(trustFilePath)) {
				trustFilePath = PerforceEnvironment.getP4Trust();
			}
			// Search standard OS location
			if (isBlank(trustFilePath)) {
				trustFilePath = getDefaultP4TrustFile();
			}
		}
		serverStats = new ServerStats();
		// Auth file lock handling properties
		authFileLockTry = getPropertyAsInt(properties,
				new String[]{AUTH_FILE_LOCK_TRY_KEY_SHORT_FORM, AUTH_FILE_LOCK_TRY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_TRY);

		authFileLockDelay = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_DELAY_KEY_SHORT_FORM, AUTH_FILE_LOCK_DELAY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_DELAY);

		authFileLockWait = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_WAIT_KEY_SHORT_FORM, AUTH_FILE_LOCK_WAIT_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_WAIT);
	} catch (UnknownHostException uhe) {
           //throw new ConfigException(
           //        "Unable to determine client host name: %s" + uhe.getLocalizedMessage());
           // p4ic4idea: include underlying exception and use clearer exception
           throw new UnknownServerException(
                   "Unable to determine client host name: %s" + uhe.getLocalizedMessage(),
                   uhe);
	}

	// Initialize client trust
	clientTrust = new ClientTrust(this);
	return status;
}
 
Example 7
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(final String host, final int port, final Properties properties,
                         final UsageOptions opts, final boolean secure)
		throws ConfigException, ConnectionException {

	super.init(host, port, properties, opts, secure);
	try {
		cmdMapArgs = new HashMap<>();
		cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, EMPTY);
		relaxCmdNameValidationChecks = getPropertyAsBoolean(properties,
				RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
		applicationName = RpcPropertyDefs.getProperty(properties, RPC_APPLICATION_NAME_NICK);
		if (isNotBlank(getUsageOptions().getHostName())) {
			localHostName = getUsageOptions().getHostName();
		} else {
			localHostName = InetAddress.getLocalHost().getHostName();
		}

		Validate.notBlank(localHostName,
				"Null or empty client host name in RPC connection init");

		if (!useAuthMemoryStore) {
			// Search properties for ticket file path, fix for job035376
			ticketsFilePath = getPropertyByKeys(props, TICKET_PATH_KEY_SHORT_FORM,
					TICKET_PATH_KEY);
			// Search environment variable
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = PerforceEnvironment.getP4Tickets();
			}
			// Search standard OS location
			if (isBlank(ticketsFilePath)) {
				ticketsFilePath = getDefaultP4TicketsFile();
			}

			// Search properties for trust file path
			trustFilePath = getPropertyByKeys(props, TRUST_PATH_KEY_SHORT_FORM, TRUST_PATH_KEY);
			// Search environment variable
			if (isBlank(trustFilePath)) {
				trustFilePath = PerforceEnvironment.getP4Trust();
			}
			// Search standard OS location
			if (isBlank(trustFilePath)) {
				trustFilePath = getDefaultP4TrustFile();
			}
		}
		serverStats = new ServerStats();
		// Auth file lock handling properties
		authFileLockTry = getPropertyAsInt(properties,
				new String[]{AUTH_FILE_LOCK_TRY_KEY_SHORT_FORM, AUTH_FILE_LOCK_TRY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_TRY);

		authFileLockDelay = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_DELAY_KEY_SHORT_FORM, AUTH_FILE_LOCK_DELAY_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_DELAY);

		authFileLockWait = getPropertyAsLong(properties,
				new String[]{AUTH_FILE_LOCK_WAIT_KEY_SHORT_FORM, AUTH_FILE_LOCK_WAIT_KEY},
				AbstractAuthHelper.DEFAULT_LOCK_WAIT);
	} catch (UnknownHostException uhe) {
		throw new ConfigException(
				"Unable to determine client host name: %s" + uhe.getLocalizedMessage());
	}

	// Initialize client trust
	clientTrust = new ClientTrust(this);
	return status;
}
 
Example 8
Source File: RpcServer.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public ServerStatus init(String host, int port, Properties props, UsageOptions opts, boolean secure)
                        throws ConfigException, ConnectionException {
        super.init(host, port, props, opts, secure);
        try {
    			this.cmdMapArgs = new HashMap<String, Object>();
    			this.cmdMapArgs.put(ProtocolCommand.RPC_ARGNAME_PROTOCOL_ZTAGS, "");
                this.relaxCmdNameValidationChecks = RpcPropertyDefs.getPropertyAsBoolean(props,
                                                        RpcPropertyDefs.RPC_RELAX_CMD_NAME_CHECKS_NICK, false);
                this.applicationName = RpcPropertyDefs.getProperty(props,
                        								RpcPropertyDefs.RPC_APPLICATION_NAME_NICK, null);
                if (this.getUsageOptions().getHostName() != null) {
                        // This had better reflect reality...
                        this.localHostName = this.getUsageOptions().getHostName();
                } else {
                        this.localHostName = java.net.InetAddress.getLocalHost().getHostName();
                }
                if (this.localHostName == null) {
                        throw new NullPointerError("Null client host name in RPC connection init");
                }
                if (!this.useAuthMemoryStore) {
                  // Search properties for ticket file path, fix for job035376
                  this.ticketsFilePath = this.props.getProperty(PropertyDefs.TICKET_PATH_KEY_SHORT_FORM,
                                                       this.props.getProperty(PropertyDefs.TICKET_PATH_KEY));
                  // Search environment variable
                  if (this.ticketsFilePath == null) {
                  		this.ticketsFilePath = PerforceEnvironment.getP4Tickets();
                  }
                  // Search standard OS location
                  if (this.ticketsFilePath == null) {
                  		this.ticketsFilePath = getDefaultP4TicketsFile();
                  }
                  
                  // Search properties for trust file path
                  this.trustFilePath = this.props.getProperty(PropertyDefs.TRUST_PATH_KEY_SHORT_FORM,
                                                     this.props.getProperty(PropertyDefs.TRUST_PATH_KEY));
                  // Search environment variable
                  if (this.trustFilePath == null) {
                          this.trustFilePath = PerforceEnvironment.getP4Trust();

                  }
                  // Search standard OS location
                  if (this.trustFilePath == null) {
                          this.trustFilePath = getDefaultP4TrustFile();
                  }
                }
                this.serverStats = new ServerStats();
        } catch (UnknownHostException uhe) {
                throw new ConfigException("Unable to determine client host name: "
                                + uhe.getLocalizedMessage());
        }

        // Initialize client trust
        clientTrust = new ClientTrust(this);
        
        return status;
}