Author: adietish
Date: 2010-08-25 08:45:11 -0400 (Wed, 25 Aug 2010)
New Revision: 24420
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetRequest.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IHttpGetRequest.java
Removed:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageIntegrationTest.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageRequestsTest.java
Log:
[JBIDE-6376] httpGetRequest extracted to interface (shall be replaceable)
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java 2010-08-25
12:39:11 UTC (rev 24419)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.text.MessageFormat;
-
-
-/**
- * Class that executes a HTTP Get request to the given url.
- *
- * @author Andre Dietisheim
- */
-public class HttpGetMethod {
-
- private static final String USER_AGENT = "User-Agent"; //$NON-NLS-1$
-
- private static final String GET_METHOD_NAME = "GET"; //$NON-NLS-1$
-
- private ILoggingAdapter loggingAdapter = null;
-
-// private CookieHandler cookieHandler;
-
- private String userAgent;
-
- public HttpGetMethod(String userAgent, ILoggingAdapter loggingAdapter) {
- this.userAgent = userAgent;
- this.loggingAdapter = loggingAdapter;
-// this.cookieHandler = new CookieHandler();
-// this.cookieHandler = CookieHandler.getDefault();
-// cookieHandler.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
- }
-
- public void request(String urlString) {
-
-// CookieHandler currentCookieHandler = setCookieHandler(cookieHandler);
- try {
- HttpURLConnection urlConnection = createURLConnection(urlString, userAgent);
- urlConnection.connect();
- int responseCode = getResponseCode(urlConnection);
- if (responseCode == HttpURLConnection.HTTP_OK) {
- loggingAdapter.logMessage(MessageFormat.format(UsageMessages.HttpGetMethod_Success,
urlString, responseCode));
- } else {
- loggingAdapter.logError(MessageFormat.format(UsageMessages.HttpGetMethod_Error_Http,
urlString));
- }
- } catch (Exception e) {
- loggingAdapter.logMessage(MessageFormat.format(UsageMessages.HttpGetMethod_Error_Io,
urlString, e.toString()));
- } finally {
-// setCookieHandler(currentCookieHandler);
- }
- }
-
- /**
- * Returns the return code from the given {@link HttpURLConnection}.
- * Provided to be called by test cases so that they can retrieve the return code.
- *
- * @param urlConnection to get the response code from
- * @return the return code the HttpUrlConnection received
- * @throws IOException Signals that an I/O exception has occurred.
- */
- protected int getResponseCode(HttpURLConnection urlConnection) throws IOException {
- return urlConnection.getResponseCode();
- }
-
-// private CookieHandler setCookieHandler(CookieHandler cookieHandler) {
-// CookieHandler currentCookieHandler = CookieHandler.getDefault();
-// CookieHandler.setDefault(cookieHandler);
-// return currentCookieHandler;
-// }
-
- /**
- * Creates a new url connection.
- *
- * @param urlString the url string
- * @param userAgent the user agent
- * @return the http url connection
- * @throws IOException Signals that an I/O exception has occurred.
- */
- protected HttpURLConnection createURLConnection(String urlString, String userAgent)
throws IOException {
- URL url = new URL(urlString);
- HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
- urlConnection.setInstanceFollowRedirects(true);
- urlConnection.setRequestMethod(GET_METHOD_NAME);
- urlConnection.setRequestProperty(USER_AGENT, userAgent);
- return urlConnection;
- }
-}
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetRequest.java
(from rev 24374,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetRequest.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetRequest.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.MessageFormat;
+
+
+/**
+ * Class that executes a HTTP Get request to the given url.
+ *
+ * @author Andre Dietisheim
+ */
+public class HttpGetRequest implements IHttpGetRequest {
+
+ private static final String USER_AGENT = "User-Agent"; //$NON-NLS-1$
+
+ private static final String GET_METHOD_NAME = "GET"; //$NON-NLS-1$
+
+ private ILoggingAdapter loggingAdapter = null;
+
+// private CookieHandler cookieHandler;
+
+ private String userAgent;
+
+ public HttpGetRequest(String userAgent, ILoggingAdapter loggingAdapter) {
+ this.userAgent = userAgent;
+ this.loggingAdapter = loggingAdapter;
+// this.cookieHandler = new CookieHandler();
+// this.cookieHandler = CookieHandler.getDefault();
+// cookieHandler.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.usage.IHttpGetRequest#request(java.lang.String)
+ */
+ public void request(String urlString) {
+
+// CookieHandler currentCookieHandler = setCookieHandler(cookieHandler);
+ try {
+ HttpURLConnection urlConnection = createURLConnection(urlString, userAgent);
+ urlConnection.connect();
+ int responseCode = getResponseCode(urlConnection);
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ loggingAdapter.logMessage(MessageFormat.format(UsageMessages.HttpGetMethod_Success,
urlString, responseCode));
+ } else {
+ loggingAdapter.logError(MessageFormat.format(UsageMessages.HttpGetMethod_Error_Http,
urlString));
+ }
+ } catch (Exception e) {
+ loggingAdapter.logMessage(MessageFormat.format(UsageMessages.HttpGetMethod_Error_Io,
urlString, e.toString()));
+ } finally {
+// setCookieHandler(currentCookieHandler);
+ }
+ }
+
+ /**
+ * Returns the return code from the given {@link HttpURLConnection}.
+ * Provided to be called by test cases so that they can retrieve the return code.
+ *
+ * @param urlConnection to get the response code from
+ * @return the return code the HttpUrlConnection received
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ protected int getResponseCode(HttpURLConnection urlConnection) throws IOException {
+ return urlConnection.getResponseCode();
+ }
+
+// private CookieHandler setCookieHandler(CookieHandler cookieHandler) {
+// CookieHandler currentCookieHandler = CookieHandler.getDefault();
+// CookieHandler.setDefault(cookieHandler);
+// return currentCookieHandler;
+// }
+
+ /**
+ * Creates a new url connection.
+ *
+ * @param urlString the url string
+ * @param userAgent the user agent
+ * @return the http url connection
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ protected HttpURLConnection createURLConnection(String urlString, String userAgent)
throws IOException {
+ URL url = new URL(urlString);
+ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setInstanceFollowRedirects(true);
+ urlConnection.setRequestMethod(GET_METHOD_NAME);
+ urlConnection.setRequestProperty(USER_AGENT, userAgent);
+ return urlConnection;
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IHttpGetRequest.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IHttpGetRequest.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IHttpGetRequest.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage;
+
+/**
+ * A interface that represents a HTTP Get Request.
+ *
+ * @author Andre Dietisheim
+ */
+public interface IHttpGetRequest {
+
+ public abstract void request(String urlString);
+
+}
\ No newline at end of file
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IHttpGetRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java 2010-08-25
12:39:11 UTC (rev 24419)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -24,11 +24,11 @@
public class Tracker implements ITracker {
private IURLBuildingStrategy urlBuildingStrategy = null;
- private HttpGetMethod httpRequest;
+ private IHttpGetRequest httpRequest;
private ILoggingAdapter loggingAdapter;
- public Tracker(IURLBuildingStrategy urlBuildingStrategy, String userAgent,
ILoggingAdapter loggingAdapter) {
- this.httpRequest = new HttpGetMethod(userAgent, loggingAdapter);
+ public Tracker(IURLBuildingStrategy urlBuildingStrategy, IHttpGetRequest httpGetRequest,
ILoggingAdapter loggingAdapter) {
+ this.httpRequest = httpGetRequest;
this.loggingAdapter = loggingAdapter;
this.urlBuildingStrategy = urlBuildingStrategy;
}
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java 2010-08-25
12:39:11 UTC (rev 24419)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -14,6 +14,8 @@
import org.eclipse.jface.window.Window;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.usage.FocusPoint;
+import org.jboss.tools.usage.HttpGetRequest;
+import org.jboss.tools.usage.IHttpGetRequest;
import org.jboss.tools.usage.ILoggingAdapter;
import org.jboss.tools.usage.ITracker;
import org.jboss.tools.usage.IURLBuildingStrategy;
@@ -76,13 +78,14 @@
}
private ITracker getTracker() {
- IGoogleAnalyticsParameters eclipseSettings = new EclipseEnvironment(
+ IGoogleAnalyticsParameters eclipseEnvironment = new EclipseEnvironment(
GANALYTICS_ACCOUNTNAME
, HOST_NAME
, IGoogleAnalyticsParameters.VALUE_NO_REFERRAL
, PreferencesUtils.getPreferences());
ILoggingAdapter loggingAdapter = new
PluginLogger(JBossToolsUsageActivator.getDefault());
- IURLBuildingStrategy urlStrategy = new GoogleAnalyticsUrlStrategy(eclipseSettings);
- return new Tracker(urlStrategy, eclipseSettings.getUserAgent(), loggingAdapter);
+ IURLBuildingStrategy urlStrategy = new GoogleAnalyticsUrlStrategy(eclipseEnvironment);
+ IHttpGetRequest httpGetRequest = new HttpGetRequest(eclipseEnvironment.getUserAgent(),
loggingAdapter);
+ return new Tracker(urlStrategy, httpGetRequest, loggingAdapter);
}
}
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageIntegrationTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageIntegrationTest.java 2010-08-25
12:39:11 UTC (rev 24419)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageIntegrationTest.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -21,6 +21,8 @@
import org.eclipse.core.runtime.Platform;
import org.jboss.tools.usage.FocusPoint;
+import org.jboss.tools.usage.HttpGetRequest;
+import org.jboss.tools.usage.IHttpGetRequest;
import org.jboss.tools.usage.ILoggingAdapter;
import org.jboss.tools.usage.IURLBuildingStrategy;
import org.jboss.tools.usage.PluginLogger;
@@ -44,7 +46,7 @@
@Test
public void sameUserIdOnSametEclipseInstance() throws Exception {
UrlRevealingTracker tracker = getTracker(getEclipseEnvironmentInstance());
- FocusPoint focusPoint =
createFocusPoint("testSameUserIdOnSametEclipseInstance" +
System.currentTimeMillis());
+ FocusPoint focusPoint =
createFocusPoint("/testSameUserIdOnSametEclipseInstance" +
System.currentTimeMillis());
tracker.trackSynchronously(focusPoint);
String userId = getUserId(tracker.getTrackingUrl());
assertTrue(userId != null);
@@ -65,7 +67,7 @@
assertTrue(userId != null);
tracker = getTracker(createEclipseEnvironment());
- FocusPoint focusPoint =
createFocusPoint("testDifferentUserIdOnDifferentEclipseInstance"
+ FocusPoint focusPoint =
createFocusPoint("/testDifferentUserIdOnDifferentEclipseInstance"
+ System.currentTimeMillis());
tracker.trackSynchronously(focusPoint);
String newUserId = getUserId(tracker.getTrackingUrl());
@@ -88,7 +90,8 @@
private UrlRevealingTracker getTracker(IGoogleAnalyticsParameters environment) {
ILoggingAdapter loggingAdapter = new
PluginLogger(JBossToolsUsageTestActivator.getDefault());
IURLBuildingStrategy urlStrategy = new GoogleAnalyticsUrlStrategy(environment);
- return new UrlRevealingTracker(urlStrategy, environment.getUserAgent(),
loggingAdapter);
+ IHttpGetRequest httpGetRequest = new HttpGetRequest(environment.getUserAgent(),
loggingAdapter);
+ return new UrlRevealingTracker(urlStrategy, httpGetRequest, loggingAdapter);
}
private IGoogleAnalyticsParameters getEclipseEnvironmentInstance() {
@@ -119,16 +122,21 @@
private String trackingUrl;
private Lock lock;
- public UrlRevealingTracker(IURLBuildingStrategy urlBuildingStrategy, String userAgent,
+ public UrlRevealingTracker(IURLBuildingStrategy urlBuildingStrategy, IHttpGetRequest
httpGetRequest,
ILoggingAdapter loggingAdapter) {
- super(urlBuildingStrategy, userAgent, loggingAdapter);
+ super(urlBuildingStrategy, httpGetRequest, loggingAdapter);
lock = new ReentrantLock();
}
@Override
public void trackAsynchronously(FocusPoint focusPoint) {
- lock.lock();
- super.trackAsynchronously(focusPoint);
+ try {
+ lock.lock();
+ super.trackAsynchronously(focusPoint);
+ } catch (Exception e) {
+ lock.unlock();
+ throw new RuntimeException(e);
+ }
}
@Override
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageRequestsTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageRequestsTest.java 2010-08-25
12:39:11 UTC (rev 24419)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/JBossToolsUsageRequestsTest.java 2010-08-25
12:45:11 UTC (rev 24420)
@@ -14,7 +14,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
-import org.jboss.tools.usage.HttpGetMethod;
+import org.jboss.tools.usage.HttpGetRequest;
import org.jboss.tools.usage.ILoggingAdapter;
import org.junit.Before;
import org.junit.Ignore;
@@ -802,7 +802,7 @@
assertEquals(HttpURLConnection.HTTP_OK, method.getResponseCode());
}
- protected class TestHttpGetMethod extends HttpGetMethod {
+ protected class TestHttpGetMethod extends HttpGetRequest {
private HttpURLConnection urlConnection;