コード例 #1
0
  public void init() throws javax.servlet.ServletException {
    super.init();

    org.slf4j.Logger logServerStartup = org.slf4j.LoggerFactory.getLogger("serverStartup");
    logServerStartup.info(
        getClass().getName() + " initialization start - " + UsageLog.setupNonRequestContext());

    this.ascLimit = ThreddsConfig.getInt("Opendap.ascLimit", ascLimit);
    this.binLimit = ThreddsConfig.getInt("Opendap.binLimit", binLimit);

    this.odapVersionString = ThreddsConfig.get("Opendap.serverVersion", odapVersionString);
    logServerStartup.info(
        getClass().getName()
            + " version= "
            + odapVersionString
            + " ascLimit = "
            + ascLimit
            + " binLimit = "
            + binLimit);

    // debugging actions
    makeDebugActions();

    logServerStartup.info(
        getClass().getName()
            + " initialization done - "
            + UsageLog.closingMessageNonRequestContext());
  }
コード例 #2
0
 /**
  * Query RadarServer controller for Spring Framework
  *
  * @param request HttpServletRequest
  * @param response HttpServletResponse
  * @return ModelAndView
  * @throws Exception
  */
 protected ModelAndView handleRequestInternal(
     HttpServletRequest request, HttpServletResponse response) throws Exception {
   try {
     // Gather diagnostics for logging request.
     log.info("handleRequestInternal(): " + UsageLog.setupRequestContext(request));
     // catch rogue invalid request here
     if (request.getQueryString() == null) {
       log.info("Invalid dataset url reference " + request.getPathInfo());
       throw new RadarServerException("Invalid dataset url reference " + request.getPathInfo());
     }
     // Query results in model
     Map<String, Object> model = new HashMap<String, Object>();
     radarQuery(request, response, model);
     if (model == null || model.size() == 0) {
       ModelAndView mav = new ModelAndView(CREATE_VIEW);
       mav.addObject(MODEL_KEY, MSG_CODE);
       return mav;
     } else {
       return new ModelAndView("queryXml", model);
     }
   } catch (RadarServerException e) {
     throw e; // pass it onto Spring exceptionResolver
   } catch (Throwable e) {
     log.error("handleRequestInternal(): Problem handling request.", e);
     log.info(
         "handleRequestInternal(): "
             + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
     throw new RadarServerException("handleRequestInternal(): Problem handling request.");
   }
 }
コード例 #3
0
  private void sendErrorResponse(HttpServletResponse response, int errorCode, String errorMessage) {
    try {
      log.info(UsageLog.closingMessageForRequestContext(errorCode, -1));
      response.setStatus(errorCode);
      response.setHeader("Content-Description", "dods-error");
      response.setContentType("text/plain");

      PrintWriter pw = new PrintWriter(response.getOutputStream());
      pw.println("Error {");
      pw.println("    code = " + errorCode + ";");
      pw.println("    message = \"" + errorMessage + "\";");

      pw.println("};");
      pw.flush();
    } catch (Exception e) {
      System.err.println("sendErrorResponse: " + e);
    }
  }
コード例 #4
0
  public void doGet(HttpServletRequest request, HttpServletResponse response) {
    log.info("doGet(): " + UsageLog.setupRequestContext(request));
    // System.out.printf("opendap doGet: req=%s%n%s%n", ServletUtil.getRequest(request),
    // ServletUtil.showRequestDetail(this, request));

    String path = null;

    ReqState rs = getRequestState(request, response);

    try {
      path = request.getPathInfo();
      log.debug("doGet path={}", path);

      if (thredds.servlet.Debug.isSet("showRequestDetail"))
        log.debug(ServletUtil.showRequestDetail(this, request));

      if (path == null) {
        log.info(
            "doGet(): "
                + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_NOT_FOUND, -1));
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }

      if (baseURI == null) { // first time, set baseURI
        URI reqURI = ServletUtil.getRequestURI(request);
        // Build base URI from request (rather than hard-coding "/thredds/dodsC/").
        String baseUriString = request.getContextPath() + request.getServletPath() + "/";
        baseURI = reqURI.resolve(baseUriString);
        log.debug("doGet(): baseURI was set = {}", baseURI);
      }

      if (path.endsWith("latest.xml")) {
        DataRootHandler.getInstance().processReqForLatestDataset(this, request, response);
        return;
      }

      // Redirect all catalog requests at the root level.
      if (path.equals("/") || path.equals("/catalog.html") || path.equals("/catalog.xml")) {
        ServletUtil.sendPermanentRedirect(ServletUtil.getContextPath() + path, request, response);
        return;
      }

      // Make sure catalog requests match a dataRoot before trying to handle.
      if (path.endsWith("/") || path.endsWith("/catalog.html") || path.endsWith("/catalog.xml")) {
        if (!DataRootHandler.getInstance().hasDataRootMatch(path)) {
          log.info(
              "doGet(): "
                  + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_NOT_FOUND, -1));
          response.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        if (!DataRootHandler.getInstance().processReqForCatalog(request, response))
          log.error(
              "doGet(): "
                  + UsageLog.closingMessageForRequestContext(
                      ServletUtil.STATUS_FORWARD_FAILURE, -1));

        return;
      }

      if (rs != null) {
        String dataSet = rs.getDataSet();
        String requestSuffix = rs.getRequestSuffix();

        if ((dataSet == null) || dataSet.equals("/") || dataSet.equals("")) {
          doGetDIR(rs);
        } else if (requestSuffix.equalsIgnoreCase("blob")) {
          doGetBLOB(rs);
        } else if (requestSuffix.equalsIgnoreCase("close")) {
          doClose(rs);
        } else if (requestSuffix.equalsIgnoreCase("dds")) {
          doGetDDS(rs);
        } else if (requestSuffix.equalsIgnoreCase("das")) {
          doGetDAS(rs);
        } else if (requestSuffix.equalsIgnoreCase("ddx")) {
          doGetDDX(rs);
        } else if (requestSuffix.equalsIgnoreCase("dods")) {
          doGetDAP2Data(rs);
        } else if (requestSuffix.equalsIgnoreCase("asc")
            || requestSuffix.equalsIgnoreCase("ascii")) {
          doGetASC(rs);
        } else if (requestSuffix.equalsIgnoreCase("info")) {
          doGetINFO(rs);
        } else if (requestSuffix.equalsIgnoreCase("html")
            || requestSuffix.equalsIgnoreCase("htm")) {
          doGetHTML(rs);
        } else if (requestSuffix.equalsIgnoreCase("ver")
            || requestSuffix.equalsIgnoreCase("version")
            || dataSet.equalsIgnoreCase("/version")
            || dataSet.equalsIgnoreCase("/version/")) {
          doGetVER(rs);
        } else if (dataSet.equalsIgnoreCase("/help")
            || dataSet.equalsIgnoreCase("/help/")
            || dataSet.equalsIgnoreCase("/" + requestSuffix)
            || requestSuffix.equalsIgnoreCase("help")) {
          doGetHELP(rs);
        } else {
          sendErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "Unrecognized request");
          return;
        }

      } else {
        sendErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "Unrecognized request");
        return;
      }

      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_OK, -1));

      // plain ol' 404
    } catch (FileNotFoundException e) {
      sendErrorResponse(response, HttpServletResponse.SC_NOT_FOUND, e.getMessage());

      // DAP2Exception bad url
    } catch (BadURLException e) {
      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      dap2ExceptionHandler(e, rs);

      // all other DAP2Exception
    } catch (DAP2Exception de) {
      int status =
          (de.getErrorCode() == DAP2Exception.NO_SUCH_FILE)
              ? HttpServletResponse.SC_NOT_FOUND
              : HttpServletResponse.SC_BAD_REQUEST;
      if ((de.getErrorCode() != DAP2Exception.NO_SUCH_FILE) && (de.getErrorMessage() != null))
        log.debug(de.getErrorMessage());
      log.info(UsageLog.closingMessageForRequestContext(status, -1));
      response.setStatus(status);
      dap2ExceptionHandler(de, rs);

      // parsing, usually the CE
    } catch (ParseException pe) {
      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      parseExceptionHandler(pe, response);

      // 403 - request too big
    } catch (UnsupportedOperationException e) {
      sendErrorResponse(response, HttpServletResponse.SC_FORBIDDEN, e.getMessage());

    } catch (java.net.SocketException e) {
      log.info("SocketException: " + e.getMessage(), e);
      log.info(UsageLog.closingMessageForRequestContext(ServletUtil.STATUS_CLIENT_ABORT, -1));

    } catch (IOException e) {
      String eName =
          e.getClass().getName(); // dont want compile time dependency on ClientAbortException
      if (eName.equals("org.apache.catalina.connector.ClientAbortException")) {
        log.debug("ClientAbortException: " + e.getMessage());
        log.info(UsageLog.closingMessageForRequestContext(ServletUtil.STATUS_CLIENT_ABORT, -1));
        return;
      }

      log.error("path= " + path, e);
      sendErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());

      // everything else
    } catch (Throwable t) {
      log.error("path= " + path, t);
      t.printStackTrace();
      sendErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage());
    }
  }
