Class D1ResourceHandler

java.lang.Object
edu.ucsb.nceas.metacat.restservice.D1ResourceHandler
Direct Known Subclasses:
CNResourceHandler, CNResourceHandler, MNResourceHandler, MNResourceHandler

public class D1ResourceHandler extends Object
Base class for handling D1 REST calls in Metacat
Author:
leinfelder
  • Field Details

  • Constructor Details

    • D1ResourceHandler

      public D1ResourceHandler(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Initializes new instance by setting servlet context,request and response
      Parameters:
      request - the request that the handler will handle
      response - the response that the handler will send back
  • Method Details

    • handle

      public void handle(byte httpVerb)
      This function is called from REST API servlet and handles each request
      Parameters:
      httpVerb - (GET, POST, PUT or DELETE)
    • isD1Enabled

      protected boolean isD1Enabled()
      subclasses should provide a more useful implementation
      Returns:
    • parseTrailing

      protected String parseTrailing(String resource, String token)
    • collectMultipartParams

      protected void collectMultipartParams() throws IOException, org.apache.commons.fileupload.FileUploadException, Exception
      Parse string parameters from the mime multipart entity of the request. Populates the multipartparams map
      Throws:
      IOException
      org.apache.commons.fileupload.FileUploadException
      Exception
    • collectMultipartFiles

      protected Map<String,File> collectMultipartFiles() throws org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidRequest
      Process the MMP request that includes files for each param
      Returns:
      map of param key and the temp file that contains the encoded information
      Throws:
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest
    • collectObjectFiles

      protected MultipartRequestWithSysmeta collectObjectFiles() throws IOException, org.apache.commons.fileupload.FileUploadException, InstantiationException, IllegalAccessException, NoSuchAlgorithmException, org.dataone.exceptions.MarshallingException, org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure, RuntimeException, InterruptedException, org.dataone.service.exceptions.InvalidSystemMetadata, InvocationTargetException
      Parse the request by the streaming multiple part handler. This method is good for the cn.create and mn.create/update methods.
      Returns:
      the MultipartRequestWithSysmeta object which includes the stored object file with its checksum and the system metadata about this object
      Throws:
      IOException
      org.apache.commons.fileupload.FileUploadException
      InstantiationException
      IllegalAccessException
      NoSuchAlgorithmException
      org.dataone.exceptions.MarshallingException
      InterruptedException
      RuntimeException
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.InvalidSystemMetadata
      InvocationTargetException
    • initParams

      protected void initParams()
      copies request parameters to a hashtable which is given as argument to native metacathandler functions
    • initMultipartParams

      protected void initMultipartParams() throws Exception
      Collect the multipart params from the request
      Throws:
      Exception
    • getTempDirectory

      protected static File getTempDirectory()
      return the directory where temp files are stored
      Returns:
    • printError

      protected void printError(String message, javax.servlet.http.HttpServletResponse response)
      Prints xml response
      Parameters:
      message - Message to be displayed
      response - Servlet response that xml message will be printed
    • serializeException

      protected void serializeException(org.dataone.service.exceptions.BaseException e, OutputStream out)
      serialize a D1 exception using jibx
      Parameters:
      e -
      out -
    • decode

      public static String decode(String s)
      A method to decode the given string which is a part of a uri. The default encoding is utf-8. If the utf-8 is not support in this system, the default one in the systme will be used.
      Parameters:
      s -
      Returns:
      null if the given string is null
    • getSessionFromHeader

      protected void getSessionFromHeader()
      Get the session from the header of the request. This mechanism is disabled by default due to network security conditions needed for it to be secure