Squashed commit of the following:

commit 566881b695b8bc00e618fe9a9b4c86a8fd563cc1
Author: sboikov <sboi...@gridgain.com>
Date:   Fri Oct 7 13:08:38 2016 +0300

    minor

commit 7fe88a1cb21f794ee55a176ab36d895cbf916528
Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Date:   Thu Oct 6 11:11:24 2016 +0300

    ignite-update-notifier fix after review

    (cherry picked from commit a10d2ff)

commit f2de749f958a3b18dc479f8a5517d7bf9362b933
Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Date:   Tue Oct 4 12:12:08 2016 +0300

    ignite-2079-2 optimize import and change url path

    (cherry picked from commit 830a3cf)

commit 0d1be85ad55b0aa91224690d6c112ae92e8bc0a9
Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Date:   Thu Sep 29 19:54:54 2016 +0300

    update-notifier remove parse xml, now parse like properties

    (cherry picked from commit 9ecaa29)

commit e43bca6fb4528a7fc0dcb804a74fca1c59d7468b
Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Date:   Tue Sep 27 17:07:21 2016 +0300

    remove dom parser

    (cherry picked from commit d1653b2)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/952be8b9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/952be8b9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/952be8b9

Branch: refs/heads/ignite-ssl-hotfix
Commit: 952be8b995050b34379006dd6e739da3fe3b49e3
Parents: e6317e0
Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Authored: Fri Oct 7 15:00:09 2016 +0300
Committer: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com>
Committed: Fri Oct 7 15:00:09 2016 +0300

----------------------------------------------------------------------
 .../processors/cluster/GridUpdateNotifier.java  | 108 ++++---------------
 1 file changed, 21 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/952be8b9/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
index b41bf28..592fdd1 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
@@ -18,13 +18,11 @@
 package org.apache.ignite.internal.processors.cluster;
 
 import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
@@ -32,9 +30,6 @@ import java.net.URLConnection;
 import java.util.Collection;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.atomic.AtomicReference;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSystemProperties;
@@ -47,12 +42,6 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.util.worker.GridWorker;
 import org.apache.ignite.plugin.PluginProvider;
 import org.jetbrains.annotations.Nullable;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
 
 import static java.net.URLEncoder.encode;
 
