Example usage for java.net UnknownHostException getMessage

List of usage examples for java.net UnknownHostException getMessage

Introduction

In this page you can find the example usage for java.net UnknownHostException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.clever.ClusterManager.StorageManagerPlugins.StorageManagerClever.StorageManager.java

/**
 * Instantiates a new StorageManager object
 *//*from w  ww .  ja v a 2  s. com*/
public StorageManager() {
    this.logger = Logger.getLogger("StorageManager");
    try {
        hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        this.logger.error("Error getting local host name :" + e.getMessage());
    }
}

From source file:net.tsz.afinal.http.AjaxRequestHandler.java

private void makeRequestWithRetries(HttpUriRequest request) throws ConnectException {

    boolean retry = true;
    IOException cause = null;//  ww  w  .j  a v a2s. c om
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            if (!isCancelled()) {
                HttpResponse response = client.execute(request, context);
                if (!isCancelled()) {
                    handleResponse(response);
                }
            }
            return;
        } catch (UnknownHostException e) {
            publishProgress(Update_failure, e, "can't resolve host");
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    //??
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:org.opendaylight.ipsec.impl.IPsecImpl.java

@Override
public Future<RpcResult<RuleAddOutput>> ruleAdd(RuleAddInput input) {
    try {//from   ww  w . j a  v  a 2  s .  co m
        InetAddress srcAddress = InetAddress.getByName(input.getSource());
        InetAddress dstAddress = InetAddress.getByName(input.getDestination());
        IPsecRule rule = new IPsecRule(srcAddress, input.getSrcPrefixLen(), dstAddress, input.getDstPrefixLen(),
                input.getAction(), input.getConnectionName());
        if (IPsecConnectionBuffer.getActiveByName(input.getConnectionName()) == null) {
            throw new RuleConflictException("connection not found");
        }
        if (input.getPos() != null) {
            LOG.info("insert rule at " + input.getPos() + ": " + rule.getSource() + " --> "
                    + rule.getDestination());
            IPsecRuleBuffer.add(input.getPos(), rule);
        } else {
            LOG.info("add rule: " + rule.getSource() + " --> " + rule.getDestination());
            IPsecRuleBuffer.add(rule);
        }
        // return result
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult("success");
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    } catch (UnknownHostException e) {
        // return error message
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult("unknown host");
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    } catch (RuleConflictException e) {
        LOG.info(e.getMessage());
        // return error message
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult(e.getMessage());
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    }
}

From source file:jetbrains.buildServer.vmgr.agent.Utils.java

public String checkVAPIConnection(String url, boolean requireAuth, String user, String password)
        throws Exception {

    String textOut = null;//from   w  w w.j  ava  2s  .  co m
    try {

        System.out.println("Trying to connect with vManager vAPI " + url);
        String input = "{}";

        String apiURL = url + "/rest/sessions/count";

        HttpURLConnection conn = getVAPIConnection(apiURL, requireAuth, user, password, "POST", false, "", null,
                null);
        OutputStream os = null;
        try {
            os = conn.getOutputStream();
        } catch (java.net.UnknownHostException e) {

            throw new Exception("Failed to connect to host " + e.getMessage() + ".  Host is unknown.");

        }
        os.write(input.getBytes());
        os.flush();

        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            String reason = "";
            if (conn.getResponseCode() == 503)
                reason = "vAPI process failed to connect to remote vManager server.";
            if (conn.getResponseCode() == 401)
                reason = "Authentication Error";
            if (conn.getResponseCode() == 412)
                reason = "vAPI requires vManager 'Integration Server' license.";
            String errorMessage = "Failed : HTTP error code : " + conn.getResponseCode() + " (" + reason + ")";

            return errorMessage;
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

        StringBuilder result = new StringBuilder();
        String output;

        while ((output = br.readLine()) != null) {
            result.append(output);
        }

        conn.disconnect();

        JSONObject tmp = JSONObject.fromObject(result.toString());

        textOut = " The current number of sessions held on this vManager server are: " + tmp.getString("count");

    } catch (Exception e) {

        String errorMessage = "Failed : HTTP error: " + e.getMessage();

        if (e.getMessage().indexOf("Unexpected end of file from server") > -1) {
            errorMessage = errorMessage
                    + " (from Incisive 14.2 onward the connection is secured.  Verify your url is https://)";
        }

        System.out.println(errorMessage);
        textOut = errorMessage;
    }

    return textOut;
}

From source file:org.rifidi.emulator.reader.alien.commandhandler.AlienAutonomous.java

/**
 * Set the address that will be connected to for autonomous.
 * /*from w w  w.j a v a 2 s .  c  o  m*/
 * @param arg
 *            The CommandObject which contains the information from the
 *            method.
 * @return The CommandObject, unmodified.
 */
public CommandObject notifyAddress(CommandObject arg, AbstractReaderSharedResources asr) {

    AlienReaderSharedResources aliensr = (AlienReaderSharedResources) asr;

    if (arg.getArguments().size() > 0) {
        String ip = (String) arg.getArguments().get(0);
        if (ip.contains(":")) {
            String[] splitString = ip.split(":");
            logger.debug("splitstring length is: " + splitString.length);
            try {
                logger.debug("splitstring[0]: " + splitString[0]);
                logger.debug("splitstring[1]: " + splitString[1]);
                InetAddress newAddress = InetAddress.getByName(splitString[0]);

                ExtraInformation extraInfo = new TCPExtraInformation(newAddress,
                        Integer.parseInt(splitString[1]));

                aliensr.getAutoCommCommunicationPower().setExtraInformation(extraInfo);
            } catch (UnknownHostException e) {
                logger.error("Bad address: " + e.getMessage());
            }
        }
    }

    return AlienCommon.getter_setter(arg, asr);
}

From source file:com.clustercontrol.notify.util.SendSyslog.java

/**
 * syslog??(ShelfCheckTask?AplLogger)/*from w  ww .  j  av  a  2  s .com*/
 * ?????????syslog??<br>
 *
 * @param ipAddress
 * @param port
 * @param facility
 * @param severity
 * @param facilityId
 * @param message
 * @param timeStamp
 */
public void sendAfterConvertHostname(String ipAddress, int port, String facility, String severity,
        String facilityId, String message, String timeStamp) {
    // 
    String hostname = "";

    // ?
    hostname = getSyslogHeaderHost(facilityId);
    InetAddress inetAddress = null;

    int facilityInt = -1;
    int severityInt = -1;
    int priority = -1;

    // ?
    try {
        // generate InetAddress
        inetAddress = InetAddress.getByName(ipAddress);

        // generate priority of header
        facilityInt = SyslogFacilityConstant.stringToType(facility);
        severityInt = SyslogSeverityConstant.stringToType(severity);
        if (facilityInt == -1 || severityInt == -1) {
            m_log.info("send() sending syslog failure. facility(" + facility + ") or severity(" + severity
                    + ") is invalid.");
            return;
        }
        priority = facilityInt + severityInt;

        sendMsgWithRetry(inetAddress, port, priority, timeStamp, hostname, message);

    } catch (UnknownHostException e) {
        m_log.info("sending syslog failure. syslog's host(" + ipAddress + ") is invalid."
                + e.getClass().getSimpleName() + ", " + e.getMessage());
    } catch (SocketException e) {
        m_log.info("sending syslog failure." + e.getClass().getSimpleName() + ", " + e.getMessage());
    } catch (IOException e) {
        m_log.info("sending syslog failure." + e.getClass().getSimpleName() + ", " + e.getMessage());
    }
}

From source file:com.example.pierre.applicompanies.library_http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;/*from   w w w.java2 s  .com*/
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                if (isCancelled()) {
                    // Eating exception, as the request was cancelled
                    return;
                }
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry) {
                responseHandler.sendRetryMessage(executionCount);
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        Log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:com.zftlive.android.library.third.asynchttp.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;//from w  ww. j av  a2s. c o m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(e, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                if (isCancelled()) {
                    // Eating exception, as the request was cancelled
                    return;
                }
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry) {
                responseHandler.sendRetryMessage(executionCount);
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        Log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:gov.nist.appvet.servlet.AppVetServlet.java

private AppInfo createAppInfo(String userName, String sessionId, FileItem fileItem, String clientIpAddress,
        HttpServletRequest request) {/*from  ww  w  . j  a v  a  2  s.  c  o m*/
    String appId = generateAppid();
    AppInfo appInfo = new AppInfo(appId, true);
    appInfo.userName = userName;
    appInfo.sessionId = sessionId;
    appInfo.fileItem = fileItem;
    appInfo.fileName = FileUtil.getNormalizedFileName(fileItem.getName());
    InetAddress addr;
    try {
        addr = InetAddress.getByName(request.getRemoteHost());
    } catch (UnknownHostException e) {
        log.error(e.getMessage());
        return null;
    }
    appInfo.clientHost = addr.getCanonicalHostName();

    // Set temporary icon until icon is extracted from app
    final String sourceIconPath = AppVetProperties.APP_IMAGES + "/default.png";
    appInfo.log.debug("Source icon: " + sourceIconPath);
    final String destIconPath = AppVetProperties.APP_IMAGES + "/" + appInfo.appId + ".png";
    FileUtil.copyFile(sourceIconPath, destIconPath);
    return appInfo;
}

From source file:com.yunmall.ymsdk.net.http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;// w  ww  . j a  va  2 s  .co  m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                if (isCancelled()) {
                    // Eating exception, as the request was cancelled
                    return;
                }
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry && (responseHandler != null)) {
                responseHandler.sendRetryMessage(executionCount);
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        YmLog.d(TAG, "Unhandled exception origin cause", e);
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}