コード例 #5
0
  /*
      Final Output format, save information in DatasetEntry de
       <dataset name="Level2_KFTG_20100121_0000.ar2v" ID="735519521"
          urlPath="KFTG/20100121/Level2_KFTG_20100121_0000.ar2v">
          <date type="start of ob">2010-01-21T00:00:00</date>
        </dataset>
  */
  private Boolean processQuery(
      String dataset, QueryParams qp, String var, List<DatasetEntry> entries)
      throws RadarServerException {

    Boolean getAllTimes = true;
    String yyyymmddStart = null;
    String yyyymmddEnd = null;
    String dateStart = null;
    String dateEnd = null;
    try {
      if (!qp.time_start.equals(epicDateType)) {
        getAllTimes = false;
        yyyymmddStart = qp.time_start.toDateString();
        yyyymmddStart = yyyymmddStart.replace("-", "");
        yyyymmddEnd = qp.time_end.toDateString();
        yyyymmddEnd = yyyymmddEnd.replace("-", "");
        dateStart = yyyymmddStart + "_" + RadarServerUtil.hhmm(qp.time_start.toDateTimeString());
        dateEnd = yyyymmddEnd + "_" + RadarServerUtil.hhmm(qp.time_end.toDateTimeString());
      }

      RadarDatasetCollection rdc = DatasetRepository.getRadarDatasetCollection(dataset, var);
      if (rdc == null) {
        qp.errs.append("Invalid dataset =").append(dataset);
        qp.errs.append(" or var =").append(var);
        return false;
      }
      StringBuffer time = new StringBuffer();
      StringBuffer product = new StringBuffer();
      StringBuffer url = new StringBuffer();
      boolean isLevel2 = dataset.contains("level2");
      String type = (isLevel2 ? "Level2" : "Level3");
      String suffix = (isLevel2 ? ".ar2v" : ".nids");
      Calendar cal = Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT"));
      Date now = cal.getTime();
      String currentDay = dateFormat.format(now);

      for (String stn : qp.stns) {
        RadarStationCollection rsc = rdc.queryStation(stn, currentDay);
        if (rsc == null) continue;
        for (String day : rsc.getDays()) {
          // check for valid day
          if (!getAllTimes && !RadarServerUtil.isValidDay(day, yyyymmddStart, yyyymmddEnd))
            continue;
          ArrayList<String> tal;
          if (rdc.isCaseStudy()) { //
            tal = rsc.getHourMinute("all");
            for (String prod : tal) {
              // check times
              if (!getAllTimes && !RadarServerUtil.isValidDate(prod, dateStart, dateEnd)) continue;
              // save this entry
              DatasetEntry de = new DatasetEntry();
              int idx = prod.indexOf('/');
              if (idx > 0) {
                de.setName(prod.substring(idx + 1));
              } else {
                de.setName(prod);
              }
              de.setID(Integer.toString(prod.hashCode()));
              url.setLength(0);
              url.append(stn).append("/");
              if (var != null) {
                url.append(var).append("/");
              }
              url.append(prod);
              de.setUrlPath(url.toString());
              de.setDate(RadarServerUtil.getObTimeISO(prod));
              entries.add(de);
            }
            continue;
          } else {
            tal = rsc.getHourMinute(day);
          }
          if (tal == null) continue;
          for (String hm : tal) {
            time.setLength(0);
            time.append(day).append("_").append(hm);
            if (!getAllTimes && !RadarServerUtil.isValidDate(time.toString(), dateStart, dateEnd))
              continue;

            // save this entry
            DatasetEntry de = new DatasetEntry();

            product.setLength(0);
            product.append(type).append("_").append(rsc.getStnName()).append("_");
            if (!isLevel2) product.append(var).append("_");
            product.append(day).append("_").append(hm).append(suffix);

            de.setName(product.toString());
            de.setID(Integer.toString(product.toString().hashCode()));
            url.setLength(0);
            if (!isLevel2) {
              url.append(var).append("/");
            }
            url.append(rsc.getStnName())
                .append("/")
                .append(day)
                .append("/")
                .append(product.toString());
            de.setUrlPath(url.toString());
            de.setDate(RadarServerUtil.getObTimeISO(product.toString()));
            entries.add(de);
            if (qp.hasTimePoint) break;
          }
          if (qp.hasTimePoint) break;
        }
      }
      return true;
    } catch (Throwable e) {
      log.error("Invalid dataset =" + dataset + " or var =" + var, e);
      log.info(
          "handleRequestInternal(): "
              + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
      throw new RadarServerException("Invalid dataset =" + dataset + " or var =" + var);
    }
  }