@@ -73,23 +62,20 @@ class GridUpdateNotifier {
     private static final long THROTTLE_PERIOD = 24 * 60 * 60 * 1000; // 1 day.
 
     /** Sleep milliseconds time for worker thread. */
-    public static final int WORKER_THREAD_SLEEP_TIME = 5000;
+    private static final int WORKER_THREAD_SLEEP_TIME = 5000;
+
+    /** Url for request version. */
+    private final static String UPDATE_NOTIFIER_URL = 
"https://ignite.run/update_status_ignite-plain-text.php";;
 
     /** Grid version. */
     private final String ver;
 
-    /** Site. */
-    private final String url;
-
     /** Latest version. */
     private volatile String latestVer;
 
     /** Download url for latest version. */
     private volatile String downloadUrl;
 
-    /** HTML parsing helper. */
-    private final DocumentBuilder documentBuilder;
-
     /** Grid name. */
     private final String gridName;
 
@@ -130,23 +116,7 @@ class GridUpdateNotifier {
     GridUpdateNotifier(String gridName, String ver, GridKernalGateway gw, 
Collection<PluginProvider> pluginProviders,
         boolean reportOnlyNew) throws IgniteCheckedException {
         try {
-            DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
-
-            documentBuilder = factory.newDocumentBuilder();
-
-            documentBuilder.setEntityResolver(new EntityResolver() {
-                @Override public InputSource resolveEntity(String publicId, 
String sysId) {
-                    if (sysId.endsWith(".dtd"))
-                        return new InputSource(new StringReader(""));
-
-                    return null;
-                }
-            });
-
             this.ver = ver;
-
-            url = "http://ignite.run/update_status_ignite.php";;
-
             this.gridName = gridName == null ? "null" : gridName;
             this.gw = gw;
 
@@ -184,9 +154,6 @@ class GridUpdateNotifier {
 
             workerThread.start();
         }
-        catch (ParserConfigurationException e) {
-            throw new IgniteCheckedException("Failed to create xml parser.", 
e);
-        }
         catch (UnsupportedEncodingException e) {
             throw new IgniteCheckedException("Failed to encode.", e);
         }
@@ -346,7 +313,7 @@ class GridUpdateNotifier {
                     (!F.isEmpty(vmProps) ? "&vmProps=" + encode(vmProps, 
CHARSET) : "") +
                         pluginsVers;
 
-                URLConnection conn = new URL(url).openConnection();
+                URLConnection conn = new 
URL(UPDATE_NOTIFIER_URL).openConnection();
 
                 if (!isCancelled()) {
                     conn.setDoOutput(true);
@@ -356,8 +323,6 @@ class GridUpdateNotifier {
                     conn.setConnectTimeout(3000);
                     conn.setReadTimeout(3000);
 
-                    Document dom = null;
-
                     try {
                         try (OutputStream os = conn.getOutputStream()) {
                             os.write(postParams.getBytes(CHARSET));
@@ -369,30 +334,19 @@ class GridUpdateNotifier {
 
                             BufferedReader reader = new BufferedReader(new 
InputStreamReader(in, CHARSET));
 
-                            StringBuilder xml = new StringBuilder();
-
-                            String line;
-
-                            while ((line = reader.readLine()) != null) {
-                                if (line.contains("<meta") && 
!line.contains("/>"))
-                                    line = line.replace(">", "/>");
-
-                                xml.append(line).append('\n');
+                            for (String line; (line = reader.readLine()) != 
null; ) {
+                                if (line.contains("version"))
+                                    latestVer = obtainVersionFrom(line);
+                                else if (line.contains("downloadUrl"))
+                                    downloadUrl = obtainDownloadUrlFrom(line);
                             }
 
-                            dom = documentBuilder.parse(new 
ByteArrayInputStream(xml.toString().getBytes(CHARSET)));
                         }
                     }
                     catch (IOException e) {
                         if (log.isDebugEnabled())
                             log.debug("Failed to connect to Ignite update 
server. " + e.getMessage());
                     }
-
-                    if (dom != null) {
-                        latestVer = obtainVersionFrom(dom);
-
-                        downloadUrl = obtainDownloadUrlFrom(dom);
-                    }
                 }
             }
             catch (Exception e) {
@@ -404,55 +358,35 @@ class GridUpdateNotifier {
         /**
          * Gets the version from the current {@code node}, if one exists.
          *
-         * @param node W3C DOM node.
+         * @param  line Line which contains value for extract.
+         * @param  metaName Name for extract.
          * @return Version or {@code null} if one's not found.
          */
-        @Nullable private String obtainMeta(String metaName, Node node) {
-            assert node != null;
-
-            if (node instanceof Element && 
"meta".equals(node.getNodeName().toLowerCase())) {
-                Element meta = (Element)node;
-
-                String name = meta.getAttribute("name");
-
-                if (metaName.equals(name)) {
-                    String content = meta.getAttribute("content");
+        @Nullable private String obtainMeta(String metaName, String line) {
+            assert line.contains(metaName);
 
-                    if (content != null && !content.isEmpty())
-                        return content;
-                }
-            }
-
-            NodeList childNodes = node.getChildNodes();
-
-            for (int i = 0; i < childNodes.getLength(); i++) {
-                String ver = obtainMeta(metaName, childNodes.item(i));
+            return line.substring(line.indexOf(metaName) + 
metaName.length()).trim();
 
-                if (ver != null)
-                    return ver;
-            }
-
-            return null;
         }
 
         /**
          * Gets the version from the current {@code node}, if one exists.
          *
-         * @param node W3C DOM node.
+         * @param  line Line which contains value for extract.
          * @return Version or {@code null} if one's not found.
          */
-        @Nullable private String obtainVersionFrom(Node node) {
-            return obtainMeta("version", node);
+        @Nullable private String obtainVersionFrom(String line) {
+            return obtainMeta("version=", line);
         }
 
         /**
          * Gets the download url from the current {@code node}, if one exists.
          *
-         * @param node W3C DOM node.
+         * @param line Which contains value for extract.
          * @return download url or {@code null} if one's not found.
          */
-        @Nullable private String obtainDownloadUrlFrom(Node node) {
-            return obtainMeta("downloadUrl", node);
+        @Nullable private String obtainDownloadUrlFrom(String line) {
+            return obtainMeta("downloadUrl=", line);
         }
     }
 }

Reply via email to