From: jihye kim Date: Tue, 24 Jul 2012 07:14:17 +0000 (+0900) Subject: [Title] print system proxy because of checking state loading map X-Git-Tag: 2.2.1_release^2~81^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f47580437bd27b7615c202d31ae0092cb956dc42;p=sdk%2Femulator%2Feventinjector-eplugin.git [Title] print system proxy because of checking state loading map [Type] work [Module] event injector [Priority] major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/org.tizen.location.map/src/org/tizen/location/map/Map.java b/org.tizen.location.map/src/org/tizen/location/map/Map.java index 9f72cf0..30554d8 100644 --- a/org.tizen.location.map/src/org/tizen/location/map/Map.java +++ b/org.tizen.location.map/src/org/tizen/location/map/Map.java @@ -29,9 +29,9 @@ package org.tizen.location.map; import java.util.ArrayList; -import org.eclipse.core.internal.net.ProxyManager; -import org.eclipse.core.net.proxy.IProxyData; -import org.eclipse.core.net.proxy.IProxyService; +//import org.eclipse.core.internal.net.ProxyManager; +//import org.eclipse.core.net.proxy.IProxyData; +//import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.forms.widgets.Section; @@ -42,20 +42,21 @@ import org.tizen.injector.provider.AbstractInjectorItem; import org.tizen.location.core.model.GeoLocationVO; import org.tizen.location.map.page.MapImage; -@SuppressWarnings("restriction") +//@SuppressWarnings("restriction") public class Map extends AbstractInjectorItem { private static String LABEL = Messages.Map_0; private DefaultTableModel model = new DefaultTableModel(new GeoLocationVO()); private ArrayList viewerList = new ArrayList(); - public static String host = null; - public static int port = -1; + //public static String host = null; + //public static int port = -1; @Override protected void addPages() { - init(); + //init(); addPage(new MapImage(this, Messages.Map_1, model)); } - + + /* private void init() { // Get Preferences - General - Network Connections IProxyService proxyManager = ProxyManager.getProxyManager(); @@ -85,7 +86,7 @@ public class Map extends AbstractInjectorItem { // DebugLog.log("[Activator] proxy initiate...." + System.getProperty("network.proxy_host") + " : " + //$NON-NLS-3$ // System.getProperty("network.proxy_port")); //$NON-NLS-1$ } - + */ public void addViewer(TableViewer viewer){ viewerList.add(viewer); } diff --git a/org.tizen.location.map/src/org/tizen/location/map/page/DebugLog.java b/org.tizen.location.map/src/org/tizen/location/map/page/DebugLog.java new file mode 100644 index 0000000..d162717 --- /dev/null +++ b/org.tizen.location.map/src/org/tizen/location/map/page/DebugLog.java @@ -0,0 +1,123 @@ +/* + * org.tizen.location.core + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Sungmin Ha + * YeongKyoon Lee + * DongKyun Yun + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.location.map.page; + +import java.util.Calendar; +import java.util.logging.FileHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +public class DebugLog { + private static final String LOG_FILE_NAME = "injector.log"; + private static Logger logger; + + static { + synchronized(DebugLog.class) { + init(); + } + } + + private static void init() { + logger = Logger.getLogger("Event Injector"); + logger.setUseParentHandlers(false); + //File logFolder; + Handler logFileHandler; + try { + /* + logFolder = new File(FilePath.getInstance().getTizenVmsArchPath()); + if (!logFolder.exists()) { + logFolder.mkdirs(); + } + */ + logFileHandler = new FileHandler(/*logFolder.getAbsolutePath() + File.separator + */LOG_FILE_NAME); + + logger.setLevel(Level.ALL); + logFileHandler.setLevel(Level.INFO); + + logFileHandler.setFormatter(new LoggerFormatter()); + logger.addHandler(logFileHandler); + } catch (Exception e) { + logger.setLevel(Level.OFF); + e.getMessage(); + } + } + + public static void log(String msg) { + logger.info(msg); + } +} + +class LoggerFormatter extends Formatter { + public String format(LogRecord record) { + StringBuffer sb = new StringBuffer(); + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(record.getMillis()); + + // [YYYY.MM.DD HH:MM:SS][LEVEL][CLASS.METHOD] MESSAGE + sb.append('['); + sb.append(cal.get(Calendar.YEAR)); + sb.append('.'); + sb.append(cal.get(Calendar.MONTH)); + sb.append('.'); + sb.append(cal.get(Calendar.DAY_OF_MONTH)); + sb.append(' '); + sb.append(cal.get(Calendar.HOUR_OF_DAY)); + sb.append(':'); + sb.append(cal.get(Calendar.MINUTE)); + sb.append(':'); + sb.append(cal.get(Calendar.SECOND)); + sb.append(']'); + sb.append('['); + sb.append(record.getLevel()); + sb.append(']'); + sb.append('['); + sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1)); + sb.append('.'); + sb.append(record.getSourceMethodName()); + sb.append("] "); + sb.append(record.getMessage()); + + // in case when called Logger.throwing() + Throwable t = record.getThrown(); + if (t != null) { + StackTraceElement[] stacks = t.getStackTrace(); + sb.append('\n'); + sb.append(t.toString()); + for (int i = 0; i < stacks.length; i++) { + sb.append('\n'); + sb.append(stacks[i].toString()); + } + } + sb.append('\n'); + return sb.toString(); + } +} + 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 7fe49da..7458d47 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 @@ -31,8 +31,13 @@ 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; @@ -66,7 +71,7 @@ import org.tizen.injector.model.ITableVO; import org.tizen.injector.provider.AbstractInjectorItem; import org.tizen.injector.provider.AbstractInjectorPage; //import org.tizen.location.core.injector.AbstractLocationInjector; -import org.tizen.location.core.injector.DebugLog; +//import org.tizen.location.core.injector.DebugLog; import org.tizen.location.core.injector.LocationInjector; import org.tizen.location.core.model.GeoLocationVO; import org.tizen.location.core.protocol.GeoLocation; @@ -109,60 +114,108 @@ public class MapImage extends AbstractInjectorPage { } - private void createGoogleMapScript() { - if(Map.host == null && Map.port == -1) - { - 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; + 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(); } + in.close(); + } - if (!isLoading) { - this.googleMapScript = "



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



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



