Targeted URL Stream Handler Plugin Extension
This plugin extension can handle the following protocols: http
,
https
, ftp
or sftp
, for which Oxygen XML Developer plugin usually provides specific fixed URL stream handlers. If it is set to
handle connections for a specific protocol, this extension will be asked to provide
the URL
stream handler for each opened connection of a URL having that protocol.
To use this type of plugin, you have to implement the
ro.sync.exml.plugin.urlstreamhandler.TargetedURLStreamHandlerPluginExtension
interface, that provides the following methods:
boolean canHandleProtocol(String protocol)
This method checks if the plugin can handle a specific protocol. If this method returns
true
for a specific protocol, thegetURLStreamHandler(URL)
method will be called for each opened connection of a URL having this protocol.URLStreamHandler getURLStreamHandler(URL url)
This method provides the URL handler for the specified URL and it is called for each opened connection of a URL with a protocol for which the
canHandleProtocol(String)
method returnstrue
.If this method returns
null
, the default Oxygen XML Developer pluginURLStreamHandler
is used.
TargetedURLHandler
type in your plugin.xml
and specify
the class that implements
TargetedURLStreamHandlerPluginExtension
:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plugin SYSTEM "../plugin.dtd"> <plugin name="CustomTargetedURLStreamHandlerPlugin" ..............> <runtime> ........ </runtime> <extension type="TargetedURLHandler" class="CustomTargetedURLStreamHandlerPluginExtension"/> ............... </plugin>
This extension can be useful in situations when connections opened from a specific
host must
be handled in a particular way. For example, the Oxygen XML Developer plugin
HTTP URLStreamHandler
may not be compatible for sending and receiving SOAP
using the SUN Web Services implementation. In this case, you can override the stream
handler
(set by Oxygen XML Developer plugin) to use the default SUN URLStreamHandler
,
since it is more compatible with sending and receiving SOAP requests.
public class CustomTargetedURLStreamHandlerPluginExtension implements TargetedURLStreamHandlerPluginExtension { @Override public boolean canHandleProtocol(String protocol) { boolean handleProtocol = false; if ("http".equals(protocol) || "https".equals(protocol)) { // This extension handles both HTTP and HTTPS protocols handleProtocol = true; } return handleProtocol; } @Override public URLStreamHandler getURLStreamHandler(URL url) { // This method is called only for the URLs with a protocol // where canHandleProtocol(String) method returns true (HTTP and HTTPS) URLStreamHandler handler = null; String host = url.getHost(); String protocol = url.getProtocol(); if ("some_host".equals(host)) { // When there are connections opened from some_host, the SUN HTTP(S) // handlers are used if ("http".equals(protocol)) { handler = new sun.net.www.protocol.http.Handler(); } else { handler = new sun.net.www.protocol.https.Handler(); } } return handler; } }