List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:net.mohatu.bloocoin.miner.SubmitList.java
private void submit() { for (int i = 0; i < solved.size(); i++) { try {//from w w w .j a v a 2 s . c o m Socket sock = new Socket(this.url, this.port); String result = new String(); DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = null; BufferedReader in = new BufferedReader(new InputStreamReader(is)); solution = solved.get(i); hash = DigestUtils.sha512Hex(solution); String command = "{\"cmd\":\"check" + "\",\"winning_string\":\"" + solution + "\",\"winning_hash\":\"" + hash + "\",\"addr\":\"" + Main.getAddr() + "\"}"; os = new DataOutputStream(sock.getOutputStream()); os.write(command.getBytes()); String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } if (result.contains("\"success\": true")) { System.out.println("Result: Submitted"); Main.updateStatusText(solution + " submitted", Color.blue); Thread gc = new Thread(new Coins()); gc.start(); } else if (result.contains("\"success\": false")) { System.out.println("Result: Failed"); Main.updateStatusText("Submission of " + solution + " failed, already exists!", Color.red); } is.close(); os.close(); os.flush(); sock.close(); } catch (UnknownHostException e) { e.printStackTrace(); Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red); } catch (IOException e) { e.printStackTrace(); Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red); } } Thread gc = new Thread(new Coins()); gc.start(); }
From source file:net.mohatu.bloocoin.miner.RegCustom.java
private void register() { try {// www. j a v a2 s .c o m String result = new String(); Socket sock = new Socket(this.url, this.port); String command = "{\"cmd\":\"register" + "\",\"addr\":\"" + addr + "\",\"pwd\":\"" + key + "\"}"; DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = new DataOutputStream(sock.getOutputStream()); os.write(command.getBytes()); os.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } is.close(); os.close(); sock.close(); System.out.println(result); if (result.contains("\"success\": true")) { System.out.println("Registration successful: " + addr); saveBloostamp(); } else if (result.contains("\"success\": false")) { System.out.println("Result: Failed"); JOptionPane.showMessageDialog(Main.scrollPane, "Registration failed.\nCheck your network connection", "Registration Failed", JOptionPane.ERROR_MESSAGE); System.exit(0); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.medsphere.ovid.common.uuid.KeyGenerator.java
public KeyGenerator() { try {//from w w w. j a v a2 s . c om InetAddress inet = InetAddress.getLocalHost(); byte[] bytes = inet.getAddress(); String inetAddressInHex = new String(Hex.encodeHex(bytes)); String hashCodeForThis = new String(Hex.encodeHex(intToByteArray(System.identityHashCode(this)))); middle = inetAddressInHex + hashCodeForThis; seeder = new SecureRandom(); seeder.nextInt(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); seeder = new SecureRandom(); seeder.nextInt(); middle = new Integer(this.hashCode()).toString(); } }
From source file:org.mangelp.fakeSmtpWeb.Config.java
public InetAddress getWebBindInetAddress() { InetAddress address = null;//from w w w.j a va 2 s .c om try { address = InetAddress.getByName(this.webBindAddress); } catch (UnknownHostException e) { e.printStackTrace(); } return address; }
From source file:org.mangelp.fakeSmtpWeb.Config.java
public InetAddress getMailBindInetAddress() { InetAddress address = null;// www . ja v a2 s . com try { address = InetAddress.getByName(this.mailBindAddress); } catch (UnknownHostException e) { e.printStackTrace(); } return address; }
From source file:mobi.espier.lgc.data.UploadHelper.java
private String doHttpPostAndGetResponse(String url, byte[] data) { if (TextUtils.isEmpty(url) || data == null || data.length < 1) { return null; }//from ww w . j av a 2 s .com String response = null; try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(data.length)); OutputStream outStream = conn.getOutputStream(); outStream.write(data); int mResponseCode = conn.getResponseCode(); if (mResponseCode == 200) { response = getHttpResponse(conn); } conn.disconnect(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (SocketTimeoutException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return response; }
From source file:com.waltz3d.common.httpclient.request.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;/* w ww . j av a 2s . c o m*/ HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { makeRequest(); return; } catch (UnknownHostException e) { e.printStackTrace(); if (responseHandler != null) { responseHandler.sendFailureMessage(e, "can't resolve host"); } return; } catch (SocketException e) { e.printStackTrace(); // Added to detect host unreachable if (responseHandler != null) { responseHandler.sendFailureMessage(e, "can't resolve host"); } return; } catch (SocketTimeoutException e) { e.printStackTrace(); if (responseHandler != null) { responseHandler.sendFailureMessage(e, "socket time out"); } return; } catch (IOException e) { e.printStackTrace(); cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (NullPointerException e) { e.printStackTrace(); // 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:uk.ac.cam.eng.rule.retrieval.HFileRuleQuery.java
public HFileRuleQuery(HFileRuleReader reader, BloomFilter bf, BufferedWriter out, Collection<Text> query, FeatureCreator features, RuleRetriever retriever, Configuration conf) { this.reader = reader; this.bf = bf; this.out = out; this.query = query; this.features = features; this.retriever = retriever; this.s2tClient = new TTableClient(); this.t2sClient = new TTableClient(); this.conf = conf; try {//from w w w. j a va 2s . c om s2tClient.setup(conf, true); t2sClient.setup(conf, false); } catch (UnknownHostException e) { e.printStackTrace(); System.exit(1); } }
From source file:org.apache.hadoop.mpich.MpichContainerWrapper.java
public void run() { try {//from w w w .ja v a2s . c om clientSock = new Socket(ioServer, ioServerPort); System.setOut(new PrintStream(clientSock.getOutputStream(), true)); System.setErr(new PrintStream(clientSock.getOutputStream(), true)); String hostName = InetAddress.getLocalHost().getHostName(); System.out.println("Starting process " + executable + " on " + hostName); List<String> commands = new ArrayList<String>(); commands.add(executable); if (appArgs != null && appArgs.length > 0) { commands.addAll(Arrays.asList(appArgs)); } ProcessBuilder processBuilder = new ProcessBuilder(commands); processBuilder.redirectErrorStream(true); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); Map<String, String> evns = processBuilder.environment(); evns.put("PMI_RANK", rank); evns.put("PMI_SIZE", np); evns.put("PMI_ID", pmiid); evns.put("PMI_PORT", pmiServer + ":" + pmiServerPort); if (this.isSpawn) { evns.put("PMI_SPAWNED", "1"); } LOG.info("Starting process:"); for (String cmd : commands) { LOG.info(cmd + "\n"); } Process process = processBuilder.start(); System.out.println("Process exit with value " + process.waitFor()); System.out.println("EXIT");//Stopping IOThread clientSock.close(); } catch (UnknownHostException exp) { System.err.println("Unknown Host Exception, Host not found"); exp.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.shopxx.controller.admin.VirAccountController.java
/** * //from ww w . ja v a 2 s . c om */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Long id, String amount, String content, ModelMap model, RedirectAttributes redirectAttributes, String recruitMap) { VirAccount virAccount = virAccountService.find(id); Admin admin = adminService.getCurrent(); InetAddress addr; try { addr = InetAddress.getLocalHost(); virAccount.setLastRechargeIp(addr.getHostAddress()); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } BigDecimal rebateAmounts = virAccount.getRebateAmounts().add(new BigDecimal(amount)); virAccount.setRebateAmounts(rebateAmounts); virAccount.setLastRechargeDate(new Date()); virAccountService.update(virAccount); VirTradeLog virTradeLog = new VirTradeLog(); virTradeLog.setVirAccount(virAccount); virTradeLog.setType(VirTradeLog.Type.rebate); virTradeLog.setOperator(admin.getName()); if (content == null) { virTradeLog.setContent(admin.getName() + "? " + virAccount.getSerialNumber() + "" + new BigDecimal(amount)); } else { virTradeLog.setContent(content); } virTradeLog.setRebateAmount(new BigDecimal(amount)); virTradeLog.setRechargeAmount(new BigDecimal(0)); virTradeLogService.save(virTradeLog); model.addAttribute("vitual", virAccount); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }