Esempio n. 1
0
 public static String encode(String unencoded) throws LowlevelStorageException {
   try {
     int i = unencoded.indexOf("+");
     if (i != -1) {
       return Server.getPID(unencoded.substring(0, i)).toFilename() + unencoded.substring(i);
     } else {
       return Server.getPID(unencoded).toFilename();
     }
   } catch (MalformedPidException e) {
     throw new LowlevelStorageException(true, e.getMessage(), e);
   }
 }
  /**
   * Process Fedora Access Request. Parse and validate the servlet input parameters and then execute
   * the specified request.
   *
   * @param request The servlet request.
   * @param response servlet The servlet response.
   * @throws ServletException If an error occurs that effects the servlet's basic operation.
   * @throws IOException If an error occurrs with an input or output operation.
   */
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String PID = null;
    Date asOfDateTime = null;
    Date versDateTime = null;
    boolean xml = false;
    requestURI = request.getRequestURL().toString() + "?" + request.getQueryString();

    // Parse servlet URL.
    String[] URIArray = request.getRequestURL().toString().split("/");
    if (URIArray.length == 6 || URIArray.length == 7) {
      // Request is either unversioned or versioned listMethods request
      try {
        PID = Server.getPID(URIArray[5]).toString(); // normalize PID
      } catch (Throwable th) {
        logger.error("Bad pid syntax in request", th);
        throw new BadRequest400Exception(request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
      }
      if (URIArray.length == 7) {
        // Request is a versioned listMethods request
        try {
          versDateTime = DateUtility.parseDateStrict(URIArray[6]);
        } catch (ParseException e) {
          logger.error("Bad date format in request");
          throw new BadRequest400Exception(request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
        }
        asOfDateTime = versDateTime;
      }
      logger.debug("Listing methods (PID={}, asOfDate={})", PID, versDateTime);
    } else {
      logger.error("Bad syntax (expected 6 or 7 parts) in request");
      throw new BadRequest400Exception(request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
    }

    if (request.getParameter("xml") != null) {
      xml = Boolean.parseBoolean(request.getParameter("xml"));
    }

    try {
      Context context = ReadOnlyContext.getContext(HTTP_REQUEST.REST.uri, request);
      listMethods(context, PID, asOfDateTime, xml, request, response);
      logger.debug("Finished listing methods");
    } catch (ObjectNotFoundException e) {
      logger.error(
          "Object not found for request: " + requestURI + " (actionLabel=" + ACTION_LABEL + ")", e);
      throw new NotFound404Exception(request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
    } catch (DisseminationException e) {
      logger.error(
          "Error Listing Methods: " + requestURI + " (actionLabel=" + ACTION_LABEL + ")", e);
      throw new NotFound404Exception(
          "Error Listing Methods", e, request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
    } catch (ObjectNotInLowlevelStorageException e) {
      logger.error(
          "Object not found for request: " + requestURI + " (actionLabel=" + ACTION_LABEL + ")", e);
      throw new NotFound404Exception(request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
    } catch (AuthzException ae) {
      logger.error("Authorization error listing methods", ae);
      throw RootException.getServletException(ae, request, ACTION_LABEL, EMPTY_STRING_ARRAY);
    } catch (Throwable th) {
      logger.error("Error listing methods", th);
      throw new InternalError500Exception(
          "Error listing methods", th, request, ACTION_LABEL, "", EMPTY_STRING_ARRAY);
    }
  }