This type of plugin can be used when it is necessary to impose custom URL stream handlers for specific URLs.
This plugin extension can handle the following protocols: http, https, ftp or sftp, for which Oxygen XML 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 an URL having that protocol.
This method checks if the plugin can handle a specific protocol. If this method returns true for a specific protocol, the getURLStreamHandler(URL) method will be called for each opened connection of an URL having this protocol.
This method provides the URL handler for the specified URL and it is called for each opened connection of an URL with a protocol for which the canHandleProtocol(String) method returns true.
If this method returns null, the Oxygen URLStreamHandler is used.
<?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 HTTP URLStreamHandler may not be compatible for sending and receiving SOAP using the SUN Webservices implementation. In this case you can override the stream handler set by Oxygen for HTTP to use the default SUN URLStreamHandler which 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 // for which the 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; } }