List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:com.cablelabs.fsm.AutoProvState.java
private String autoGenerate(int msgIndexQueue) { Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM); Properties dut = SystemSettings.getSettings(SettingConstants.DUT); Boolean autoProv = SystemSettings.getBooleanSetting(SettingConstants.AUTO_GENERATE); Boolean autoGen = SystemSettings.getBooleanSetting(SettingConstants.AUTO_PROVISION); if (autoProv && autoGen) { if (pd != null && platform != null && dut != null) { String pcscfLabel = dut.getProperty(SettingConstants.PCSCF); String macAddr = dut.getProperty(SettingConstants.MAC_ADDRESS); String tftpIP = platform.getProperty(SettingConstants.TFTP_SERVER_IP); String tftpPort = platform.getProperty(SettingConstants.TFTP_SERVER_PORT); String phone1 = dut.getProperty(SettingConstants.PHONE_NUMBER_1); String phone2 = dut.getProperty(SettingConstants.PHONE_NUMBER_2); String cw = platform.getProperty(SettingConstants.CW_NUMBER); if (macAddr != null && pcscfLabel != null && tftpIP != null && tftpPort != null && cw != null) { // Next verify the port is not set to zero try { int port = Integer.parseInt(tftpPort); if (port > 0 && port <= 65535) { // Next make sure the TFTP Server IP is not set to 0.0.0.0 if (tftpIP.equals("0.0.0.0")) { logger.warn(PC2LogCategory.PCSim2, subCat, "The TFTP Server IP setting in the platform file is not valid. Ending auto generate operation."); return null; }/*from w w w. j a v a 2 s.com*/ File input = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator + SettingConstants.CW + cw + File.separator + pd.getProvFileName()); if (input != null) { ProvGen pg = new ProvGen(input); if (phone1 != null) pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_1, phone1); if (phone2 != null) pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_2, phone2); Properties pcscf = SystemSettings.getSettings(pcscfLabel); if (pcscf != null) { String pcscfIP = pcscf.getProperty(SettingConstants.IP); if (pcscfIP != null) pg.changePCSCF(pcscfIP); } String newFileName = macAddr + ".bin"; if (pg.output(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator + SettingConstants.CW + cw + File.separator + newFileName)) { // Test system //File output = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + newFileName); //File pact = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + "chinmaya_base_ph1_pcscf.bin"); //pg.compare(pact, output); // Create a data entry of the issued event //ProvisioningData issuePD = new ProvisioningData(macAddr, pd.getPolicyFileName(), newFileName); logger.info(PC2LogCategory.FSM, subCat, "AutoProvState beginning to TFTP the new provisioning file."); // Next we need to TFTP the file to the server TFTPClient client = new TFTPClient(); File binFile = new File( SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator + SettingConstants.CW + cw + File.separator + newFileName); if (binFile.isFile() && binFile.canRead()) { FileInputStream istrm = new FileInputStream(binFile); //InetAddress ia = InetAddress.getByName("10.4.1.37"); client.open(); // client.open(20003, ia); client.sendFile(newFileName, TFTP.BINARY_MODE, istrm, tftpIP, port); client.close(); logger.info(PC2LogCategory.FSM, subCat, "TFTP of the new provisioning file is complete."); super.processPrelude(msgIndexQueue); } else { logger.warn(PC2LogCategory.FSM, subCat, "The " + macAddr + ".bin doesn't appear in the " + SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator + SettingConstants.CW + cw + " Ending auto generate operation."); } } else { logger.error(PC2LogCategory.FSM, subCat, "AutoProvState could not locate provisioning template file[" + input.getAbsolutePath() + "]."); } } // else { // logger.info(PC2LogCategory.FSM, subCat, "AutoProvState is terminating because the input directory is null."); // } } else { logger.info(PC2LogCategory.PCSim2, subCat, "AutoProvState is terminating because the port(" + port + ") is less than 0 or greater than 65535."); } } catch (NumberFormatException nfe) { logger.warn(PC2LogCategory.FSM, subCat, "AutoProvState is not auto generating a provisioning file because the " + "TFTP Server Port setting doesn't appear to be a number."); } catch (UnknownHostException uhe) { logger.warn(PC2LogCategory.FSM, subCat, "AutoProvState is not auto generating a provisioning file because the " + "system encountered an error when attempting to send the file to the TFTP Server.\n" + uhe.getMessage() + "\n" + uhe.getStackTrace()); } catch (IOException ioe) { logger.warn(PC2LogCategory.FSM, subCat, "AutoProvState is not auto generating a provisioning file because the " + "system encountered an error when attempting to send the file to the TFTP Server.\n" + ioe.getMessage() + "\n" + ioe.getStackTrace()); } } else { logger.info(PC2LogCategory.FSM, subCat, "AutoProvState is stopping because one of the values is null.\n" + "macAddr=" + macAddr + " pcscfLabel=" + pcscfLabel + " tftpIP=" + tftpIP + " tftpPort=" + tftpPort); } } else { if (pd != null) logger.info(PC2LogCategory.FSM, subCat, "The provisioning data is null, terminating processing."); if (platform != null) logger.info(PC2LogCategory.FSM, subCat, "The Platform settings is null, terminating processing."); if (dut != null) logger.info(PC2LogCategory.FSM, subCat, "The DUT settings is null, terminating processing."); } } else { Generate g = new Generate(EventConstants.AUTO_PROV_PROMPT, null, this.owner.getName()); try { g.execute(super.api, 0); } catch (PC2Exception pce) { logger.error(PC2LogCategory.FSM, subCat, name + " couldn't generate " + EventConstants.AUTO_PROV_PROMPT + " event to the FSM."); } } return null; }
From source file:cn.isif.util_plus.http.HttpHandler.java
@SuppressWarnings("unchecked") private ResponseInfo<T> sendRequest(HttpRequestBase request) throws HttpException { HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (true) { if (autoResume && isDownloadingFile) { File downloadFile = new File(fileSavePath); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }//from www. j a va 2s. c om if (fileLen > 0) { request.setHeader("RANGE", "bytes=" + fileLen + "-"); } } boolean retry = true; IOException exception = null; try { requestMethod = request.getMethod(); if (HttpUtils.sHttpCache.isEnabled(requestMethod)) { String result = HttpUtils.sHttpCache.get(requestUrl); if (result != null) { return new ResponseInfo<T>(null, (T) result, true); } } ResponseInfo<T> responseInfo = null; if (!isCancelled()) { HttpResponse response = client.execute(request, context); responseInfo = handleResponse(response); } return responseInfo; } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (NullPointerException e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (HttpException e) { throw e; } catch (Throwable e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } if (!retry) { throw new HttpException(exception); } } }
From source file:com.drive.student.xutils.http.HttpHandler.java
@SuppressWarnings("unchecked") private com.drive.student.xutils.http.ResponseInfo<T> sendRequest(HttpRequestBase request) throws HttpException { HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (true) { if (autoResume && isDownloadingFile) { File downloadFile = new File(fileSavePath); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }//www . j av a2s . c om if (fileLen > 0) { request.setHeader("RANGE", "bytes=" + fileLen + "-"); } } boolean retry = true; IOException exception = null; try { requestMethod = request.getMethod(); if (HttpUtils.sHttpCache.isEnabled(requestMethod)) { String result = HttpUtils.sHttpCache.get(requestUrl); if (result != null) { return new com.drive.student.xutils.http.ResponseInfo<T>(null, (T) result, true); } } com.drive.student.xutils.http.ResponseInfo<T> responseInfo = null; if (!isCancelled()) { HttpResponse response = client.execute(request, context); responseInfo = handleResponse(response); } return responseInfo; } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (NullPointerException e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (HttpException e) { throw e; } catch (Throwable e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } if (!retry) { throw new HttpException(exception); } } }
From source file:jenkins.plugins.coverity.CIMInstance.java
public FormValidation doCheck() throws IOException { StringBuilder errorMessage = new StringBuilder(); errorMessage.append("\"" + user + "\" does not have following permission(s): "); try {//from ww w. jav a2 s .c o m URL url = WebServiceFactory.getInstance().getURL(this); int responseCode = getURLResponseCode(new URL(url, WebServiceFactory.CONFIGURATION_SERVICE_V9_WSDL)); if (responseCode != 200) { return FormValidation .error("Coverity web services were not detected. Connection attempt responded with " + responseCode + ", check Coverity Connect version (minimum supported version is " + CoverityVersion.MINIMUM_SUPPORTED_VERSION.getEffectiveVersion() .getEffectiveVersion() + ")."); } List<String> missingPermission = new ArrayList<String>(); ; if (!checkUserPermission(missingPermission) && !missingPermission.isEmpty()) { for (String permission : missingPermission) { errorMessage.append("\"" + permission + "\" "); } return FormValidation.error(errorMessage.toString()); } return FormValidation.ok("Successfully connected to the instance."); } catch (UnknownHostException e) { return FormValidation.error("Host name unknown"); } catch (ConnectException e) { return FormValidation.error("Connection refused"); } catch (SocketException e) { return FormValidation.error("Error connecting to CIM. Please check your connection settings."); } catch (SOAPFaultException e) { if (StringUtils.isNotEmpty(e.getMessage())) { if (e.getMessage().contains("User " + user + " Doesn't have permissions to perform {invokeWS}")) { return FormValidation.error(errorMessage.append("\"Access web services\"").toString()); } return FormValidation.error(e.getMessage()); } return FormValidation.error(e, "An unexpected error occurred."); } catch (Throwable e) { String javaVersion = System.getProperty("java.version"); if (javaVersion.startsWith("1.6.0_")) { int patch = Integer.parseInt(javaVersion.substring(javaVersion.indexOf('_') + 1)); if (patch < 26) { return FormValidation.error(e, "Please use Java 1.6.0_26 or later to run Jenkins."); } } return FormValidation.error(e, "An unexpected error occurred."); } }
From source file:com.damytech.HttpConn.AsyncHttpRequest.java
private void makeRequestWithRetries() throws ConnectException { // This is an additional layer of retry logic lifted from droid-fu // See: https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java boolean retry = true; IOException cause = null;//from www .j a v a2 s . com HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { makeRequest(); return; } catch (UnknownHostException e) { if (responseHandler != null) { responseHandler.sendFailureMessage(e, "can't resolve host"); } return; } catch (IOException e) { cause = e; retry = 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); } } // no retries left, crap out with exception ConnectException ex = new ConnectException(); ex.initCause(cause); throw ex; }
From source file:com.my.cloudcontact.http.HttpHandler.java
private void makeRequestWithRetries(HttpUriRequest request) throws IOException { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }// w w w . j av a 2 s. co m if (fileLen > 0) request.setHeader("RANGE", "bytes=" + fileLen + "-"); } boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { if (!isCancelled()) { HttpResponse response = client.execute(request, context); if (!isCancelled()) { handleResponse(request, response); } } return; } catch (UnknownHostException e) { publishProgress(UPDATE_FAILURE, e, 0, "unknownHostExceptioncan'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); } catch (Exception e) { cause = new IOException("Exception" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } } if (cause != null) throw cause; else throw new IOException(""); }
From source file:org.jivesoftware.smack.ConnectionConfiguration.java
/** * Returns the host to use when establishing the connection. The host and port to use * might have been resolved by a DNS lookup as specified by the XMPP spec (and therefore * may not match the {@link #getServiceName service name}. * * @return the host to use when establishing the connection. *//*from w w w.j a v a 2 s .c o m*/ public String getHost() { // ?IP???IP? if (!InetAddressUtils.isIPv4Address(host) && !InetAddressUtils.isIPv6Address(host)) { try { InetAddress address = InetAddress.getByName(host); host = address.getHostAddress(); Log.d(LOG_TAG, "transform host name to host address:" + host); } catch (UnknownHostException e) { Log.e(LOG_TAG, e.getMessage(), e); } } return host; }
From source file:com.adis.tools.http.HttpHandler.java
@SuppressWarnings("unchecked") private ResponseInfo<T> sendRequest(HttpRequestBase request) throws HttpException { HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (true) { if (autoResume && isDownloadingFile) { downloadFile = new File(fileSavePath); fileLen = 0;/*from w ww .ja va2 s. co m*/ if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); } if (fileLen > 0) { request.setHeader("RANGE", "bytes=" + fileLen + "-"); } } boolean retry = true; IOException exception = null; try { requestMethod = request.getMethod(); if (HttpUtils.sHttpCache.isEnabled(requestMethod)) { String result = HttpUtils.sHttpCache.get(requestUrl); if (result != null) { return new ResponseInfo<T>(null, (T) result, true); } } ResponseInfo<T> responseInfo = null; if (!isCancelled()) { HttpResponse response = client.execute(request, context); responseInfo = handleResponse(response); } return responseInfo; } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (NullPointerException e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } catch (HttpException e) { throw e; } catch (Throwable e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedCount, context); } if (!retry) { throw new HttpException(exception); } } }
From source file:com.roach.framework.http.AsyncHttpRequest.java
private void makeRequestWithRetries() throws ConnectException { // This is an additional layer of retry logic lifted from droid-fu // See:/*from w w w. j a v a2s .com*/ // https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { makeRequest(); return; } catch (UnknownHostException e) { if (responseHandler != null) { responseHandler.sendFailureMessage(e, "can't resolve host"); } return; } catch (IOException e) { cause = e; retry = 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); } } // no retries left, crap out with exception ConnectException ex = new ConnectException(); ex.initCause(cause); throw ex; }
From source file:com.miku.framelite.httpx.core.DownloadHandler.java
private void makeRequestWithRetries(HttpUriRequest request) throws Exception { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }/*w w w.j a v a2 s .c om*/ if (fileLen > 0) { request.setHeader("RANGE", "bytes=" + fileLen + "-"); } } Exception cause = null; try { if (!isCancelled()) { HttpResponse response = client.execute(request/* , context */); if (!isCancelled()) { handleResponse(response); } } } catch (UnknownHostException e) { e.printStackTrace(); publishProgress(UPDATE_FAILURE, e, 0, "unknownHostExceptioncan't resolve host"); cause = e; } catch (IOException e) { e.printStackTrace(); cause = e; } catch (NullPointerException e) { e.printStackTrace(); // HttpClient 4.0.x ?bug // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); } catch (Exception e) { e.printStackTrace(); cause = e; } if (cause != null) { throw cause; } }