List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:com.boundary.camel.component.url.UrlClient.java
protected void connect() { try {// www .j a v a2 s. c o m URL url = configuration.toURL(); LOG.info("attempting connection with url: {}", url); connection = (HttpURLConnection) url.openConnection(); configureConnection(connection); connection.connect(); setResponseCode(connection.getResponseCode()); setInputStream(connection.getInputStream()); BufferedReader is = new BufferedReader(new InputStreamReader(getInputStream())); String line; StringBuffer sb = new StringBuffer(); while ((line = is.readLine()) != null) { sb.append(line); } setResponseBody(sb.toString()); setURLStatus(OK); } catch (UnknownHostException u) { setURLStatus(UNKNOWN_HOST); setResponseCode(HTTP_BAD_GATEWAY); if (LOG.isDebugEnabled()) { u.printStackTrace(); } } catch (SocketTimeoutException s) { setURLStatus(TIME_OUT); setResponseCode(HTTP_INTERNAL_ERROR); if (LOG.isDebugEnabled()) { s.printStackTrace(); } } catch (IOException i) { setURLStatus(ERROR); setResponseCode(HTTP_INTERNAL_ERROR); if (LOG.isDebugEnabled()) { i.printStackTrace(); } } catch (Exception e) { setURLStatus(ERROR); setResponseCode(HTTP_INTERNAL_ERROR); if (LOG.isDebugEnabled()) { e.printStackTrace(); } } }
From source file:net.Downloader.java
/** *Constructor Method. You can select allowed mime and upper size limit to download a file. *@param url: The url of the file we want to download from the web *@param path: The path of the file we want to store the file downloaded file. It may dbe different from the name of the file *@param allowedType: The allowed mime types we want to download *@param allowedSize: The maximum size of downloaded file in <strong>BYTES</strong> that we permit to download for no limit enter<br> *zero or negative valie //from w w w.ja v a2 s . c o m */ public Downloader(String url, String path, String[] allowedType, long allowedSize) { boolean ok = true; //Needed for ssl try { if (!url.startsWith("http://") && !url.startsWith("https://")) { url = "http://" + url; } else if (url.startsWith("https://")) { ssl = true; } dl = new URL(url); fl = new File(path); conn = dl.openConnection(); if (conn != null) { mime = conn.getContentType(); for (int i = 0; allowedType != null && mime != null && i < allowedType.length; i++) { if (mime.startsWith(allowedType[i])) { //System.out.println("Mime OK"); ok = true; break; } else { //System.out.println("Mime Not OK"); ok = false; } } String s = conn.getHeaderField("Content-Length"); if (s != null) { total = Long.parseLong(s); if (ok) { if (allowedSize > 0 && total < allowedSize) { System.out.println("OK"); ok = true; } else if (allowedSize <= 0) { System.out.println("No Limit"); ok = true; } else { System.out.println("Not OK"); ok = false; } } } } if (ok) { Thread t = new Thread(this); t.start(); } else { status = "Error"; } } catch (UnknownHostException u) { System.err.println("Uknown Host"); u.printStackTrace(); } catch (Exception m) { m.printStackTrace(); } }
From source file:org.sipfoundry.preflight.TFTP.java
public ResultCode validate(int timeout, NetworkResources networkResources, JournalService journalService, InetAddress bindAddress) { ResultCode results = NONE;//from w ww . j a va 2 s .c o m InetAddress tftpServerAddress = null; String testFile = new String("00D01EFFFFFE"); String[] verificationStrings = { "LIP-68XX configuration information", "[VOIP]", "outbound_proxy_server", "[PROVISION]", "decrypt_key" }; if (networkResources.configServer == null) { journalService.println("No TFTP server provided, skipping test.\n"); return CONFIG_SERVER_MISSING; } journalService.println("Starting TFTP server test."); TFTPClient tftp = new TFTPClient(); tftp.setDefaultTimeout(timeout * 1000); if (IPAddressUtil.isLiteralIPAddress(networkResources.configServer)) { try { tftpServerAddress = InetAddress.getByName(networkResources.configServer); } catch (UnknownHostException e) { // Should never get here. e.printStackTrace(); } journalService.println("Using TFTP server literal address: " + networkResources.configServer); } else { // Try to retrieve A RECORD for TFTP server, checking each DNS server. SimpleResolver resolver = null; try { resolver = new SimpleResolver(); resolver.setTimeout(timeout); } catch (UnknownHostException e) { e.printStackTrace(); } for (InetAddress dnsServer : networkResources.domainNameServers) { journalService.println( "Looking up TFTP server address via DNS server: " + dnsServer.getCanonicalHostName()); String targetMessage = new String( " TFTP server address \"" + networkResources.configServer + "\""); resolver.setAddress(dnsServer); Lookup aLookup = null; try { aLookup = new Lookup(networkResources.configServer, Type.A); } catch (TextParseException e) { journalService.println(" is malformed.\n"); journalService.println(targetMessage); return TFTP_ADDRESS_MALFORMED; } aLookup.setResolver(resolver); Record[] aRecords = aLookup.run(); switch (aLookup.getResult()) { case Lookup.SUCCESSFUL: if (aRecords != null) { InetAddress targetAddress = ((ARecord) aRecords[0]).getAddress(); targetMessage += " resolves to: " + targetAddress.getHostAddress(); journalService.println(targetMessage); if (tftpServerAddress == null) { tftpServerAddress = targetAddress; } else { // Check that multiple lookups result in same address. if (!tftpServerAddress.equals(targetAddress)) { journalService.println(" TFTP server address does not match prior lookup."); results = MULTIPLE_CONFIG_TARGETS; } } } else { targetMessage += " could not be resolved."; journalService.println(targetMessage); results = TFTP_TARGET_UNRESOLVED; } break; case Lookup.UNRECOVERABLE: targetMessage += " [Unrecoverable error]"; journalService.println(targetMessage); results = TFTP_TARGET_UNRESOLVED; break; case Lookup.TRY_AGAIN: targetMessage += " [Lookup timeout]"; journalService.println(targetMessage); results = TFTP_TARGET_UNRESOLVED; break; case Lookup.HOST_NOT_FOUND: targetMessage += " could not be resolved."; journalService.println(targetMessage); results = TFTP_TARGET_UNRESOLVED; break; case Lookup.TYPE_NOT_FOUND: targetMessage += " could not be resolved."; journalService.println(targetMessage); results = TFTP_TARGET_UNRESOLVED; break; } } } if ((tftpServerAddress == null) || (results == MULTIPLE_CONFIG_TARGETS)) { journalService.println("Cannot recover from previous errors, aborting TFTP test.\n"); return results; } journalService.println("Beginning TFTP get request of test file: " + testFile); // Open local socket try { tftp.open(); } catch (SocketException e) { journalService.println("TFTP client failure. " + e.getMessage() + "\n"); return TFTP_CLIENT_FAILURE; } // Try to receive remote file via TFTP try { ByteArrayOutputStream output = new ByteArrayOutputStream(); tftp.open(bindPort, bindAddress); tftp.receiveFile(testFile, org.apache.commons.net.tftp.TFTP.ASCII_MODE, output, tftpServerAddress); String testFileContents = output.toString(); boolean verified = true; for (String verificationString : verificationStrings) { if (!testFileContents.contains(verificationString)) { verified = false; } } if (verified) { journalService.println("File received successfully."); } else { journalService.println("File received but contents do not verify."); results = TFTP_CONTENTS_FAILED; } } catch (UnknownHostException e) { journalService.println("TFTP client failure. " + e.getMessage()); results = TFTP_CLIENT_FAILURE; } catch (IOException e) { journalService.println("TFTP get failed. " + e.getMessage()); results = TFTP_GET_FAILED; } finally { // Close local socket and output file tftp.close(); } journalService.println(""); return results; }
From source file:org.openhab.binding.hexabus.internal.HexaBusBinding.java
private void testSwitch() { InetAddress pp = null;//from ww w . j a va 2 s . c o m try { pp = InetAddress.getByName("acdc::50:c4ff:fe04:8310"); } catch (UnknownHostException e) { e.printStackTrace(); logger.debug("Could create InetAddress in testSwitch()!"); } logger.debug("Attempting to send 'off' and 'on' packets..."); switchPlug(pp, ON); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); logger.debug("Interrupted in testSwitch()!"); } switchPlug(pp, OFF); }
From source file:edu.uic.udptransmit.UDPTransmit.java
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if ("initialize".equals(action)) { final String host = args.getString(0); final int port = args.getInt(1); // Run the UDP transmitter initialization on its own thread (just in case, see sendMessage comment) cordova.getThreadPool().execute(new Runnable() { public void run() { this.initialize(host, port, callbackContext); }/*ww w.j a v a2 s .c o m*/ private void initialize(String host, int port, CallbackContext callbackContext) { boolean successResolvingIPAddress = false; // create packet InetAddress address = null; try { // 'host' can be a ddd.ddd.ddd.ddd or named URL, so doesn't always resolve address = InetAddress.getByName(host); successResolvingIPAddress = true; } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } // If we were able to resolve the IP address from the host name, we're good to try to initialize if (successResolvingIPAddress) { byte[] bytes = new byte[0]; datagramPacket = new DatagramPacket(bytes, 0, address, port); // create socket try { datagramSocket = new DatagramSocket(); successInitializingTransmitter = true; } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (successInitializingTransmitter) callbackContext.success( "Success initializing UDP transmitter using datagram socket: " + datagramSocket); else callbackContext.error( "Error initializing UDP transmitter using datagram socket: " + datagramSocket); } }); return true; } else if ("sendMessage".equals(action)) { final String message = args.getString(0); // Run the UDP transmission on its own thread (it fails on some Android environments if run on the same thread) cordova.getThreadPool().execute(new Runnable() { public void run() { this.sendMessage(message, callbackContext); } private void sendMessage(String data, CallbackContext callbackContext) { boolean messageSent = false; // Only attempt to send a packet if the transmitter initialization was successful if (successInitializingTransmitter) { byte[] bytes = data.getBytes(); datagramPacket.setData(bytes); try { datagramSocket.send(datagramPacket); messageSent = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (messageSent) callbackContext.success("Success transmitting UDP packet: " + datagramPacket); else callbackContext.error("Error transmitting UDP packet: " + datagramPacket); } }); return true; } else if ("resolveHostName".equals(action)) { final String url = args.getString(0); // Run the UDP transmission on its own thread (it fails on some Android environments if run on the same thread) cordova.getThreadPool().execute(new Runnable() { public void run() { this.resolveHostName(url, callbackContext); } private void resolveHostName(String url, CallbackContext callbackContext) { boolean hostNameResolved = false; InetAddress address = null; try { // 'host' can be a ddd.ddd.ddd.ddd or named URL, so doesn't always resolve address = InetAddress.getByName(url); hostNameResolved = true; } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (hostNameResolved) callbackContext.success(address.getHostAddress()); else callbackContext.error("Error resolving host name: " + url); } }); return true; } else if ("resolveHostNameWithUserDefinedCallbackString".equals(action)) { final String url = args.getString(0); final String userString = args.getString(1); // Run the UDP transmission on its own thread (it fails on some Android environments if run on the same thread) cordova.getThreadPool().execute(new Runnable() { public void run() { this.resolveHostNameWithUserDefinedCallbackString(url, userString, callbackContext); } private void resolveHostNameWithUserDefinedCallbackString(String url, String userString, CallbackContext callbackContext) { boolean hostNameResolved = false; InetAddress address = null; try { // 'host' can be a ddd.ddd.ddd.ddd or named URL, so doesn't always resolve address = InetAddress.getByName(url); hostNameResolved = true; } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (hostNameResolved) callbackContext.success(address.getHostAddress() + "|" + userString); else callbackContext.error("|" + userString); } }); return true; } return false; }
From source file:org.speechforge.cairo.server.resource.ResourceServerImpl.java
/** * TODOC// www.j a v a 2 s. c om * * @param registryImpl * @throws RemoteException * @throws SipException */ public ResourceServerImpl(ResourceRegistry registryImpl, int sipPort, String sipTransport, String hostIpAddress, String publicAddress) throws RemoteException, SipException { super(); this.hostIpAddress = hostIpAddress; if (hostIpAddress == null) { try { InetAddress addr = CairoUtil.getLocalHost(); this.hostIpAddress = addr.getHostAddress(); //host = addr.getCanonicalHostName(); } catch (UnknownHostException e) { this.hostIpAddress = "127.0.0.1"; _logger.debug(e, e); e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (sipPort == 0) sipPort = 5050; if (sipTransport == null) sipTransport = "tcp"; cairoSipAddress = "sip:cairo@" + this.hostIpAddress; _ua = new SipAgent(this, cairoSipAddress, "Cairo SIP Stack", this.hostIpAddress, publicAddress, sipPort, sipTransport); _registryImpl = registryImpl; }
From source file:org.apache.camel.processor.idempotent.mongodb.MongoDbIdempotentRepository.java
public void init() { try {//from w w w .ja va2s . c om Mongo mongo = new Mongo(host, port); db = mongo.getDB(dbName); coll = db.getCollection(collectionName); // create a unique index on event id key coll.ensureIndex(new BasicDBObject(EVENTID, 1), "repo_index", true); log.debug("unique index constraint --> " + coll.getIndexInfo()); } catch (UnknownHostException e) { e.printStackTrace(); } catch (MongoException e) { e.printStackTrace(); } }
From source file:gash.router.app.DemoApp.java
public void sendDeleteTasks(String fileName) { try {//from w ww . j a v a 2s . c om mc.deleteFile(fileName); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gash.router.app.DemoApp.java
public void sendReadTasks(String filename) { try {/*w ww . j a va2 s .c o m*/ mc.getFile(filename); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ow.tool.emulator.Main.java
public void start(String[] args) { EmulatorMode mode = EmulatorMode.NORMAL; boolean eventDrivenMode = false; RemoteAppInstanceTable workerTable = null; String controlTargetListFilename = null; EmulatorContext emuContext = null;//from ww w.ja v a 2s.c o m int initialHostID = 0; // get self hostname InetAddress selfHostAddress = null; try { selfHostAddress = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); System.exit(1); } // parse command-line arguments Options opts = new Options(); opts.addOption("h", "help", false, "print help"); opts.addOption("E", "eventdriven", false, "emulator runs in event driven mode"); opts.addOption("f", "hostfile", true, "host file for working in master mode"); opts.addOption("w", "workertable", true, "works in worker mode"); opts.addOption("s", "selfipaddress", true, "self IP address (and port)"); opts.addOption("c", "controltargetlistfile", true, "control target list file"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(opts, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(); System.exit(1); } if (cmd.hasOption('E')) { eventDrivenMode = true; } optVal = cmd.getOptionValue('f'); if (optVal != null) { try { workerTable = RemoteAppInstanceTable.readHostFile(optVal); } catch (IOException e) { e.printStackTrace(); usage(); System.exit(1); } mode = EmulatorMode.MASTER; } optVal = cmd.getOptionValue('w'); if (optVal != null) { try { workerTable = RemoteAppInstanceTable.parseString(optVal); } catch (UnknownHostException e) { e.printStackTrace(); usage(); System.exit(1); } mode = EmulatorMode.WORKER; } optVal = cmd.getOptionValue('s'); if (optVal != null) { try { selfHostAddress = InetAddress.getByName(optVal); } catch (UnknownHostException e) { e.printStackTrace(); System.exit(1); } } optVal = cmd.getOptionValue('c'); if (optVal != null) { controlTargetListFilename = optVal; mode = EmulatorMode.CONTROLLER; } args = cmd.getArgs(); if (mode == EmulatorMode.WORKER) { // set initial host ID (emuXX) initialHostID = workerTable.getStartHostID(selfHostAddress); } // provide an EmulatorContext if (mode == EmulatorMode.MASTER) { emuContext = new EmulatorContext(System.out, initialHostID, workerTable, eventDrivenMode, mode); } else { emuContext = new EmulatorContext(System.out, initialHostID, new LocalAppInstanceTable(), eventDrivenMode, mode); } // connect to controlee if (mode == EmulatorMode.CONTROLLER) { try { this.connect(emuContext, controlTargetListFilename); } catch (IOException e) { e.printStackTrace(); return; } } // force the messaging service to use Emulator if (mode == EmulatorMode.WORKER) { MessagingFactory.forceDistributedEmulator(initialHostID, workerTable); } else { MessagingFactory.forceEmulator(initialHostID); } // parse scenario files try { parseScenario(emuContext, args); } catch (IOException e) { e.printStackTrace(); return; } }