Class Resource

    • Field Detail

      • servletContext

        @Context
        public javax.servlet.ServletContext servletContext
    • Constructor Detail

      • Resource

        public Resource()
    • Method Detail

      • createContext

        protected static Context createContext()
                                        throws ContextException,
                                               SQLException
        Create context to work with DSpace database. It can create context with or without a logged in user (retrieved from SecurityContextHolder). Throws WebApplicationException caused by: SQLException if there was a problem with reading from database. Throws AuthorizeException if there was a problem with authorization to read from the database. Throws Exception if there was a problem creating context.
        Returns:
        Newly created context with the logged in user unless the specified user was null. If user is null, create the context without a logged in user.
        Throws:
        ContextException - Thrown in case of a problem creating context. Can be caused by SQLException error in creating context or finding the user to log in. Can be caused by AuthorizeException if there was a problem authorizing the found user.
        SQLException - An exception that provides information on a database access error or other errors.
      • writeStats

        protected void writeStats​(DSpaceObject dspaceObject,
                                  UsageEvent.Action action,
                                  String user_ip,
                                  String user_agent,
                                  String xforwardedfor,
                                  javax.ws.rs.core.HttpHeaders headers,
                                  javax.servlet.http.HttpServletRequest request,
                                  Context context)
        Records a statistics event about an object used via REST API.
        Parameters:
        dspaceObject - DSpace object on which a request was performed.
        action - Action that was performed.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        context - Context which must be aborted.
      • processException

        protected static void processException​(String message,
                                               Context context)
                                        throws javax.ws.rs.WebApplicationException
        Process exception, print message to logger error stream and abort DSpace context.
        Parameters:
        message - Message, which will be printed to error stream.
        context - Context which must be aborted.
        Throws:
        javax.ws.rs.WebApplicationException - This exception is throw for user of REST api.
      • processFinally

        protected void processFinally​(Context context)
                               throws javax.ws.rs.WebApplicationException
        Process finally statement. It will print message to logger error stream and abort DSpace context, if was not properly ended.
        Parameters:
        context - Context which must be aborted.
        Throws:
        javax.ws.rs.WebApplicationException - This exception is thrown for user of REST API.
      • mySplit

        protected String[] mySplit​(String key)
        Split string with regex ".".
        Parameters:
        key - String which will be splitted.
        Returns:
        String array filed with separated string.
      • getActionString

        protected String getActionString​(int action)
        Return string representation of values org.dspace.core.Constants.{READ,WRITE,DELETE}.
        Parameters:
        action - Constant from org.dspace.core.Constants.*
        Returns:
        String representation. read or write or delete.