From 1f504af23cf5587f1b626f261f1ddfbc510f71ae Mon Sep 17 00:00:00 2001 From: jihye kim Date: Thu, 9 Aug 2012 23:11:23 +0900 Subject: [PATCH] [Title] add time out when checking network connection [Type] bug fix [Module] event injector [Priority] major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- .../tizen/location/map/page/CheckNetThread.java | 91 ++++++++++++++++++++++ .../src/org/tizen/location/map/page/MapImage.java | 91 +++++++--------------- package/pkginfo.manifest | 2 +- 3 files changed, 118 insertions(+), 66 deletions(-) create mode 100644 org.tizen.location.map/src/org/tizen/location/map/page/CheckNetThread.java diff --git a/org.tizen.location.map/src/org/tizen/location/map/page/CheckNetThread.java b/org.tizen.location.map/src/org/tizen/location/map/page/CheckNetThread.java new file mode 100644 index 0000000..b25c3b9 --- /dev/null +++ b/org.tizen.location.map/src/org/tizen/location/map/page/CheckNetThread.java @@ -0,0 +1,91 @@ +package org.tizen.location.map.page; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.UnknownHostException; + +public class CheckNetThread extends Thread { + private boolean isError = true; + private String errorMsg = "



" + + "
Failed to load the map (throw time out ...)
Please check the network status!
";; + + private boolean checkGoogle() { + try { + //make a URL to a known source + URL url = new URL("http://slp-info.sec.samsung.net"); + + //open a connection to that source + HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection(); + //trying to retrieve data from the source. If there + //is no connection, this line will fail + urlConnect.connect(); + boolean isLoading = false; + if (urlConnect.getResponseCode() != -1) { + // parsing title + BufferedReader in = new BufferedReader (new InputStreamReader(urlConnect.getInputStream())); + String line; + String pre = ""; + String tail = ""; + + boolean isNextLine = false; + while((line = in.readLine()) != null) { + if (line.contains(pre) || isNextLine) { + if (line.contains("google")) { + isLoading = true; + } + if (!isLoading && !line.contains(tail)) { + isNextLine = true; + continue; + } + break; + } + } + in.close(); + } + + if (!isLoading) { + errorMsg = "



" + + "
Failed to load the map.
Please check the network status!
"; + return false; + } + urlConnect.disconnect(); + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + errorMsg = "



Can't connect to network.
"; + return false; + } + catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + errorMsg = "



" + + "
Failed to load the map.
" + e.getMessage() + + "
"; + return false; + } + + return true; + } + + public void run() { + if (!checkGoogle()) { + isError = true; + } else { + isError = false; + } + synchronized(this) { + notifyAll(); + } + } + + public boolean isError() { + return isError; + } + + public String getErrorMsg() { + return errorMsg; + } +} diff --git a/org.tizen.location.map/src/org/tizen/location/map/page/MapImage.java b/org.tizen.location.map/src/org/tizen/location/map/page/MapImage.java index 9ba624e..2f92ed5 100644 --- a/org.tizen.location.map/src/org/tizen/location/map/page/MapImage.java +++ b/org.tizen.location.map/src/org/tizen/location/map/page/MapImage.java @@ -27,16 +27,11 @@ package org.tizen.location.map.page; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; import java.net.URI; -import java.net.URL; -import java.net.UnknownHostException; import java.util.List; //import java.util.ArrayList; //import java.util.List; @@ -114,66 +109,9 @@ public class MapImage extends AbstractInjectorPage { } - private boolean checkGoogle() { - try { - //make a URL to a known source - URL url = new URL("http://www.google.com"); - - //open a connection to that source - HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection(); - //trying to retrieve data from the source. If there - //is no connection, this line will fail - urlConnect.connect(); - boolean isLoading = false; - if (urlConnect.getResponseCode() != -1) { - // parsing title - BufferedReader in = new BufferedReader (new InputStreamReader(urlConnect.getInputStream())); - String line; - String pre = ""; - String tail = ""; - - boolean isNextLine = false; - while((line = in.readLine()) != null) { - if (line.contains(pre) || isNextLine) { - if (line.contains("google")) { - isLoading = true; - } - if (!isLoading && !line.contains(tail)) { - isNextLine = true; - continue; - } - break; - } - } - in.close(); - } - - if (!isLoading) { - this.googleMapScript = "



" + - "
Failed to load the map.
Please check the network status!
"; - return false; - } - urlConnect.disconnect(); - } catch (UnknownHostException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - this.googleMapScript = "



Can't connect to network.
"; - return false; - } - catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - this.googleMapScript = "



" + - "
Failed to load the map.
" + e.getMessage() + - "
"; - return false; - } - - return true; - } - private String host = null; private int port = -1; + private boolean checkProxy() { System.setProperty("java.net.useSystemProxies","true"); try { @@ -199,9 +137,20 @@ public class MapImage extends AbstractInjectorPage { } private void createGoogleMapScript() { + CheckNetThread checkThread = new CheckNetThread(); + if (checkProxy()) { DebugLog.log("System proxy is used."); - if (checkGoogle()) { + checkThread.start(); + synchronized(checkThread) { + try { + checkThread.wait(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if (!checkThread.isError()) { if (host != null) { System.setProperty("network.proxy_host", host); if (port != -1) { @@ -210,13 +159,25 @@ public class MapImage extends AbstractInjectorPage { } } else { DebugLog.log("Failure to access the site using system proxy."); + this.googleMapScript = checkThread.getErrorMsg(); //System.setProperty("java.net.useSystemProxies", "false"); return; } } else { System.setProperty("java.net.useSystemProxies", "false"); DebugLog.log("System proxy is not used."); - if (!checkGoogle()) { + checkThread.start(); + synchronized(checkThread) { + try { + checkThread.wait(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if (checkThread.isError()) { + DebugLog.log("Failure to access the site."); + this.googleMapScript = checkThread.getErrorMsg(); return; } } diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest index e9e65ed..990339f 100644 --- a/package/pkginfo.manifest +++ b/package/pkginfo.manifest @@ -1,5 +1,5 @@ Source:eventinjector-eplugin -Version:0.2.52 +Version:0.2.53 Maintainer:yeongkyoon Lee , sungmin Ha Package:eventinjector-eplugin -- 2.7.4