Class GuiseHTTPServlet

  • All Implemented Interfaces:
    io.clogr.Clogged, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class GuiseHTTPServlet
    extends com.globalmentor.servlet.http.DefaultHTTPServlet
    The servlet that controls a Guise web applications. Each Guise session's platform will be locked during normal web page generation context will be active at one one time. This implementation only works with Guise applications that descend from AbstractGuiseApplication.

    For all ResourceReadDestinations, this servlet recognizes a query parameter named "guiseContentDisposition" specifying the content disposition of the content to return; the value is the serialize version of a ContentDispositionType value.

    This servlet supports the following initialization parameters in addition to those in BaseHTTPServlet:
    Servlets.DATA_DIRECTORY_INIT_PARAMETER
    The directory for storing data.
    Servlets.LOG_DIRECTORY_INIT_PARAMETER
    The directory for storing logs.
    BaseHTTPServlet.DEBUG_INIT_PARAMETER
    Whether the servlet is in debug mode; should be "true" or "false"; sets the log level to debug if not explicitly set.
    BaseHTTPServlet.LOG_LEVEL_INIT_PARAMETER
    The level of logging for the JVM of type Log.Level. If multiple servlets specify this value, the last one initialized will have precedence.
    BaseHTTPServlet.LOG_HTTP_INIT_PARAMETER
    Whether HTTP communication is logged.
    BaseHTTPServlet.PROFILE_INIT_PARAMETER
    Whether profiling should occur; should be "true" or "false".

    For example, the following Guise servlet context might define a data directory:

    <Context ...><Parameter name="dataDirectory" value="D:\data"/></Context>
    Author:
    Garret Wilson
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  GuiseHTTPServlet.AbstractDescriptionResource
      A resource that has retrieves its properties, if possible, from a given RDF description.
      protected class  GuiseHTTPServlet.DestinationResource
      A resource that is accessed through a Guise session's resource destination.
      • Nested classes/interfaces inherited from class com.globalmentor.servlet.http.DefaultHTTPServlet

        com.globalmentor.servlet.http.DefaultHTTPServlet.AbstractByteCacheDecoratorResource, com.globalmentor.servlet.http.DefaultHTTPServlet.AbstractURLHTTPServletResource, com.globalmentor.servlet.http.DefaultHTTPServlet.DefaultHTTPServletResource, com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String APPLICATION_CLASS_INIT_PARAMETER
      The init parameter, "applicationClass", used to specify the Guise application to create.
      protected com.globalmentor.io.IOOperation<java.io.Writer> elffWriterInitializer
      The initializer for initializing ELFF writers.
      protected com.globalmentor.io.IOOperation<java.io.Writer> elffWriterUninitializer
      The uninitializer for uninitializing ELFF writers.
      static java.lang.String GUISE_CONTENT_DISPOSITION_URI_QUERY_PARAMETER
      The URI query parameter indicating that the content disposition of the content of a ResourceReadDestination.
      static java.lang.String GUISE_ENVIRONMENT_INIT_PARAMETER_PREFIX
      The init parameter prefix, "guise-environment:", used to indicate a Guise environment property.
      static java.lang.String GUISE_ENVIRONMENT_URI_INIT_PARAMETER_SUFFIX
      The init parameter suffix, ".uri", used to indicate that a Guise environment property should be processed as a URI.
      static java.lang.String SEND_RESOURCE_VIEWPORT_ID
      The ID of the viewport to use for sending resources.
      • Fields inherited from class com.globalmentor.servlet.http.AbstractHTTPServlet

        LIST_DIRECTORIES
      • Fields inherited from class com.globalmentor.servlet.http.BaseHTTPServlet

        DEBUG_INIT_PARAMETER, LOG_HTTP_INIT_PARAMETER, LOG_LEVEL_INIT_PARAMETER, NONCE_EXPIRATION_DURATION, PROFILE_INIT_PARAMETER
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiseHTTPServlet()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void authenticated​(javax.servlet.http.HttpServletRequest request, java.net.URI resourceURI, java.lang.String method, java.lang.String requestURI, java.security.Principal principal, java.lang.String realm, com.globalmentor.net.http.AuthenticateCredentials credentials, boolean authenticated)
      protected void beginModalNavigation​(GuiseApplication guiseApplication, GuiseSession guiseSession, ModalNavigation modalNavigation)
      Begins modal navigation based upon modal navigation information.
      protected boolean canSubstitute​(javax.servlet.http.HttpServletRequest request, java.net.URI requestedResourceURI, java.net.URI substituteResourceURI)
      void destroy()
      void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      void doPut​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected boolean exists​(javax.servlet.http.HttpServletRequest request, java.net.URI resourceURI)
      protected void getComponentsByDepictName​(Component component, java.lang.String depictName, java.util.Set<Component> componentSet)
      Retrieves all descendant components, including the given component, that have a given depict name.
      com.globalmentor.text.elff.ELFF getELFF()  
      protected AbstractGuiseApplication getGuiseApplication()  
      protected HTTPServletGuiseContainer getGuiseContainer()
      Returns the Guise container.
      protected char[] getPassword​(java.security.Principal principal)
      protected java.security.Principal getPrincipal​(java.lang.String id)
      protected java.lang.String getRealm​(java.net.URI resourceURI)
      protected java.util.List<GuiseEvent> getRequestEvents​(HTTPServletGuiseRequest guiseRequest, GuiseSession guiseSession, DepictContext depictContext)
      Retrieves events from the HTTP request.
      protected com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource getResource​(javax.servlet.http.HttpServletRequest request, java.net.URI resourceURI)
      protected AbstractGuiseApplication initGuiseApplication​(javax.servlet.ServletConfig servletConfig)
      Initializes bindings between paths and associated navigation frame classes.
      void initialize​(javax.servlet.http.HttpServletRequest request)
      void initialize​(javax.servlet.ServletConfig servletConfig)
      protected boolean isAuthorized​(javax.servlet.http.HttpServletRequest request, java.net.URI resourceURI, java.lang.String method, java.security.Principal principal, java.lang.String realm)
      protected boolean isValid​(javax.servlet.http.HttpServletRequest request, com.globalmentor.security.Nonce nonce)
      Determines if the given nonce is valid.
      protected void redirect​(HTTPServletGuiseRequest guiseRequest, GuiseApplication guiseApplication, RedirectDestination redirectDestination, Bookmark bookmark)
      Processes a redirect from a redirect destination.
      protected void redirect​(HTTPServletGuiseRequest guiseRequest, GuiseApplication guiseApplication, java.net.URI redirectNavigationURI, Bookmark bookmark, boolean permanent)
      Redirects to the given navigation path, preserving the given bookmark.
      protected void serveResource​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource resource, boolean serveContent)  
      protected void synchronizeCookies​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, GuiseSession guiseSession)
      Synchronizes the cookies in a request with the environment properties in a Guise session.
      • Methods inherited from class com.globalmentor.servlet.http.DefaultHTTPServlet

        createCollection, createResource, deleteResource, getChildResources, getContentLength, getContentType, getInputStream, getLastModifiedDate, getOutputStream, isCollection
      • Methods inherited from class com.globalmentor.servlet.http.AbstractHTTPServlet

        doDelete, doHead, doOptions, doPost, getAllowedMethods, getResourceURI, getResourceURI, getXML, isReadOnly, isRedirectSupported, serveResource, setReadOnly, setXML
      • Methods inherited from class com.globalmentor.servlet.http.BaseHTTPServlet

        checkAuthorization, checkAuthorization, createAuthenticateChallenge, createNonce, doMethod, getContextPath, getLogFile, getNonce, getNoncePrincipalID, getNoncePrivateKey, getPrincipal, getResourceContextAbsolutePath, getServletPath, init, isAuthenticated, isDebug, isProfiled, isStale, service, setNoncePrincipalID, storeNonce
      • Methods inherited from class javax.servlet.http.HttpServlet

        doTrace, getLastModified, service
      • Methods inherited from class javax.servlet.GenericServlet

        getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.clogr.Clogged

        getLogger
    • Field Detail

      • APPLICATION_CLASS_INIT_PARAMETER

        public static final java.lang.String APPLICATION_CLASS_INIT_PARAMETER
        The init parameter, "applicationClass", used to specify the Guise application to create.
        See Also:
        Constant Field Values
      • GUISE_ENVIRONMENT_INIT_PARAMETER_PREFIX

        public static final java.lang.String GUISE_ENVIRONMENT_INIT_PARAMETER_PREFIX
        The init parameter prefix, "guise-environment:", used to indicate a Guise environment property.
        See Also:
        Constant Field Values
      • GUISE_ENVIRONMENT_URI_INIT_PARAMETER_SUFFIX

        public static final java.lang.String GUISE_ENVIRONMENT_URI_INIT_PARAMETER_SUFFIX
        The init parameter suffix, ".uri", used to indicate that a Guise environment property should be processed as a URI.
        See Also:
        Constant Field Values
      • GUISE_CONTENT_DISPOSITION_URI_QUERY_PARAMETER

        public static final java.lang.String GUISE_CONTENT_DISPOSITION_URI_QUERY_PARAMETER
        The URI query parameter indicating that the content disposition of the content of a ResourceReadDestination. The value will be the serialize version of a ContentDispositionType value.
        See Also:
        Constant Field Values
      • SEND_RESOURCE_VIEWPORT_ID

        public static final java.lang.String SEND_RESOURCE_VIEWPORT_ID
        The ID of the viewport to use for sending resources.
        See Also:
        Constant Field Values
      • elffWriterInitializer

        protected final com.globalmentor.io.IOOperation<java.io.Writer> elffWriterInitializer
        The initializer for initializing ELFF writers. This implementation writes the default directives along with the Start-Date directive.
      • elffWriterUninitializer

        protected final com.globalmentor.io.IOOperation<java.io.Writer> elffWriterUninitializer
        The uninitializer for uninitializing ELFF writers. This implementation writes the End-Date directive.
    • Constructor Detail

      • GuiseHTTPServlet

        public GuiseHTTPServlet()
        Default constructor. Creates a single Guise application.
    • Method Detail

      • getGuiseContainer

        protected HTTPServletGuiseContainer getGuiseContainer()
        Returns the Guise container. This method must not be called before a request is processed.
        Returns:
        The Guise container that owns the applications.
        Throws:
        java.lang.IllegalStateException - if this method is called before any requests have been processed.
      • getGuiseApplication

        protected AbstractGuiseApplication getGuiseApplication()
        Returns:
        The Guise application controlled by this servlet.
      • getELFF

        public com.globalmentor.text.elff.ELFF getELFF()
        Returns:
        The ELFF logger for this application.
      • initialize

        public void initialize​(javax.servlet.ServletConfig servletConfig)
                        throws javax.servlet.ServletException,
                               java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException

        This version initializes the Guise application.

        Overrides:
        initialize in class com.globalmentor.servlet.http.BaseHTTPServlet
        Throws:
        javax.servlet.ServletException
        java.lang.IllegalArgumentException
        java.lang.IllegalStateException
      • initGuiseApplication

        protected AbstractGuiseApplication initGuiseApplication​(javax.servlet.ServletConfig servletConfig)
                                                         throws javax.servlet.ServletException
        Initializes bindings between paths and associated navigation frame classes.
        Parameters:
        servletConfig - The servlet configuration.
        Returns:
        The new initialized application.
        Throws:
        java.lang.IllegalArgumentException - if the one of the frame bindings is not expressed in correct format.
        java.lang.IllegalArgumentException - if the one of the classes specified as a frame binding could not be found.
        java.lang.IllegalArgumentException - if the one of the classes specified as a frame binding could not be found.
        java.lang.ClassCastException - if the one of the classes specified as a frame binding does not represent a subclass of a frame component.
        javax.servlet.ServletException - if there is a problem initializing the application or frame bindings.
        See Also:
        Frame
      • initialize

        public void initialize​(javax.servlet.http.HttpServletRequest request)
                        throws javax.servlet.ServletException

        This version installs the application into the container.

        Overrides:
        initialize in class com.globalmentor.servlet.http.BaseHTTPServlet
        Throws:
        javax.servlet.ServletException
      • doGet

        public void doGet​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws javax.servlet.ServletException,
                          java.io.IOException
        Overrides:
        doGet in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • doPut

        public void doPut​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws javax.servlet.ServletException,
                          java.io.IOException
        Overrides:
        doPut in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • redirect

        protected void redirect​(HTTPServletGuiseRequest guiseRequest,
                                GuiseApplication guiseApplication,
                                RedirectDestination redirectDestination,
                                Bookmark bookmark)
                         throws com.globalmentor.net.http.HTTPRedirectException
        Processes a redirect from a redirect destination. This method will unconditionally throw an exception. Under normal circumstances, an HTTPRedirectException will be thrown.
        Parameters:
        guiseRequest - The Guise request information.
        guiseApplication - The Guise application.
        redirectDestination - The destination indicating how and to where redirection should occur.
        bookmark - The requested bookmark, or null if no bookmark is requested
        Throws:
        java.lang.IllegalArgumentException - if the referenced destination does not specify a path (instead specifying a path pattern, for example).
        com.globalmentor.net.http.HTTPRedirectException - unconditionally to indicate how and to where redirection should occur.
      • redirect

        protected void redirect​(HTTPServletGuiseRequest guiseRequest,
                                GuiseApplication guiseApplication,
                                java.net.URI redirectNavigationURI,
                                Bookmark bookmark,
                                boolean permanent)
                         throws com.globalmentor.net.http.HTTPRedirectException
        Redirects to the given navigation path, preserving the given bookmark. This method will unconditionally throw an exception. Under normal circumstances, an HTTPRedirectException will be thrown.
        Parameters:
        guiseRequest - The Guise request information.
        guiseApplication - The Guise application.
        redirectNavigationURI - The absolute or application-relative URI to which redirection should occur in navigation space.
        bookmark - The requested bookmark, or null if no bookmark is requested
        permanent - true if the redirect should be permanent.
        Throws:
        com.globalmentor.net.http.HTTPRedirectException - unconditionally to indicate how and to where redirection should occur.
      • synchronizeCookies

        protected void synchronizeCookies​(javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          GuiseSession guiseSession)
        Synchronizes the cookies in a request with the environment properties in a Guise session. Any cookies missing from the request will be added from the environment to the response.
        Parameters:
        request - The HTTP request.
        response - The HTTP response.
        guiseSession - The Guise session.
      • serveResource

        protected void serveResource​(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response,
                                     com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource resource,
                                     boolean serveContent)
                              throws javax.servlet.ServletException,
                                     java.io.IOException
        Overrides:
        serveResource in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • getComponentsByDepictName

        protected void getComponentsByDepictName​(Component component,
                                                 java.lang.String depictName,
                                                 java.util.Set<Component> componentSet)
        Retrieves all descendant components, including the given component, that have a given depict name.
        Parameters:
        component - The component to check, along with all descendants, for components with the given depict name.
        depictName - The name for which to check.
        componentSet - The set of components collecting the components with the given depict name.
        Throws:
        java.lang.NullPointerException - if the given depict name is null.
        See Also:
        WebComponentDepictor.getDepictName()
      • getRequestEvents

        protected java.util.List<GuiseEvent> getRequestEvents​(HTTPServletGuiseRequest guiseRequest,
                                                              GuiseSession guiseSession,
                                                              DepictContext depictContext)
                                                       throws java.io.IOException
        Retrieves events from the HTTP request.
        Parameters:
        guiseRequest - The HTTP request.
        guiseSession - The Guise session object.
        depictContext - The platform depict object.
        Returns:
        The events from the HTTP request.
        Throws:
        java.io.IOException - if there is an error reading or writing data.
      • beginModalNavigation

        protected void beginModalNavigation​(GuiseApplication guiseApplication,
                                            GuiseSession guiseSession,
                                            ModalNavigation modalNavigation)
        Begins modal navigation based upon modal navigation information.
        Parameters:
        guiseApplication - The Guise application.
        guiseSession - The Guise session.
        modalNavigation - The modal navigation information
      • destroy

        public void destroy()

        This version uninstalls the Guise application from the Guise container.

        Specified by:
        destroy in interface javax.servlet.Servlet
        Overrides:
        destroy in class com.globalmentor.servlet.http.BaseHTTPServlet
      • getPrincipal

        protected java.security.Principal getPrincipal​(java.lang.String id)
                                                throws com.globalmentor.net.http.HTTPInternalServerErrorException

        This version delegates to the Guise container.

        Overrides:
        getPrincipal in class com.globalmentor.servlet.http.BaseHTTPServlet
        Throws:
        com.globalmentor.net.http.HTTPInternalServerErrorException
      • getPassword

        protected char[] getPassword​(java.security.Principal principal)
                              throws com.globalmentor.net.http.HTTPInternalServerErrorException

        This version delegates to the Guise container.

        Overrides:
        getPassword in class com.globalmentor.servlet.http.BaseHTTPServlet
        Throws:
        com.globalmentor.net.http.HTTPInternalServerErrorException
      • getRealm

        protected java.lang.String getRealm​(java.net.URI resourceURI)
                                     throws com.globalmentor.net.http.HTTPInternalServerErrorException

        This version delegates to the container.

        Overrides:
        getRealm in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        com.globalmentor.net.http.HTTPInternalServerErrorException
      • isAuthorized

        protected boolean isAuthorized​(javax.servlet.http.HttpServletRequest request,
                                       java.net.URI resourceURI,
                                       java.lang.String method,
                                       java.security.Principal principal,
                                       java.lang.String realm)
                                throws com.globalmentor.net.http.HTTPInternalServerErrorException

        This version delegates to the Guise container, using the principal of the current Guise session instead of the given principal. This technique allows browser-based authentication to function normally (as successful authentication will have already updated the session's principal), and also allows browser-based authentication to work with session-based authentication in the even that the session has already authenticated a principal unknown to the browser.

        Overrides:
        isAuthorized in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        com.globalmentor.net.http.HTTPInternalServerErrorException
      • isValid

        protected boolean isValid​(javax.servlet.http.HttpServletRequest request,
                                  com.globalmentor.security.Nonce nonce)
        Determines if the given nonce is valid. This version counts a nonce as invalid if it was associated with a different principal than the current Guise session principal (i.e. the Guise principal was logged out).
        Overrides:
        isValid in class com.globalmentor.servlet.http.BaseHTTPServlet
        Parameters:
        request - The HTTP request.
        nonce - The nonce to check for validity.
        Returns:
        true if the nonce is not valid.
      • authenticated

        protected void authenticated​(javax.servlet.http.HttpServletRequest request,
                                     java.net.URI resourceURI,
                                     java.lang.String method,
                                     java.lang.String requestURI,
                                     java.security.Principal principal,
                                     java.lang.String realm,
                                     com.globalmentor.net.http.AuthenticateCredentials credentials,
                                     boolean authenticated)

        This version stores the authenticated principal in the current Guise session if authentication was successful for valid credentials.

        Overrides:
        authenticated in class com.globalmentor.servlet.http.BaseHTTPServlet
      • canSubstitute

        protected boolean canSubstitute​(javax.servlet.http.HttpServletRequest request,
                                        java.net.URI requestedResourceURI,
                                        java.net.URI substituteResourceURI)
                                 throws java.io.IOException

        This version prevents redirects from a registered Guise destination.

        Overrides:
        canSubstitute in class com.globalmentor.servlet.http.AbstractHTTPServlet<com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource>
        Throws:
        java.io.IOException
      • exists

        protected boolean exists​(javax.servlet.http.HttpServletRequest request,
                                 java.net.URI resourceURI)
                          throws java.io.IOException

        This version adds checks to see if the URI represents a valid application navigation path. This version adds support for Guise public resources.

        Overrides:
        exists in class com.globalmentor.servlet.http.DefaultHTTPServlet
        Throws:
        java.io.IOException
      • getResource

        protected com.globalmentor.servlet.http.DefaultHTTPServlet.HTTPServletResource getResource​(javax.servlet.http.HttpServletRequest request,
                                                                                                   java.net.URI resourceURI)
                                                                                            throws java.lang.IllegalArgumentException,
                                                                                                   java.io.IOException

        This version adds support for Guise public and temporary resources; and destination resources.

        Overrides:
        getResource in class com.globalmentor.servlet.http.DefaultHTTPServlet
        Throws:
        java.lang.IllegalArgumentException
        java.io.IOException