List of usage examples for java.net UnknownHostException toString
public String toString()
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 . j av 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:com.zhengde163.netguard.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { // Util.setTheme(this); setTheme(R.style.AppThemeBlue);//from w ww. ja va 2 s . co m super.onCreate(savedInstanceState); setContentView(R.layout.logging); running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); // SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); ImageView ivEnabled = (ImageView) actionView.findViewById(R.id.ivEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); log = prefs.getBoolean("log", false); // Show disabled message // TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); // tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); final LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable); ly.setVisibility(log ? View.GONE : View.VISIBLE); ImageView ivClose = (ImageView) findViewById(R.id.ivClose); ivClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ly.setVisibility(View.GONE); } }); // Set enabled switch // swEnabled.setChecked(log); if (ivEnabled != null) { if (log) { ivEnabled.setImageResource(R.drawable.on); } else { ivEnabled.setImageResource(R.drawable.off); } ivEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { log = !log; boolean isChecked = log; prefs.edit().putBoolean("log", isChecked).apply(); } }); } // swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prefs.edit().putBoolean("log", isChecked).apply(); // } // }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; case R.id.menu_block: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main1 = new Intent(ActivityLog.this, ActivityMain.class); main1.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main1); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:com.radicaldynamic.groupinform.services.DatabaseService.java
synchronized public ReplicationStatus replicate(String db, int mode) { final String tt = t + "replicate(): "; if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "about to replicate " + db); // Will not replicate unless signed in if (!Collect.getInstance().getIoService().isSignedIn()) { if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "aborting replication: not signed in"); return null; }/*from w w w.j av a2 s . co m*/ if (Collect.getInstance().getInformOnlineState().isOfflineModeEnabled()) { if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "aborting replication: offline mode is enabled"); return null; } /* * Lookup master cluster by IP. Do this instead of relying on Erlang's internal resolver * (and thus Google's public DNS). Our builds of Erlang for Android do not yet use * Android's native DNS resolver. */ String masterClusterIP = null; try { InetAddress[] clusterInetAddresses = InetAddress .getAllByName(getString(R.string.tf_default_ionline_server)); masterClusterIP = clusterInetAddresses[new Random().nextInt(clusterInetAddresses.length)] .getHostAddress(); } catch (UnknownHostException e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to lookup master cluster IP addresses: " + e.toString()); e.printStackTrace(); } // Create local instance of database boolean dbCreated = false; // User may not have connected to local database yet - start up the connection for them try { if (mLocalDbInstance == null) { connectToLocalServer(); } } catch (DbUnavailableException e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "cannot connect to local database server"); e.printStackTrace(); } if (mLocalDbInstance.getAllDatabases().indexOf("db_" + db) == -1) { switch (mode) { case REPLICATE_PULL: if (Collect.Log.INFO) Log.i(Collect.LOGTAG, tt + "creating local database " + db); mLocalDbInstance.createDatabase("db_" + db); dbCreated = true; break; case REPLICATE_PUSH: // If the database does not exist client side then there is no point in continuing if (Collect.Log.WARN) Log.w(Collect.LOGTAG, tt + "cannot find local database " + db + " to push"); return null; } } // Configure replication direction String source = null; String target = null; String deviceId = Collect.getInstance().getInformOnlineState().getDeviceId(); String deviceKey = Collect.getInstance().getInformOnlineState().getDeviceKey(); String localServer = "http://" + mLocalHost + ":" + mLocalPort + "/db_" + db; String remoteServer = "http://" + deviceId + ":" + deviceKey + "@" + masterClusterIP + ":5984/db_" + db; // Should we use encrypted transfers? SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(Collect.getInstance().getBaseContext()); if (settings.getBoolean(PreferencesActivity.KEY_ENCRYPT_SYNCHRONIZATION, true)) { remoteServer = "https://" + deviceId + ":" + deviceKey + "@" + masterClusterIP + ":6984/db_" + db; } switch (mode) { case REPLICATE_PUSH: source = localServer; target = remoteServer; break; case REPLICATE_PULL: source = remoteServer; target = localServer; break; } ReplicationCommand cmd = new ReplicationCommand.Builder().source(source).target(target).build(); ReplicationStatus status = null; try { status = mLocalDbInstance.replicate(cmd); } catch (Exception e) { // Remove a recently created DB if the replication failed if (dbCreated) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, t + "replication exception: " + e.toString()); e.printStackTrace(); mLocalDbInstance.deleteDatabase("db_" + db); } } return status; }
From source file:edu.uci.ics.asterix.aoya.AsterixApplicationMaster.java
/** * Start the AM and request all necessary resources. * /*from www . ja v a 2 s . c o m*/ * @return True if the run fully succeeded, false otherwise. * @throws YarnException * @throws IOException */ public boolean run() throws YarnException, IOException { LOG.info("Starting ApplicationMaster"); AMRMClientAsync.CallbackHandler allocListener = new RMCallbackHandler(); resourceManager = AMRMClientAsync.createAMRMClientAsync(1000, allocListener); resourceManager.init(conf); resourceManager.start(); containerListener = new NMCallbackHandler(); nmClientAsync = new NMClientAsyncImpl(containerListener); nmClientAsync.init(conf); nmClientAsync.start(); // Register self with ResourceManager // This will start heartbeating to the RM try { appMasterHostname = InetAddress.getLocalHost().toString(); } catch (java.net.UnknownHostException uhe) { appMasterHostname = uhe.toString(); } RegisterApplicationMasterResponse response = resourceManager.registerApplicationMaster(appMasterHostname, appMasterRpcPort, appMasterTrackingUrl); // Dump out information about cluster capability as seen by the // resource manager int maxMem = response.getMaximumResourceCapability().getMemory(); LOG.info("Max mem capabililty of resources in this cluster " + maxMem); try { requestResources(clusterDesc); } catch (YarnException e) { LOG.error("Could not allocate resources properly:" + e.getMessage()); done = true; throw e; } //now we just sit and listen for messages from the RM while (!done) { try { Thread.sleep(200); } catch (InterruptedException ex) { } } finish(); return success; }
From source file:org.lockss.servlet.LockssServlet.java
protected String getLocalIPAddr() { if (localAddr == null) { try {//from w w w . j a va 2 s .c o m IPAddr localHost = IPAddr.getLocalHost(); localAddr = localHost.getHostAddress(); } catch (UnknownHostException e) { // shouldn't happen log.error("LockssServlet: getLocalHost: " + e.toString()); return "???"; } } return localAddr; }
From source file:com.untangle.app.license.LicenseManagerImpl.java
/** * For the specified applicaton, attempt to get a trial license. * /* w ww . ja v a 2 s .c o m*/ * @param appName Application name to request. * @throws Exception Throw excepton based on inability or general errors conecting license server. */ @Override public void requestTrialLicense(String appName) throws Exception { if (appName == null) { logger.warn("Invalid name: " + appName); return; } // if already have a valid license, just return if (UvmContextFactory.context().licenseManager().isLicenseValid(appName)) { logger.warn("Already have a valid license for: " + appName); return; } String licenseUrl = System.getProperty("uvm.license.url"); if (licenseUrl == null) licenseUrl = "https://license.untangle.com/license.php"; /** * The API specifies libitem, however libitems no longer exist * First we try with the actual name, then the libitem time * Then we try with the old app name (if it has an old name), then we try with the old libitem name * We do all these different calls so that the product supports any version of the license server */ String libitemName = "untangle-libitem-" + appName; String urlStr = licenseUrl + "?action=startTrial" + "&node=" + appName + "&" + getServerParams(); String urlStr2 = licenseUrl + "?action=startTrial" + "&libitem=" + libitemName + "&" + getServerParams(); String oldName = null; String urlStr3 = null; String urlStr4 = null; switch (appName) { case License.DIRECTORY_CONNECTOR: oldName = DIRECTORY_CONNECTOR_OLDNAME; break; case License.BANDWIDTH_CONTROL: oldName = BANDWIDTH_CONTROL_OLDNAME; break; case License.CONFIGURATION_BACKUP: oldName = CONFIGURATION_BACKUP_OLDNAME; break; case License.BRANDING_MANAGER: oldName = BRANDING_MANAGER_OLDNAME; break; case License.VIRUS_BLOCKER: oldName = VIRUS_BLOCKER_OLDNAME; break; case License.SPAM_BLOCKER: oldName = SPAM_BLOCKER_OLDNAME; break; case License.WAN_FAILOVER: oldName = WAN_FAILOVER_OLDNAME; break; case License.IPSEC_VPN: oldName = IPSEC_VPN_OLDNAME; break; case License.POLICY_MANAGER: oldName = POLICY_MANAGER_OLDNAME; break; case License.WEB_FILTER: oldName = WEB_FILTER_OLDNAME; break; case License.WAN_BALANCER: oldName = WAN_BALANCER_OLDNAME; break; case License.WEB_CACHE: oldName = WEB_CACHE_OLDNAME; break; case License.APPLICATION_CONTROL: oldName = APPLICATION_CONTROL_OLDNAME; break; case License.SSL_INSPECTOR: oldName = SSL_INSPECTOR_OLDNAME; break; case License.LIVE_SUPPORT: oldName = LIVE_SUPPORT_OLDNAME; break; } if (oldName != null) { String oldLibitemName = "untangle-libitem-" + oldName; urlStr3 = licenseUrl + "?action=startTrial" + "&node=" + oldName + "&" + getServerParams(); urlStr4 = licenseUrl + "?action=startTrial" + "&libitem=" + oldLibitemName + "&" + getServerParams(); } CloseableHttpClient httpClient = HttpClients.custom().build(); CloseableHttpResponse response = null; HttpGet get; URL url; try { logger.info("Requesting Trial: " + urlStr); url = new URL(urlStr); get = new HttpGet(url.toString()); response = httpClient.execute(get); if (response != null) { response.close(); response = null; } if (urlStr2 != null) { logger.info("Requesting Trial: " + urlStr2); url = new URL(urlStr2); get = new HttpGet(url.toString()); response = httpClient.execute(get); if (response != null) { response.close(); response = null; } } if (urlStr3 != null) { logger.info("Requesting Trial: " + urlStr3); url = new URL(urlStr3); get = new HttpGet(url.toString()); response = httpClient.execute(get); if (response != null) { response.close(); response = null; } } if (urlStr4 != null) { logger.info("Requesting Trial: " + urlStr4); url = new URL(urlStr4); get = new HttpGet(url.toString()); response = httpClient.execute(get); if (response != null) { response.close(); response = null; } } } catch (java.net.UnknownHostException e) { logger.warn("Exception requesting trial license:" + e.toString()); throw (new Exception("Unable to fetch trial license: DNS lookup failed.", e)); } catch (java.net.ConnectException e) { logger.warn("Exception requesting trial license:" + e.toString()); throw (new Exception("Unable to fetch trial license: Connection timeout.", e)); } catch (Exception e) { logger.warn("Exception requesting trial license:" + e.toString()); throw (new Exception("Unable to fetch trial license: " + e.toString(), e)); } finally { try { if (response != null) response.close(); } catch (Exception e) { logger.warn("close", e); } try { httpClient.close(); } catch (Exception e) { logger.warn("close", e); } } // blocking call because we need the new trial license UvmContextFactory.context().licenseManager().reloadLicenses(true); }
From source file:org.openspaces.pu.container.servicegrid.deploy.Deploy.java
private boolean isOnGsmHost() throws UnknownHostException, RemoteException { InetAddress localHost = InetAddress.getLocalHost(); InetAddress gsmHostByName = null; InetAddress gsmHostByAddress = null; try {/*from www.j av a 2 s.c o m*/ gsmHostByName = InetAddress.getByName(gsm.getOSDetails().getHostName()); } catch (UnknownHostException e1) { try { gsmHostByAddress = InetAddress.getByName(gsm.getOSDetails().getHostAddress()); } catch (UnknownHostException e2) { throw new UnknownHostException("failed to resolve host by name (" + gsm.getOSDetails().getHostName() + ") - caused by " + e1 + "; failed to resolve host by address (" + gsm.getOSDetails().getHostAddress() + ") - caused by " + e2.toString()); } } if (logger.isDebugEnabled()) { logger.debug("local host: " + localHost + " GSM host-by-name: " + gsmHostByName + " host-by-address: " + gsmHostByAddress); } return localHost.equals(gsmHostByName) || localHost.equals(gsmHostByAddress); }
From source file:org.commoncrawl.service.crawler.HttpFetcher.java
private boolean fillSlot(int index, CrawlTarget optionalTarget) { // dont fill slot in paused state ... if (!isPaused() || optionalTarget != null) { if (_active[index] != null) { LOG.error("fill Slot Called on Non-Empty Slot:" + index + " With URL:" + _active[index].getURL()); }// ww w.j av a2 s .c o m // if there are pending urls ... if (optionalTarget != null || _pending.size() != 0) { // pop a url off of the queue ... or use the optionally passed in target CrawlTarget crawlTarget = (optionalTarget != null) ? optionalTarget : _pending.removeFirst(); try { URL fetchURL = new URL(crawlTarget.getActiveURL()); URL originalURL = (crawlTarget.getRedirectCount() == 0) ? fetchURL : new URL(crawlTarget.getOriginalURL()); // open a new connection and assign it to the available slot ... if (_crawlInterfaces != null) { _active[index] = new NIOHttpConnection(fetchURL, _crawlInterfaces[getCrawlInterfaceForCrawlTarget(crawlTarget)], _selector, _resolver, crawlTarget.getCookieStore()); } else { _active[index] = new NIOHttpConnection(fetchURL, _selector, _resolver, crawlTarget.getCookieStore()); } // LOG.info("### FETCHER Alloc HTTPConnect to:" + fetchURL + " Slot:" + index); //TODO: MAJOR HACK // disable proxy requests for robots if ((crawlTarget.getFlags() & CrawlURL.Flags.IsRobotsURL) == 0) { if (CrawlerServer.getServer().getProxyAddress() != null) { // check to see if we should be using a proxy server _active[index].setProxyServer(CrawlerServer.getServer().getProxyAddress()); } } // add in special source header _active[index].getRequestHeaders().setIfNotSet("x-cc-id", _crawlerName); // add in cache tests if present if (crawlTarget.getRedirectCount() == 0) { if (crawlTarget.getLastModifiedTime() != -1) { _active[index].getRequestHeaders().setIfNotSet("If-Modified-Since", http_date_format.format(new Date(crawlTarget.getLastModifiedTime()))); } if (crawlTarget.getETag() != null) { _active[index].getRequestHeaders().setIfNotSet("If-None-Match", crawlTarget.getETag()); } } _activeVersions[index] = (short) ((_activeVersions[index] + 1) % 10); long currentTime = System.currentTimeMillis(); if (crawlTarget.getRedirectCount() != 0) { String newHost = fetchURL.getHost(); String originalHost = originalURL.getHost(); if (newHost != null && originalHost != null && newHost.equalsIgnoreCase(originalHost)) { crawlTarget.getSourceList().populateIPAddressForTarget(fetchURL.getHost(), crawlTarget); } } // IFF NOT Redirect else { // if the cached ip is still valid based on stored TTL ... if (crawlTarget.getServerIP() != 0 && crawlTarget.getServerIPTTL() >= System.currentTimeMillis()) { // then set the resolved address data members (thus enabling us to bypass dns lookup) _active[index].setResolvedAddress( IPAddressUtils.IntegerToInetAddress(crawlTarget.getServerIP()), crawlTarget.getServerIPTTL(), null); } else { if (Environment.detailLogEnabled()) { if (crawlTarget.getServerIP() == 0) LOG.info("#### IP Address for Host:" + fetchURL.getHost() + " Not Set. Will require DNS Resolution"); else LOG.info("#### TTL of Cached IP Expired for Host:" + fetchURL.getHost() + ". Will require DNS Resolution"); } } } _active[index].setListener(this); _active[index].setContext(new CrawlContext(crawlTarget, index)); _active[index].setDownloadMax(DOWNLOAD_LIMIT); if (!_failConnections) { _active[index].open(); //LOG.info("### FETCHER called open on connection to:" + fetchURL + " slot:" + index); } else { throw new IOException("Deliberately Skipped Open and FAILED Connection"); } snapShotConnectionCount++; connectionCount++; if (Environment.detailLogEnabled()) LOG.info("Filled SLOT:" + index + " With URL:" + crawlTarget.getActiveURL()); // inform the target of the status change crawlTarget.fetchStarting(_active[index]); // LOG.info("### FETCHER called fetchStarting for:" + fetchURL + " slot:" + index); // log it ... logGET(crawlTarget, index); // and construct the http request ... } catch (UnknownHostException e) { //TODO: CLEAR SLOT BEFORE CALLING fetchFailed!!!! if (_active[index] != null) { _active[index].setContext(null); _active[index].close(); } _active[index] = null; if (Environment.detailLogEnabled()) LOG.error("Maformed URL Exception Processing URL:" + crawlTarget.getActiveURL()); crawlTarget.fetchFailed(CrawlURL.FailureReason.MalformedURL, e.toString()); failureCount++; } catch (MalformedURLException e) { //TODO: CLEAR SLOT BEFORE CALLING fetchFailed!!!! if (_active[index] != null) { _active[index].setContext(null); _active[index].close(); } _active[index] = null; if (Environment.detailLogEnabled()) LOG.error("Maformed URL Exception Processing URL:" + crawlTarget.getActiveURL()); crawlTarget.fetchFailed(CrawlURL.FailureReason.MalformedURL, e.toString()); failureCount++; } catch (IOException e2) { if (Environment.detailLogEnabled()) LOG.error("IOException Processing URL:" + crawlTarget.getActiveURL() + " Details:" + e2.getMessage()); //TODO: WATCH IT!!! - always clear slot FIRST because fetchFailed calls back into fillSlot!!!! if (_active[index] != null) { _active[index].setContext(null); _active[index].close(); } _active[index] = null; // LOG.debug("Fetch FAILED URL:"+ context.getURL().getURL() + " Code:"+ failureCode); // notify url of failure ... //TODO: Investigate if it is SANE!!! to call back into fillSlot from fetchFailed !!! crawlTarget.fetchFailed(CrawlURL.FailureReason.IOException, e2.getMessage()); failureCount++; } catch (Exception e) { LOG.error("Runtime Exception Processing URL:" + crawlTarget.getActiveURL() + " Details:" + e.getMessage()); //TODO: WATCH IT!!! - always clear slot FIRST because fetchFailed calls back into fillSlot!!!! if (_active[index] != null) { _active[index].setContext(null); _active[index].close(); } _active[index] = null; // LOG.debug("Fetch FAILED URL:"+ context.getURL().getURL() + " Code:"+ failureCode); // notify url of failure ... //TODO: Investigate if it is SANE!!! to call back into fillSlot from fetchFailed !!! crawlTarget.fetchFailed(CrawlURL.FailureReason.RuntimeError, e.getMessage()); failureCount++; } } } return _active[index] != null; }
From source file:orca.registry.DatabaseOperations.java
License:asdf
private boolean checkIP(String clientIP, String act_soapaxis2url) { if ((clientIP == null) || (act_soapaxis2url == null)) return false; log.debug("Inside DatabaseOperations: checkIP()"); String[] splitSoapUrl = act_soapaxis2url.split("//"); String noHttp = splitSoapUrl[1]; String[] splitNoHttp = noHttp.split(":"); String ipSoapUrl = splitNoHttp[0]; //System.out.println("ip in input soapUrl = " + ipSoapUrl); String humanReadableIP = null; String numericIP = null;//w w w . j a v a 2 s.co m try { InetAddress address = InetAddress.getByName(ipSoapUrl); //System.out.println("humanreadable IP/numeric IP = " + address.toString()); String[] splitResultGetByName = address.toString().split("/"); humanReadableIP = splitResultGetByName[0]; numericIP = splitResultGetByName[1]; } catch (UnknownHostException ex) { log.error("Error converting IP address: " + ex.toString()); } boolean result = false; if (clientIP.equalsIgnoreCase(numericIP)) { result = true; } else { if (ipSoapUrl.equalsIgnoreCase("localhost")) { // Special check: if the soapaxis url is localhost (implying test deployment) insert it into db result = true; } else { //System.out.println("Can't verify the identity of the client; client IP doesn't match with IP in SOAP-Axis URL of the Actor; It is also not a test deployment"); log.debug( "Can't verify the identity of the client; client IP doesn't match with IP in SOAP-Axis URL of the Actor; It is also not a test deployment"); result = false; } } return result; }