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 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected String
getContextId
(UserContext context) Computes the context id based on the user context.int
protected boolean
hostsEqual
(URL u1, URL u2) protected final URLConnection
protected final URLConnection
openConnection
(URL u, Proxy p) protected abstract URLConnection
openConnectionInContext
(String contextId, URL url, 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
-
Constructor Details
-
URLStreamHandlerWithContext
protected URLStreamHandlerWithContext()Constructor. It uses the session cookie of the Servlet container as a context id.
-
-
Method Details
-
getContextId
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
- Overrides:
openConnection
in classURLStreamHandler
- Throws:
IOException
- See Also:
-
openConnection
- Specified by:
openConnection
in classURLStreamHandler
- Throws:
IOException
- See Also:
-
openConnectionInContext
protected abstract URLConnection openConnectionInContext(String contextId, URL url, Proxy proxy) throws 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:
IOException
- If the connection fails.
-
hashCode
- Overrides:
hashCode
in classURLStreamHandler
- See Also:
-
hostsEqual
- Overrides:
hostsEqual
in classURLStreamHandler
- See Also:
-