Class URLStreamHandlerWithContext


  • @API(src=PUBLIC,
         type=EXTENDABLE)
    public abstract class URLStreamHandlerWithContext
    extends java.net.URLStreamHandler
    A base-class for URLStreamHandlers that need a context for the URL whose connection is to be opened. It is implemented by adding a user context id to the URL in the userInfo section. The context id should remain unchanged while the user edits a document. The user context contains information about the cookies and HTTP headers sent by the user. For openConnection calls, the context id passed along. You can use it to retrieve information about the user on behalf of which the request is made.
    Since:
    17
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String getContextId​(UserContext context)
      Computes the context id based on the user context.
      int hashCode​(java.net.URL u)  
      protected boolean hostsEqual​(java.net.URL u1, java.net.URL u2)  
      protected java.net.URLConnection openConnection​(java.net.URL u)  
      protected java.net.URLConnection openConnection​(java.net.URL u, java.net.Proxy p)  
      protected abstract java.net.URLConnection openConnectionInContext​(java.lang.String contextId, java.net.URL url, java.net.Proxy proxy)
      This method has the same purpose as openConnection() in a standard URLConnection except that the context is also passed in.
      • Methods inherited from class java.net.URLStreamHandler

        equals, getDefaultPort, getHostAddress, parseURL, sameFile, setURL, setURL, toExternalForm
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URLStreamHandlerWithContext

        protected URLStreamHandlerWithContext()
        Constructor. It uses the session cookie of the Servlet container as a context id.
    • Method Detail

      • getContextId

        protected java.lang.String getContextId​(UserContext context)
        Computes the context id based on the user context. By default, it uses the id of the session managed by the Servlet container.
        Parameters:
        context - The UserContext.
        Returns:
        The context id.
      • openConnection

        protected final java.net.URLConnection openConnection​(java.net.URL u,
                                                              java.net.Proxy p)
                                                       throws java.io.IOException
        Overrides:
        openConnection in class java.net.URLStreamHandler
        Throws:
        java.io.IOException
        See Also:
        URLStreamHandler.openConnection(java.net.URL, java.net.Proxy)
      • openConnection

        protected final java.net.URLConnection openConnection​(java.net.URL u)
                                                       throws java.io.IOException
        Specified by:
        openConnection in class java.net.URLStreamHandler
        Throws:
        java.io.IOException
        See Also:
        URLStreamHandler.openConnection(java.net.URL)
      • openConnectionInContext

        protected abstract java.net.URLConnection openConnectionInContext​(java.lang.String contextId,
                                                                          java.net.URL url,
                                                                          java.net.Proxy proxy)
                                                                   throws java.io.IOException
        This method has the same purpose as openConnection() in a standard URLConnection except that the context is also passed in. If the connection, or one of the following IO operations on it need some user interaction like providing credentials, they should throw an IOException that also implements the UserActionRequiredException. The message of the IOException will still be rendered in different places, but the instance of WebappMessage found in the UserActionRequiredException will be used to present an authentication dialog to the users. This message needs to be handled in JavaScript by the plugin code. If no JS handler is registered, the message will just be displayed in the browser console.
        Parameters:
        contextId - The id of the context.
        url - The URL to connect to.
        proxy - The proxy to use. May be null.
        Returns:
        The connection.
        Throws:
        java.io.IOException - If the connection fails.
      • hashCode

        public int hashCode​(java.net.URL u)
        Overrides:
        hashCode in class java.net.URLStreamHandler
        See Also:
        URLStreamHandler.hashCode(java.net.URL)
      • hostsEqual

        protected boolean hostsEqual​(java.net.URL u1,
                                     java.net.URL u2)
        Overrides:
        hostsEqual in class java.net.URLStreamHandler
        See Also:
        URLStreamHandler.hostsEqual(java.net.URL, java.net.URL)