" + - "
Failed to load the map.
" + e.getMessage() + - "
"; + "
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 { + List l = ProxySelector.getDefault().select(new URI("http://www.google.com/")); + for (Proxy proxy : l ) { + DebugLog.log("proxy hostname : " + proxy.type()); + InetSocketAddress addr = (InetSocketAddress)proxy.address(); + if(addr == null) { + DebugLog.log("no proxy"); + return false; + } else { + host = addr.getHostName(); + port = addr.getPort(); + DebugLog.log("proxy hostname : " + host); + DebugLog.log("proxy port : " + port); + return true; + } + } + } catch (Exception e) { + DebugLog.log("checkProxy() : " + e.getMessage()); + } + return false; + } + + private void createGoogleMapScript() { + if (checkProxy()) { + DebugLog.log("System proxy is used."); + if (checkGoogle()) { + if (host != null) { + System.setProperty("network.proxy_host", host); + if (port != -1) { + System.setProperty("network.proxy_port", "" + port); + } + } + } else { + DebugLog.log("Failure to access the site using system proxy."); + System.setProperty("java.net.useSystemProxies", "false"); + } + } else { + System.setProperty("java.net.useSystemProxies", "false"); + DebugLog.log("System proxy is not used."); + if (!checkGoogle()) { return; } } @@ -228,7 +281,7 @@ public class MapImage extends AbstractInjectorPage { @Override public void completed(ProgressEvent event) { -// DebugLog.log("[Map] Map Loading: Compelete"); + DebugLog.log("[Map] Map Loading: Compelete"); } @Override diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest index d2f0c9f..df0c1d3 100644 --- a/package/pkginfo.manifest +++ b/package/pkginfo.manifest @@ -1,5 +1,5 @@ Source:eventinjector-eplugin -Version:0.2.43 +Version:0.2.44 Maintainer:yeongkyoon Lee , sungmin Ha Package:eventinjector-eplugin