edu.ucsb.nceas.metacat.restservice

## Class D1ResourceHandler

- java.lang.Object
- - edu.ucsb.nceas.metacat.restservice.D1ResourceHandler

- Direct Known Subclasses:
    CNResourceHandler, CNResourceHandler, MNResourceHandler, MNResourceHandler

      public class D1ResourceHandler
      extends java.lang.Object

  Base class for handling D1 REST calls in Metacat
  Author:
    leinfelder

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static AuthSession` | `auth`
    `protected static int` | `authCacheSzie`
    `static byte` | `DELETE` HTTP Verb DELETE
    `protected static boolean` | `enableAppendLdapGroups`
    `protected boolean` | `enableSessionFromHeader`
    `protected static java.lang.String` | `FUNCTION_NAME_INSERT`
    `protected static java.lang.String` | `FUNCTION_NAME_UPDATE`
    `static byte` | `GET` HTTP Verb GET
    `static byte` | `HEAD` HTTP Verb HEAD
    `protected static org.apache.commons.logging.Log` | `logMetacat`
    `protected static int` | `MAX_UPLOAD_SIZE` Maximum size of uploads, defaults to 1GB if not set in property file
    `protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>` | `multipartparams`
    `protected java.util.Hashtable<java.lang.String,java.lang.String[]>` | `params`
    `static byte` | `POST` HTTP Verb POST
    `protected java.lang.String` | `proxyKey`
    `static byte` | `PUT` HTTP Verb PUT
    `protected javax.servlet.http.HttpServletRequest` | `request`
    `protected static java.lang.String` | `RESOURCE_ACCESS_RULES`
    `protected static java.lang.String` | `RESOURCE_BASE_URL`
    `protected static java.lang.String` | `RESOURCE_IS_AUTHORIZED`
    `protected static java.lang.String` | `RESOURCE_LOG`
    `protected static java.lang.String` | `RESOURCE_META`
    `protected static java.lang.String` | `RESOURCE_OBJECTS`
    `protected static java.lang.String` | `RESOURCE_QUERY`
    `protected static java.lang.String` | `RESOURCE_VIEWS`
    `protected javax.servlet.http.HttpServletResponse` | `response`
    `protected javax.servlet.ServletContext` | `servletContext`
    `protected org.dataone.service.types.v1.Session` | `session`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `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 Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.util.Map<java.lang.String,java.io.File>` | `collectMultipartFiles()` Process the MMP request that includes files for each param
    `protected void` | `collectMultipartParams()` Parse string parameters from the mime multipart entity of the request.
    `protected MultipartRequestWithSysmeta` | `collectObjectFiles()` Parse the request by the streaming multiple part handler.
    `static java.lang.String` | `decode(java.lang.String s)` A method to decode the given string which is a part of a uri.
    `protected static java.lang.String[]` | `findBoundaryString(java.io.InputStream is)` locate the boundary marker for an MMP
    `protected void` | `getSessionFromHeader()` Get the session from the header of the request.
    `protected static java.io.File` | `getTempDirectory()` return the directory where temp files are stored
    `void` | `handle(byte httpVerb)` This function is called from REST API servlet and handles each request
    `protected void` | `initMultipartParams()` Collect the multipart params from the request
    `protected void` | `initParams()` copies request parameters to a hashtable which is given as argument to native metacathandler functions
    `protected boolean` | `isD1Enabled()` subclasses should provide a more useful implementation
    `protected java.lang.String` | `parseTrailing(java.lang.String resource, java.lang.String token)`
    `protected void` | `printError(java.lang.String message, javax.servlet.http.HttpServletResponse response)` Prints xml response
    `protected void` | `serializeException(org.dataone.service.exceptions.BaseException e, java.io.OutputStream out)` serialize a D1 exception using jibx

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### GET

          public static final byte GET

      HTTP Verb GET
      See Also:
        Constant Field Values

    - #### POST

          public static final byte POST

      HTTP Verb POST
      See Also:
        Constant Field Values

    - #### PUT

          public static final byte PUT

      HTTP Verb PUT
      See Also:
        Constant Field Values

    - #### DELETE

          public static final byte DELETE

      HTTP Verb DELETE
      See Also:
        Constant Field Values

    - #### HEAD

          public static final byte HEAD

      HTTP Verb HEAD
      See Also:
        Constant Field Values

    - #### 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 java.lang.String RESOURCE_BASE_URL

      See Also:
        Constant Field Values

    - #### RESOURCE_OBJECTS

          protected static final java.lang.String RESOURCE_OBJECTS

      See Also:
        Constant Field Values

    - #### RESOURCE_META

          protected static final java.lang.String RESOURCE_META

      See Also:
        Constant Field Values

    - #### RESOURCE_LOG

          protected static final java.lang.String RESOURCE_LOG

      See Also:
        Constant Field Values

    - #### RESOURCE_QUERY

          protected static final java.lang.String RESOURCE_QUERY

      See Also:
        Constant Field Values

    - #### RESOURCE_IS_AUTHORIZED

          protected static final java.lang.String RESOURCE_IS_AUTHORIZED

      See Also:
        Constant Field Values

    - #### RESOURCE_ACCESS_RULES

          protected static final java.lang.String RESOURCE_ACCESS_RULES

      See Also:
        Constant Field Values

    - #### RESOURCE_VIEWS

          protected static final java.lang.String RESOURCE_VIEWS

      See Also:
        Constant Field Values

    - #### FUNCTION_NAME_INSERT

          protected static final java.lang.String FUNCTION_NAME_INSERT

      See Also:
        Constant Field Values

    - #### FUNCTION_NAME_UPDATE

          protected static final java.lang.String FUNCTION_NAME_UPDATE

      See Also:
        Constant Field Values

    - #### 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 java.lang.String proxyKey

    - #### params

          protected java.util.Hashtable<java.lang.String,java.lang.String[]> params

    - #### multipartparams

          protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> multipartparams

    - #### session

          protected org.dataone.service.types.v1.Session session

  - ### Constructor Detail

    - #### 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 Detail

    - #### 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 java.lang.String parseTrailing(java.lang.String resource,
                                                   java.lang.String token)

    - #### collectMultipartParams

          protected void collectMultipartParams()
                                         throws java.io.IOException,
                                                org.apache.commons.fileupload.FileUploadException,
                                                java.lang.Exception

      Parse string parameters from the mime multipart entity of the request. Populates the multipartparams map
      Throws:
        `java.io.IOException`
        `org.apache.commons.fileupload.FileUploadException`
        `java.lang.Exception`

    - #### collectMultipartFiles

          protected java.util.Map<java.lang.String,java.io.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 java.io.IOException,
                                                                   org.apache.commons.fileupload.FileUploadException,
                                                                   java.lang.InstantiationException,
                                                                   java.lang.IllegalAccessException,
                                                                   java.security.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:
        `java.io.IOException`
        `org.apache.commons.fileupload.FileUploadException`
        `java.lang.InstantiationException`
        `java.lang.IllegalAccessException`
        `java.security.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 java.lang.Exception

      Collect the multipart params from the request
      Throws:
        `java.lang.Exception`

    - #### findBoundaryString

          protected static java.lang.String[] findBoundaryString(java.io.InputStream is)
                                                          throws java.io.IOException

      locate the boundary marker for an MMP
      Parameters:
        `is` -
      Returns:
      Throws:
        `java.io.IOException`

    - #### getTempDirectory

          protected static java.io.File getTempDirectory()

      return the directory where temp files are stored
      Returns:

    - #### printError

          protected void printError(java.lang.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,
                                            java.io.OutputStream out)

      serialize a D1 exception using jibx
      Parameters:
        `e` -
        `out` -

    - #### decode

          public static java.lang.String decode(java.lang.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

Copyright © 2023 Regents of the University of California. All Rights Reserved.