tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1239221 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util: IO.java UpdateChecker.java
Date Wed, 01 Feb 2012 17:35:13 GMT
Author: rmannibucau
Date: Wed Feb  1 17:35:12 2012
New Revision: 1239221

URL: http://svn.apache.org/viewvc?rev=1239221&view=rev
Log:
some enhancement about update checker

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/IO.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/IO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/IO.java?rev=1239221&r1=1239220&r2=1239221&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/IO.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/IO.java
Wed Feb  1 17:35:12 2012
@@ -33,6 +33,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.zip.ZipInputStream;
@@ -44,20 +47,30 @@ import java.util.zip.ZipOutputStream;
 public class IO {
     private static final int MAX_TIMEOUT = Integer.getInteger("openejb.io.util.timeout",
5000);
 
-    public static String readFileAsString(final URL url) throws IOException {
-        final URLConnection connection = url.openConnection();
-        connection.setConnectTimeout(MAX_TIMEOUT);
-        final InputStream in = connection.getInputStream();
+    public static String readFileAsString(final URI uri) throws IOException {
         final StringBuilder builder = new StringBuilder("");
-        String line;
-        try {
-            final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-            while ((line = reader.readLine()) != null) {
-                builder.append(line);
+        for (Proxy proxy : ProxySelector.getDefault().select(uri)) {
+            InputStream is;
+
+            try {
+                URLConnection urlConnection = uri.toURL().openConnection(proxy);
+                urlConnection.setConnectTimeout(MAX_TIMEOUT);
+                is = urlConnection.getInputStream();
+            } catch (IOException e) {
+                continue;
+            }
+
+            String line;
+            try {
+                final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+                while ((line = reader.readLine()) != null) {
+                    builder.append(line);
+                }
+            } finally {
+                close(is);
             }
-        } finally {
-            close(in);
         }
+
         return builder.toString();
     }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java?rev=1239221&r1=1239220&r2=1239221&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
Wed Feb  1 17:35:12 2012
@@ -24,7 +24,7 @@ public class UpdateChecker implements Ru
 
         try {
             final URL url = new URL(URL);
-            final String metaData = IO.readFileAsString(url);
+            final String metaData = IO.readFileAsString(url.toURI());
             final String latest = extractLatest(metaData);
             RESULT.set(message(latest, OpenEjbVersion.get().getVersion()));
         } catch (Exception e) {
@@ -42,8 +42,8 @@ public class UpdateChecker implements Ru
             return "running on the latest version";
         }
         return new StringBuilder("current version => ").append(version)
-                .append(", latest stable version ").append(latest).append(" is available
")
-                .append(" on ").append(REPO_URL).toString();
+                .append(", latest stable version ").append(latest)
+                .append(" is available on ").append(REPO_URL).toString();
     }
 
     private static String extractLatest(final String metaData) {



Mime
View raw message