Class URLStreamHandlerWithContext
- java.lang.Object
-
- java.net.URLStreamHandler
-
- ro.sync.ecss.extensions.api.webapp.plugin.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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
URLStreamHandlerWithContext()
Constructor.
-
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.
-
-
-
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 classjava.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 classjava.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 classjava.net.URLStreamHandler
- See Also:
URLStreamHandler.hashCode(java.net.URL)
-
hostsEqual
protected boolean hostsEqual(java.net.URL u1, java.net.URL u2)
- Overrides:
hostsEqual
in classjava.net.URLStreamHandler
- See Also:
URLStreamHandler.hostsEqual(java.net.URL, java.net.URL)
-
-