List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:fi.iki.elonen.SimpleWebServer.java
public SimpleWebServer(String host, int port, List<File> wwwroots, boolean quiet, String cors) { super(host, port); this.quiet = quiet; this.cors = cors; this.rootDirs = new ArrayList<File>(wwwroots); try {/*ww w . ja v a2 s . com*/ this.serverIPAddr = (InetAddress.getLocalHost()).getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } init(); }
From source file:my.madet.function.HttpParser.java
public String FetchUrL(String url) { StringBuffer result = new StringBuffer(); DefaultHttpClient httpclient = new DefaultHttpClient(); try {//from w w w. ja v a2s .co m // register ntlm auth scheme httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); httpclient.getCredentialsProvider().setCredentials( new AuthScope("info.uniten.edu.my", AuthScope.ANY_PORT), new NTCredentials(unitenid, unitenpassw, "", "")); HttpGet request = new HttpGet(url); HttpResponse httpResponse = httpclient.execute(request); BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); String line = ""; while ((line = br.readLine()) != null) { result.append(line); } br.close(); } catch (UnknownHostException e) { // no internet connection catch e.printStackTrace(); Log.e("FetchUrL", "No internet "); return "No_Internet"; } catch (Exception e) { Log.e("FetchUrL", "Error in http connection:" + e.toString()); return null; } String resultString = result.toString(); String regex = "(?i)<h1>Unauthorized Access</h1>"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(resultString); if (matcher.matches()) return "Unauthorized"; Log.i("FetchUrL content: ", result.toString()); return resultString; }
From source file:Proiect.uploadFTP.java
public void actionFTP() { adressf.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { InetAddress thisIp;//from www .j a v a 2 s . c o m try { thisIp = InetAddress.getLocalHost(); titleFTP.setText("Connection: " + thisIp.getHostAddress() + " -> " + adressf.getText()); } catch (UnknownHostException e1) { e1.printStackTrace(); } } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveState(); uploadFTP.dispose(); tree.dispose(); } }); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FTPClient client = new FTPClient(); FileInputStream fis = null; String pass = String.valueOf(passf.getPassword()); try { if (filename == null) { status.setText("File does not exist!"); } else { // Server address client.connect(adressf.getText()); // Login credentials client.login(userf.getText(), pass); if (client.isConnected()) { status.setText("Succesfull transfer!"); // File type client.setFileType(FTP.BINARY_FILE_TYPE); // File location File file = new File(filepath); fis = new FileInputStream(file); // Change the folder on the server client.changeWorkingDirectory(folderf.getText()); // Save the file on the server client.storeFile(filename, fis); } else { status.setText("Transfer failed!"); } } client.logout(); } catch (IOException e1) { Encrypter.printException(e1); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } } }); browsef.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int retval = chooserf.showOpenDialog(chooserf); if (retval == JFileChooser.APPROVE_OPTION) { status.setText(""); filename = chooserf.getSelectedFile().getName().toString(); filepath = chooserf.getSelectedFile().getPath(); filenf.setText(chooserf.getSelectedFile().getName().toString()); } } }); adv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.setSize(220, uploadFTP.getHeight()); tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); tree.setResizable(false); tree.setIconImage(Toolkit.getDefaultToolkit() .getImage(getClass().getClassLoader().getResource("assets/ico.png"))); tree.setUndecorated(true); tree.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2)); tree.setVisible(true); tree.setLayout(new BorderLayout()); JLabel labeltree = new JLabel("Server documents"); labeltree.setOpaque(true); labeltree.setBackground(Encrypter.color_light); labeltree.setBorder(BorderFactory.createMatteBorder(8, 10, 10, 0, Encrypter.color_light)); labeltree.setForeground(Encrypter.color_blue); labeltree.setFont(Encrypter.font16); JButton refresh = new JButton(""); ImageIcon refresh_icon = getImageIcon("assets/icons/refresh.png"); refresh.setIcon(refresh_icon); refresh.setBackground(Encrypter.color_light); refresh.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); refresh.setForeground(Encrypter.color_black); refresh.setFont(Encrypter.font16); refresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final FTPClient client = new FTPClient(); DefaultMutableTreeNode top = new DefaultMutableTreeNode(adressf.getText()); DefaultMutableTreeNode files = null; DefaultMutableTreeNode leaf = null; final JTree tree_view = new JTree(top); tree_view.setForeground(Encrypter.color_black); tree_view.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); tree_view.putClientProperty("JTree.lineStyle", "None"); tree_view.setBackground(Encrypter.color_light); JScrollPane scrolltree = new JScrollPane(tree_view); scrolltree.setBackground(Encrypter.color_light); scrolltree.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0)); UIManager.put("Tree.textBackground", Encrypter.color_light); UIManager.put("Tree.selectionBackground", Encrypter.color_blue); UIManager.put("Tree.selectionBorderColor", Encrypter.color_blue); tree_view.updateUI(); final String pass = String.valueOf(passf.getPassword()); try { client.connect(adressf.getText()); client.login(userf.getText(), pass); client.enterLocalPassiveMode(); if (client.isConnected()) { try { FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { files = new DefaultMutableTreeNode(ftpFile.getName()); top.add(files); if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) { FTPFile[] ftpFiles1 = client.listFiles(ftpFile.getName()); for (FTPFile ftpFile1 : ftpFiles1) { leaf = new DefaultMutableTreeNode(ftpFile1.getName()); files.add(leaf); } } } } catch (IOException e1) { Encrypter.printException(e1); } client.disconnect(); } else { status.setText("Failed connection!"); } } catch (IOException e1) { Encrypter.printException(e1); } finally { try { client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } tree.add(labeltree, BorderLayout.NORTH); tree.add(scrolltree, BorderLayout.CENTER); tree.add(refresh, BorderLayout.SOUTH); uploadFTP.addComponentListener(new ComponentListener() { public void componentMoved(ComponentEvent e) { tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); } public void componentShown(ComponentEvent e) { } public void componentResized(ComponentEvent e) { } public void componentHidden(ComponentEvent e) { } }); uploadFTP.addWindowListener(new WindowListener() { public void windowActivated(WindowEvent e) { tree.toFront(); } public void windowOpened(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowClosed(WindowEvent e) { } }); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.dispose(); tree.setVisible(true); } }); } }); }
From source file:org.dawnsci.marketplace.services.MarketplaceDAO.java
private Marketplace loadCatalogs(URL url) { ResourceSet rs = new ResourceSetImpl(); rs.getPackageRegistry().put(null, MarketplacePackage.eINSTANCE); try {/*from w w w . j av a2 s. c o m*/ Resource resource = rs.createResource(URI.createURI(url.toExternalForm())); InputStream is = url.openStream(); resource.load(is, rs.getLoadOptions()); return (Marketplace) resource.getContents().get(0); } catch (UnknownHostException e) { // marketplace is unavailable flagging it as such catalogsUnavailable = true; logger.warn("Marketplace at " + url + " is unavailable"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.opendaylight.vpnservice.dhcpservice.DhcpPktHandler.java
private void setCommonOptions(DHCP pkt, DhcpInfo dhcpInfo) { pkt.setOptionInt(DHCPConstants.OPT_LEASE_TIME, dhcpMgr.getDhcpLeaseTime()); if (dhcpMgr.getDhcpDefDomain() != null) { pkt.setOptionString(DHCPConstants.OPT_DOMAIN_NAME, dhcpMgr.getDhcpDefDomain()); }//from ww w . jav a 2 s . c o m if (dhcpMgr.getDhcpLeaseTime() > 0) { pkt.setOptionInt(DHCPConstants.OPT_REBINDING_TIME, dhcpMgr.getDhcpRebindingTime()); pkt.setOptionInt(DHCPConstants.OPT_RENEWAL_TIME, dhcpMgr.getDhcpRenewalTime()); } SubnetUtils util = null; SubnetInfo info = null; util = new SubnetUtils(dhcpInfo.getCidr()); info = util.getInfo(); String gwIp = dhcpInfo.getGatewayIp(); List<String> dnServers = dhcpInfo.getDnsServers(); try { /* * setParameterListOptions may have initialized some of these * options to maintain order. If we can't fill them, unset to avoid * sending wrong information in reply. */ if (gwIp != null) { pkt.setOptionInetAddr(DHCPConstants.OPT_SERVER_IDENTIFIER, gwIp); pkt.setOptionInetAddr(DHCPConstants.OPT_ROUTERS, gwIp); } else { pkt.unsetOption(DHCPConstants.OPT_SERVER_IDENTIFIER); pkt.unsetOption(DHCPConstants.OPT_ROUTERS); } if (info != null) { pkt.setOptionInetAddr(DHCPConstants.OPT_SUBNET_MASK, info.getNetmask()); pkt.setOptionInetAddr(DHCPConstants.OPT_BROADCAST_ADDRESS, info.getBroadcastAddress()); } else { pkt.unsetOption(DHCPConstants.OPT_SUBNET_MASK); pkt.unsetOption(DHCPConstants.OPT_BROADCAST_ADDRESS); } if ((dnServers != null) && (dnServers.size() > 0)) { pkt.setOptionStrAddrs(DHCPConstants.OPT_DOMAIN_NAME_SERVERS, dnServers); } else { pkt.unsetOption(DHCPConstants.OPT_DOMAIN_NAME_SERVERS); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.ubicompforall.cityexplorer.gui.PoiDetailsActivity.java
/** * Method fetches information for the current PoI, and shows it in the GUI. * @param poi The poi to fetch information from. *//*w w w. ja v a 2 s . co m*/ private void showPoiDetails(Poi poi) { title.setText(poi.getLabel()); description.setText(poi.getDescription()); // address.setText( poi.getAddress().getStreet() + "\n" + poi.getAddress().getZipCode() + "\n" + poi.getAddress().getCity()); // ZIP code removed address.setText(poi.getAddress().getStreet() + "\n" + poi.getAddress().getCity()); category.setText(poi.getCategory()); telephone.setText(poi.getTelephone()); openingHours.setText(poi.getOpeningHours()); webPage.setText(poi.getWebPage()); if (!poi.getImageURL().equals("")) { final String imageURL = poi.getImageURL(); new Thread(new Runnable() { public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(imageURL); //have user-inserted url HttpResponse httpResponse; final HttpEntity entity; httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = httpResponse.getEntity(); // TODO: The picture is not shown on Honeycomb SDK or higher (web service calls should be made on a separate thread) // Code should be upgraded to use the Async Task if (entity != null) { //converting into bytemap and inserting into imageView poiImage.post(new Runnable() { public void run() { byte[] imageBytes = new byte[0]; try { imageBytes = EntityUtils.toByteArray(entity); } catch (Throwable t) { debug(0, "t is " + t); // t.printStackTrace(); } poiImage.setImageBitmap( BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length)); } }); } else { debug(0, "entity == null?"); } } else { debug(0, "(httpResponse.getStatusLine().getStatusCode() == not OK "); } } catch (UnknownHostException e) { //Toast.makeText(PoiDetailsActivity.this, "Enable Internet to show Picture", Toast.LENGTH_SHORT ); debug(0, "Enable Internet to show Picture: " + imageURL); } catch (Exception e) { debug(-1, "Error fetching image: " + imageURL); e.printStackTrace(); } //try-catch }//run }//new Runnable class ).start(); } else { poiImage.setImageBitmap(null); } //if img, else blank }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
private void connect(KNXConnector knxConnector) { try {//from www . j av a2 s.c o m knxConnector.connect(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (KNXException e) { e.printStackTrace(); } }
From source file:uk.bowdlerize.service.CensorCensusService.java
private CensorPayload checkURL(String checkURL) throws IllegalArgumentException, URISyntaxException { if (!checkURL.startsWith("http")) checkURL = "http://" + checkURL; CensorPayload censorPayload = new CensorPayload(checkURL); Uri mUri = Uri.parse(checkURL);/*from w w w . j a va 2 s . c o m*/ if (null == mUri.getEncodedQuery()) { checkURL = mUri.getScheme() + "://" + mUri.getHost() + mUri.getPath(); } else { checkURL = mUri.getScheme() + "://" + mUri.getHost() + mUri.getPath() + "?" + URLEncoder.encode(mUri.getEncodedQuery()); } Log.e("Checking url", checkURL); client = new DefaultHttpClient(); /*headRequest = new HttpHead(checkURL); headRequest.setHeader("User-Agent", "OONI Android Probe");*/ httpGet = new HttpGet(checkURL); httpGet.setHeader("User-Agent", "OONI Android Probe"); try { //response = client.execute(headRequest); client.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException { if (httpResponse.getStatusLine().getStatusCode() == 302 || httpResponse.getStatusLine().getStatusCode() == 301) { for (Header hdr : httpResponse.getAllHeaders()) { if (hdr.getName().equals("Location")) { /*if (hdr.getValue().equals("http://ee-outage.s3.amazonaws.com/content-blocked/content-blocked-v1.html") || hdr.getValue().contains("http://ee-outage.s3.amazonaws.com")) { Log.e("Blocked", "Blocked by EE"); throw new CensoredException("Blocked by EE", "EE", 100); } else if (hdr.getValue().contains("http://www.t-mobile.co.uk/service/wnw-mig/entry/") || hdr.getValue().contains("http://tmobile.ee.co.uk/common/system_error_pages/outage_wnw.html")) { Log.e("Blocked", "Blocked by TMobile"); throw new CensoredException("Blocked by TMobile", "TMobile", 100); } else if (hdr.getValue().contains("http://online.vodafone.co.uk/dispatch/Portal/ContentControlServlet?type=restricted")) { Log.e("Blocked", "Blocked by Vodafone"); throw new CensoredException("Blocked by Vodafone", "Vodafone", 100); } else if (hdr.getValue().contains("http://blockpage.bt.com/pcstaticpage/blocked.html")) { Log.e("Blocked", "Blocked by BT"); throw new CensoredException("Blocked by BT", "BT", 100); } else if (hdr.getValue().contains("http://www.talktalk.co.uk/notice/parental-controls?accessurl")) { Log.e("Blocked", "Blocked by TalkTalk"); throw new CensoredException("Blocked by TalkTalk", "TalkTalk", 100); } else if (hdr.getValue().contains("http://www.plus.net/support/security/abuse/blocked.shtml")) { Log.e("Blocked", "Blocked by PlusNet"); throw new CensoredException("Blocked by PlusNet", "PlusNet", 100); } else if (hdr.getValue().contains("http://mobile.three.co.uk/pc/Live/pcreator/live/100004/pin/blocked?")) { Log.e("Blocked", "Blocked by Three"); throw new CensoredException("Blocked by Three", "Three", 100); } else if (hdr.getValue().contains("http://m.virginmedia.com/MiscPages/AdultWarning.aspx")) { Log.e("Blocked", "Blocked by VirginMobile"); throw new CensoredException("Blocked by VirginMobile", "VirginMobile", 100); } else if (hdr.getValue().contains("http://assets.o2.co.uk/18plusaccess/")) { Log.e("Blocked", "Blocked by O2"); throw new CensoredException("Blocked by O2", "O2", 100); }*/ api.checkHeader(hdr); } } } /*Log.e("intercepted return code",httpResponse.getStatusLine().toString()); for(Header hdr : httpResponse.getAllHeaders()) { Log.e("intercepted header",hdr.getName().toString() + " / " + hdr.getValue().toString()); } Log.e("intercepted header","------------------\r\n------------------\r\n------------------\r\n------------------\r\n------------------\r\n");*/ } }); response = client.execute(httpGet); } //This is the best case scenario! catch (CensoredException CE) { censorPayload.consumeCensoredException(CE); return censorPayload; } catch (UnknownHostException uhe) { uhe.printStackTrace(); censorPayload.consumeError(uhe.getMessage()); return censorPayload; } catch (ConnectTimeoutException CTE) { CTE.printStackTrace(); censorPayload.consumeError(CTE.getMessage()); return censorPayload; } catch (NoHttpResponseException NHRE) { NHRE.printStackTrace(); censorPayload.consumeError(NHRE.getMessage()); return censorPayload; } catch (IOException ioe) { ioe.printStackTrace(); censorPayload.consumeError(ioe.getMessage()); return censorPayload; } catch (IllegalStateException ise) { ise.printStackTrace(); censorPayload.setCensored(false); censorPayload.setConfidence(0); return censorPayload; } catch (Exception e) { e.printStackTrace(); censorPayload.setCensored(false); censorPayload.setConfidence(0); return censorPayload; } int statusCode = response.getStatusLine().getStatusCode(); censorPayload.setReturnCode(statusCode); Log.e("checkURL code", Integer.toString(statusCode)); if (statusCode == 403 || statusCode == 404) { censorPayload.setCensored(true); censorPayload.setConfidence(25); return censorPayload; } else if (statusCode == 504 || statusCode == 503 || statusCode == 500) { censorPayload.consumeError("Server Issue " + Integer.toString(statusCode)); return censorPayload; } String phrase = response.getStatusLine().getReasonPhrase(); Log.e("checkURL phrase", phrase); if (phrase.contains("orbidden")) { censorPayload.setCensored(true); censorPayload.setConfidence(50); return censorPayload; } if (phrase.contains("blocked")) { censorPayload.setCensored(true); censorPayload.setConfidence(100); return censorPayload; } for (Header hdr : response.getAllHeaders()) { Log.e("checkURL header", hdr.getName() + " / " + hdr.getValue()); } censorPayload.setCensored(false); censorPayload.setConfidence(1); return censorPayload; }
From source file:com.cubic9.android.droidglove.Main.java
@Override public void onResume() { super.onResume(); // show IP address mTextViewIp.setText("IP: " + getIPAddress()); // prevent sleep mWakeLock.acquire();/* w w w. ja va2 s.c o m*/ // get values of sensors mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME); // get network information InetAddress mRemoteIP = null; try { mRemoteIP = InetAddress.getByName(ip); } catch (UnknownHostException e) { new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.dialog_error_title)) .setMessage(getString(R.string.dialog_error_get_ip)) .setPositiveButton(R.string.dialog_error_ok, null).create().show(); e.printStackTrace(); } // Bring the IP Address and port together to form our OSC Sender try { mSender = new OSCPortOut(mRemoteIP, OSCPort.defaultSCOSCPort()); } catch (SocketException e) { new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.dialog_error_title)) .setMessage(getString(R.string.dialog_error_sender)) .setPositiveButton(R.string.dialog_error_ok, null).create().show(); e.printStackTrace(); } try { mReceiver = new OSCPortIn(OSCPort.defaultSCOSCPort()); } catch (SocketException e) { new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.dialog_error_title)) .setMessage(getString(R.string.dialog_error_receiver)) .setPositiveButton(R.string.dialog_error_ok, null).create().show(); e.printStackTrace(); } OSCListener listener = new OSCListener() { public void acceptMessage(java.util.Date time, OSCMessage message) { Object[] args = message.getArguments(); int vibrationTime = (Integer) args[0]; if (vibrationTime == 0) { mVibrator.vibrate(userVibrationTime); } else { mVibrator.vibrate(vibrationTime); } } }; mReceiver.addListener(OSC_ADDRESS_TO_PHONE, listener); mReceiver.startListening(); }
From source file:com.turt2live.xmail.mail.Mail.java
/** * Determines if this mail is from this server. This only verifies if the mail is from a Minecraft server (this one specifically). * If the mail is from a website, desktop application, or otherwise not a Minecraft server then this will return true as * * @return true if this mail is to be considered from this server, false otherwise *///w w w. j av a 2 s.com public boolean fromThisServer() { String ip = getServerSender(); if (ip == null) { return true; } try { InetAddress add = InetAddress.getByName(ip); if (add.isAnyLocalAddress() || add.isLoopbackAddress()) { return true; } } catch (UnknownHostException e) { e.printStackTrace(); } return XMailConfig.getIP().equalsIgnoreCase(ip); }