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

    • GET

      public static final byte GET
      HTTP Verb GET
      See Also:
    • POST

      public static final byte POST
      HTTP Verb POST
      See Also:
    • PUT

      public static final byte PUT
      HTTP Verb PUT
      See Also:
    • DELETE

      public static final byte DELETE
      HTTP Verb DELETE
      See Also:
    • MAX_UPLOAD_SIZE

      protected static int MAX_UPLOAD_SIZE
      Maximum size of uploads, defaults to 1GB if not set in property file
    • RESOURCE_BASE_URL

      protected static final String RESOURCE_BASE_URL
      See Also:
    • RESOURCE_OBJECTS

      protected static final String RESOURCE_OBJECTS
      See Also:
    • RESOURCE_META

      protected static final String RESOURCE_META
      See Also:
    • RESOURCE_LOG

      protected static final String RESOURCE_LOG
      See Also:
    • RESOURCE_QUERY

      protected static final String RESOURCE_QUERY
      See Also:
    • RESOURCE_IS_AUTHORIZED

      protected static final String RESOURCE_IS_AUTHORIZED
      See Also:
    • RESOURCE_ACCESS_RULES

      protected static final String RESOURCE_ACCESS_RULES
      See Also:
    • RESOURCE_VIEWS

      protected static final String RESOURCE_VIEWS
      See Also:
    • FUNCTION_NAME_INSERT

      protected static final String FUNCTION_NAME_INSERT
      See Also:
    • FUNCTION_NAME_UPDATE

      protected static final String FUNCTION_NAME_UPDATE
      See Also:
    • auth

      protected static AuthSession auth
    • authCacheSzie

      protected static int authCacheSzie
    • enableAppendLdapGroups

      protected static boolean enableAppendLdapGroups
    • servletContext

      protected javax.servlet.ServletContext servletContext
    • logMetacat

      protected static org.apache.commons.logging.Log logMetacat
    • request

      protected javax.servlet.http.HttpServletRequest request
    • response

      protected javax.servlet.http.HttpServletResponse response
    • enableSessionFromHeader

      protected boolean enableSessionFromHeader
    • proxyKey

      protected String proxyKey
    • params

      protected Hashtable<String,String[]> params
    • multipartparams

      protected Map<String,List<String>> multipartparams
    • session

      protected org.dataone.service.types.v1.Session session
  • Constructor Details

    • D1ResourceHandler

      public D1ResourceHandler(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Initializes new instance by setting servlet context,request and response
  • 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
      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
    • 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
    • findBoundaryString

      protected static String[] findBoundaryString(InputStream is) throws IOException
      locate the boundary marker for an MMP
      Parameters:
      is -
      Returns:
      Throws:
      IOException
    • 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