Commit 61a22d4a authored by Robert Butora's avatar Robert Butora
Browse files

adds error handling to formatting-filter and makes doError if essential...

adds error handling to formatting-filter and makes doError if essential columns do not exist int the obscore-table
parent ef145d74
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class DbPSearch


   public String[] queryOverlapingPubdid(Coord coord)
      throws Exception
   {
      LOGGER.fine("trace");

@@ -110,8 +111,9 @@ public class DbPSearch
      }
      catch (SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         // se.printStackTrace();
         throw new Exception(se.toString());
      }

      String[] pubdidArr = pubdidList.toArray(new String[0]);
@@ -152,6 +154,7 @@ public class DbPSearch


   public FormatResponseFilter.ObsCore[] queryOutputData(String[] pubdidArr, Pos pos)
      throws Exception
   {
      LOGGER.fine("trace");

@@ -241,8 +244,9 @@ public class DbPSearch
      }
      catch (SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         // se.printStackTrace();
         throw new Exception(se.toString());
      }

      FormatResponseFilter.ObsCore[] cubes = obsCoreList.toArray(new FormatResponseFilter.ObsCore[0]);
@@ -261,7 +265,7 @@ public class DbPSearch
      }
      catch(SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         return null;
      }
   }
@@ -275,7 +279,7 @@ public class DbPSearch
      }
      catch(SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         return null;
      }
   }
@@ -289,7 +293,7 @@ public class DbPSearch
      }
      catch(SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         return null;
      }
   }
@@ -303,7 +307,7 @@ public class DbPSearch
      }
      catch(SQLException se)
      {
         logSqlExInfo(se);
         dbError(se);
         return null;
      }
   }
@@ -393,7 +397,7 @@ public class DbPSearch
   }


   private void logSqlExInfo(SQLException se)
   private void dbError(SQLException se)
   {
      LOGGER.fine("SQLState : " + se.getSQLState());
      LOGGER.fine("ErrorCode: " + se.getErrorCode());
+108 −56
Original line number Diff line number Diff line
@@ -61,12 +61,6 @@ public class FormatResponseFilter implements Filter

   private String reqQueryString;

   protected void doUsageError(String message, PrintWriter printWriter)
   {
      printWriter.println("UsageError : " + message);
   }


   @Override
   public void init(FilterConfig filterConfig) throws ServletException
   {
@@ -77,16 +71,38 @@ public class FormatResponseFilter implements Filter
      LOGGER.config("DB: " + settings.dbConn.toString());
   }

   // FIXME move error handling funcs to VOlib

   protected void doMultiValuedParamNotSupported(String message, PrintWriter printWriter)
   {
      printWriter.println("MultiValuedParamNotSupported : " + message);
   }

   protected void doUsageError(String message, PrintWriter printWriter)
   {
      printWriter.println("UsageError : " + message);
   }

   protected void doError(String message, PrintWriter printWriter)
   {
      printWriter.println("Error : " + message);
   }



   @Override
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
   {
      LOGGER.fine("trace");
      LOGGER.fine("REQUEST START =============================================================================================");
      long startTime_msec = System.currentTimeMillis();

      FormatResponseWrapper responseWrapper = new FormatResponseWrapper((HttpServletResponse) response);

      try
      {
         long startTime_msec = System.currentTimeMillis();


         chain.doFilter(request, responseWrapper);

         String[] pubdidArr = responseWrapper.getPubdidArr();
@@ -150,6 +166,41 @@ public class FormatResponseFilter implements Filter
         {
            LOGGER.fine("SearchServlet returned no ID's.");
         }
      }
      catch(MultiValuedParamNotSupported ex)
      {
         LOGGER.warning("MultiValuedParamNotSupported: " + ex.getMessage());

         responseWrapper.setStatus(HttpServletResponse.SC_BAD_REQUEST);
         responseWrapper.setContentType("text/plain");

         PrintWriter writer = responseWrapper.getWriter();
         doMultiValuedParamNotSupported(ex.getMessage(), writer);
         writer.close();
      }
      catch(IllegalArgumentException ex)
      {
         LOGGER.warning("IllegalArgumentException: " + ex.getMessage());

         responseWrapper.setStatus(HttpServletResponse.SC_BAD_REQUEST);
         responseWrapper.setContentType("text/plain");

         PrintWriter writer = responseWrapper.getWriter();
         doUsageError(ex.getMessage(), writer);
         writer.close();
      }
      catch(Exception ex)
      {
         LOGGER.warning("Exception: " + ex.getMessage());
         // ex.printStackTrace();

         responseWrapper.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
         responseWrapper.setContentType("text/plain");

         PrintWriter writer = responseWrapper.getWriter();
         doError(ex.toString(), writer);
         writer.close();
      }

      LOGGER.fine("REQUEST END   =============================================================================================");
   }
@@ -216,6 +267,7 @@ public class FormatResponseFilter implements Filter


   private FormatResponseFilter.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos)//, String fitsRemotePath)
           throws Exception
   {
      LOGGER.fine("trace");