[jboss-svn-commits] JBL Code SVN: r35759 - in labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src: test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 27 04:43:28 EDT 2010


Author: velias
Date: 2010-10-27 04:43:25 -0400 (Wed, 27 Oct 2010)
New Revision: 35759

Added:
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FishEyeCallException.java
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRACallException.java
Modified:
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java
   labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java
Log:
Improved exception handling on JIRA and FISHEYE calls - better messages in exceptions allowing to identify system which call failed

Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java	2010-10-27 07:35:26 UTC (rev 35758)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -1,6 +1,5 @@
 package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -114,7 +113,7 @@
   }
 
   @Override
-  public String[] getValues(FishEyeRepositoryConfig id) throws Exception {
+  public String[] getValues(FishEyeRepositoryConfig id) throws FishEyeCallException {
 
     if (id == null) {
       throw new IllegalArgumentException("FishEyeRepositoryConfig can't be null");
@@ -133,12 +132,16 @@
       int statusCode = client.executeMethod(method);
 
       if (statusCode != HttpStatus.SC_OK) {
-        throw new IOException("FishEye HTTP call failed with http code: " + method.getStatusCode() + " and message: "
+        throw new FishEyeCallException("Http code: " + method.getStatusCode() + " and message: "
             + method.getStatusLine());
       }
 
       return processResponse(method.getResponseBody());
 
+    } catch (FishEyeCallException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new FishEyeCallException(e);
     } finally {
       method.releaseConnection();
     }
@@ -172,18 +175,18 @@
    * 
    * @param responseBody to parse
    * @return values parsed from response
-   * @throws IOException if response is incorrect
+   * @throws FishEyeCallException if response is incorrect
    */
-  protected String[] processResponse(byte[] responseBody) throws IOException {
+  protected String[] processResponse(byte[] responseBody) throws FishEyeCallException {
     if (responseBody == null || responseBody.length == 0) {
-      throw new IOException("FishEye HTTP call failed: empty response");
+      throw new FishEyeCallException("Empty response");
     }
 
     String retsponse = (new String(responseBody)).trim();
     String[] responseParsed = retsponse.split(":");
 
     if (responseParsed.length < 3 || !"ok".equals(responseParsed[0])) {
-      throw new IOException("FishEye HTTP call failed: Bad response: " + retsponse);
+      throw new FishEyeCallException("Bad response (not 'ok' or not enough values): " + retsponse);
     }
 
     String[] retvalue = new String[2];

Added: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FishEyeCallException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FishEyeCallException.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FishEyeCallException.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -0,0 +1,36 @@
+package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
+
+/**
+ * Exception used when FISHEYE call fails.
+ * 
+ * @author Vlastimil Elias (velias at redhat dot com)
+ */
+public class FishEyeCallException extends Exception {
+
+  /**
+   * @param message
+   * @param cause
+   */
+  public FishEyeCallException(String message, Throwable cause) {
+    super(formatMessage(message), cause);
+  }
+
+  /**
+   * @param message
+   */
+  public FishEyeCallException(String message) {
+    super(formatMessage(message));
+  }
+
+  /**
+   * @param cause
+   */
+  public FishEyeCallException(Throwable cause) {
+    super(formatMessage(cause != null ? cause.getMessage() : "Unknown cause"), cause);
+  }
+
+  private static String formatMessage(String message) {
+    return "FISHEYE HTTP call failed: " + (message != null ? message : "");
+  }
+
+}

Added: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRACallException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRACallException.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRACallException.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -0,0 +1,36 @@
+package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
+
+/**
+ * Exception used when JIRA call fails.
+ * 
+ * @author Vlastimil Elias (velias at redhat dot com)
+ */
+public class JIRACallException extends Exception {
+
+  /**
+   * @param message
+   * @param cause
+   */
+  public JIRACallException(String message, Throwable cause) {
+    super(formatMessage(message), cause);
+  }
+
+  /**
+   * @param message
+   */
+  public JIRACallException(String message) {
+    super(formatMessage(message));
+  }
+
+  /**
+   * @param cause
+   */
+  public JIRACallException(Throwable cause) {
+    super(formatMessage(cause != null ? cause.getMessage() : "Unknown cause"), cause);
+  }
+
+  private static String formatMessage(String message) {
+    return "JIRA HTTP call failed: " + (message != null ? message : "");
+  }
+
+}

Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java	2010-10-27 07:35:26 UTC (rev 35758)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -33,9 +33,9 @@
  * System Config parameters used by this value source:
  * <ul>
  * <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.url</code> - String - http/s url to JIRA server where
- * is <a href="https://docspace.corp.redhat.com/docs/DOC-38712#Company_Contributions_Report". Typical value
- * <code>http://jira.jboss.org/secure/ConfigureReport.jspa</code>. target="_blank">"Red Hat Contributors report"
- * plugin</a>.
+ * is <a href="https://docspace.corp.redhat.com/docs/DOC-38712#Company_Contributions_Report"
+ * target="_blank">"Red Hat Contributors report" plugin</a>. Typical value
+ * <code>http://jira.jboss.org/secure/ConfigureReport.jspa</code>.
  * <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.debug</code> - Boolean - if set to <code>true</code> no
  * http/s calls to JIRA are performed, generator returns mock value only (all zero)
  * </ul>
@@ -142,7 +142,7 @@
     return ret;
   }
 
-  protected Map<String, String[]> loadData() throws IOException {
+  protected Map<String, String[]> loadData() throws JIRACallException {
     HttpMethod method = new GetMethod(StringUtils.trimToNull(sysConfig.getStringProperty(CONFIG_KEY_URL)));
     method.setDoAuthentication(false);
     method.setFollowRedirects(true);
@@ -152,12 +152,14 @@
       int statusCode = client.executeMethod(method);
 
       if (statusCode != HttpStatus.SC_OK) {
-        throw new IOException("JIRA HTTP call failed with http code: " + method.getStatusCode() + " and message: "
-            + method.getStatusLine());
+        throw new JIRACallException("Http code: " + method.getStatusCode() + " and message: " + method.getStatusLine());
       }
 
       return processResponse(method.getResponseBody());
-
+    } catch (JIRACallException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new JIRACallException(e);
     } finally {
       method.releaseConnection();
     }
@@ -187,6 +189,13 @@
     return params.toArray(new NameValuePair[] {});
   }
 
+  /**
+   * Generate token for JIRA report call.
+   * 
+   * @param df dateFrom param
+   * @param dt dateTo param
+   * @return token
+   */
   protected String generateJiraToken(String df, String dt) {
     df = StringUtils.trimToEmpty(df);
     dt = StringUtils.trimToEmpty(dt);
@@ -238,11 +247,11 @@
    * 
    * @param responseBody to process
    * @return data loaded from JIRA
-   * @throws IOException
+   * @throws JIRACallException
    */
-  protected Map<String, String[]> processResponse(byte[] responseBody) throws IOException {
+  protected Map<String, String[]> processResponse(byte[] responseBody) throws JIRACallException {
     if (responseBody == null || responseBody.length == 0) {
-      throw new IOException("JIRA HTTP call failed: empty response");
+      throw new JIRACallException("Empty response");
     }
 
     String response = (new String(responseBody)).trim();
@@ -250,16 +259,16 @@
     int idx = response.indexOf("id=\"jira_cont_rep_csv\"");
     if (idx < 0) {
       log.error("JIRA HTTP call failed: Bad response, no csv file part found in returned data: " + response);
-      throw new IOException(
-          "JIRA HTTP call failed: Bad response, no csv file part found in returned data. See logfile for returned content.");
+      throw new JIRACallException(
+          "Bad response, no csv file part found in returned data. See logfile for returned content.");
     }
     int startIdx = response.indexOf(">", idx) + 1;
     int endIdx = response.indexOf("<", startIdx);
 
     if (startIdx == -1 || endIdx == -1 || startIdx > endIdx) {
       log.error("JIRA HTTP call failed: Bad response, no csv file part found in returned data: " + response);
-      throw new IOException(
-          "JIRA HTTP call failed: Bad response, no csv file part found in returned data. See logfile for returned content.");
+      throw new JIRACallException(
+          "Bad response, no csv file part found in returned data. See logfile for returned content.");
     }
 
     String csvcontent = response.substring(startIdx, endIdx).trim();
@@ -271,23 +280,26 @@
     String[] row = null;
 
     boolean first = true;
-    while ((row = reader.readNext()) != null) {
-      if (row.length < 6) {
-        log.error("JIRA HTTP call failed: Bad response, short line in returned data: " + csvcontent);
-        throw new IOException(
-            "JIRA HTTP call failed: Bad response, short line in returned data. See logfile for returned content.");
-      }
-      // skip header
-      if (first) {
-        first = false;
-      } else {
-        String[] data = (String[]) ArrayUtils.subarray(row, 2, 6);
-        checkCSVValue(csvcontent, row[0]);
-        for (String v : data) {
-          checkCSVValue(csvcontent, v);
+    try {
+      while ((row = reader.readNext()) != null) {
+        if (row.length < 6) {
+          log.error("JIRA HTTP call failed: Bad response, short line in returned data: " + csvcontent);
+          throw new JIRACallException("Bad response, short line in returned data. See logfile for returned content.");
         }
-        ret.put(row[0], data);
+        // skip header
+        if (first) {
+          first = false;
+        } else {
+          String[] data = (String[]) ArrayUtils.subarray(row, 2, 6);
+          checkCSVValue(csvcontent, row[0]);
+          for (String v : data) {
+            checkCSVValue(csvcontent, v);
+          }
+          ret.put(row[0], data);
+        }
       }
+    } catch (IOException e) {
+      throw new JIRACallException(e);
     }
     return ret;
 
@@ -300,11 +312,11 @@
    * @param value to check
    * @throws IOException
    */
-  protected void checkCSVValue(String csvcontent, String value) throws IOException {
+  protected void checkCSVValue(String csvcontent, String value) throws JIRACallException {
     if (StringUtils.trimToNull(value) == null) {
       log.error("JIRA HTTP call failed: Bad response, no value on some line of in returned data: " + csvcontent);
-      throw new IOException(
-          "JIRA HTTP call failed: Bad response, no value on some line of in returned data. See logfile for returned content.");
+      throw new JIRACallException(
+          "Bad response, no value on some line of in returned data. See logfile for returned content.");
     }
   }
 }

Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java	2010-10-27 07:35:26 UTC (rev 35758)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -1,7 +1,5 @@
 package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
 
-import java.io.IOException;
-
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
@@ -34,7 +32,7 @@
   protected SimpleDateFormat UTIL_DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
 
   @Test
-  public void processResponse() throws IOException {
+  public void processResponse() throws FishEyeCallException {
 
     FISHEYEValueSource tested = new FISHEYEValueSource(null, null, null);
 
@@ -42,35 +40,35 @@
     try {
       ret = tested.processResponse(null);
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (FishEyeCallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (FishEyeCallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("fault:Erro xxxx".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (FishEyeCallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("ok:1".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (FishEyeCallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("nook:1:10".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (FishEyeCallException e) {
       // OK
     }
 
@@ -203,7 +201,7 @@
         server.connect();
         val = tested.getValues(id);
         Assert.fail();
-      } catch (IOException e) {
+      } catch (FishEyeCallException e) {
         // ok
       } finally {
         server.disconnect();
@@ -215,7 +213,7 @@
         server.connect();
         val = tested.getValues(id);
         Assert.fail();
-      } catch (IOException e) {
+      } catch (FishEyeCallException e) {
         // ok
       } finally {
         server.disconnect();

Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java	2010-10-27 07:35:26 UTC (rev 35758)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java	2010-10-27 08:43:25 UTC (rev 35759)
@@ -1,6 +1,5 @@
 package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
 
-import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.HashMap;
 import java.util.Map;
@@ -22,12 +21,12 @@
   /**
    * URL value used for integration test {@link #loadData_INTEGRATION()}
    */
-  protected static final String INT_TEST_URL = "http://localhost:8080/secure/ConfigureReport.jspa";
+  protected static final String INTEGRATION_TEST_URL = "https://jira01-stg.jboss.org/secure/ConfigureReport.jspa";
 
   /**
    * Disable integration test ({@link #loadData_INTEGRATION()}) here.
    */
-  protected static boolean INT_TEST_PERFORM = false;
+  protected static boolean INTEGRATION_TEST_PERFORM = false;
 
   /**
    * If change this, check all tests where used!!
@@ -73,8 +72,8 @@
 
     try {
       tested.getValues("ORG");
-      Assert.fail("IOException must be thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException must be thrown");
+    } catch (JIRACallException e) {
       // OK
     }
     Assert.assertEquals(1, tested.checkCallCount());
@@ -82,16 +81,16 @@
     // cache used
     try {
       tested.getValues("ORG44");
-      Assert.fail("IOException must be thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException must be thrown");
+    } catch (JIRACallException e) {
       // OK
     }
     Assert.assertEquals(0, tested.checkCallCount());
 
     try {
       tested.getValues("ORG22");
-      Assert.fail("IOException must be thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException must be thrown");
+    } catch (JIRACallException e) {
       // OK
     }
     Assert.assertEquals(0, tested.checkCallCount());
@@ -123,28 +122,28 @@
   }
 
   @Test
-  public void processResponse() throws IOException {
+  public void processResponse() throws JIRACallException {
     JIRAValueSource tested = new JIRAValueSource(null, null, null);
 
     Map<String, String[]> ret = null;
     try {
       ret = tested.processResponse(null);
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (JIRACallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (JIRACallException e) {
       // OK
     }
 
     try {
       ret = tested.processResponse("strange not correct content".getBytes());
       Assert.fail("No exception thrown");
-    } catch (IOException e) {
+    } catch (JIRACallException e) {
       // OK
     }
 
@@ -182,8 +181,8 @@
           .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
               + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
               + "ORG,JBoss.org,10,9,15\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
-      Assert.fail("Exception not thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException not thrown");
+    } catch (JIRACallException e) {
       // OK
     }
 
@@ -193,8 +192,8 @@
           .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
               + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
               + "ORG,JBoss.org,10,9,15,\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
-      Assert.fail("Exception not thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException not thrown");
+    } catch (JIRACallException e) {
       // OK
     }
 
@@ -204,8 +203,8 @@
           .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
               + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
               + ",JBoss.org,10,9,15,22\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
-      Assert.fail("Exception not thrown");
-    } catch (IOException e) {
+      Assert.fail("JIRACallException not thrown");
+    } catch (JIRACallException e) {
       // OK
     }
 
@@ -272,10 +271,10 @@
   @Test
   public void loadData_INTEGRATION() throws Exception {
 
-    if (INT_TEST_PERFORM) {
+    if (INTEGRATION_TEST_PERFORM) {
       MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
       config.addConfigProperty(JIRAValueSource.CONFIG_KEY_DEBUG, "false");
-      config.addConfigProperty(JIRAValueSource.CONFIG_KEY_URL, INT_TEST_URL);
+      config.addConfigProperty(JIRAValueSource.CONFIG_KEY_URL, INTEGRATION_TEST_URL);
 
       JIRAValueSource tested = new JIRAValueSource(config, null, null);
 
@@ -311,11 +310,11 @@
     }
 
     @Override
-    protected Map<String, String[]> loadData() throws IOException {
+    protected Map<String, String[]> loadData() throws JIRACallException {
 
       callcount++;
       if (exception) {
-        throw new IOException();
+        throw new JIRACallException("Test Exception");
       }
 
       Map<String, String[]> ret = new HashMap<String, String[]>();



More information about the jboss-svn-commits mailing list