FileDocCategorySizeDatePackage
Handler.javaAPI DocJCIFS 1.3.17 API6370Tue Oct 18 15:26:24 BST 2011jcifs.http

Handler

public class Handler extends URLStreamHandler
A URLStreamHandler used to provide NTLM authentication capabilities to the default HTTP handler. This acts as a wrapper, handling authentication and passing control to the underlying stream handler.

Fields Summary
public static final int
DEFAULT_HTTP_PORT
The default HTTP port (80).
private static final Map
PROTOCOL_HANDLERS
private static final String
HANDLER_PKGS_PROPERTY
private static final String[]
JVM_VENDOR_DEFAULT_PKGS
Vendor-specific default packages. If no packages are specified in "java.protocol.handler.pkgs", the VM uses one or more default packages, which are vendor specific. Sun's is included below for convenience; others could be as well. If a particular vendor's package isn't listed, it can be specified in "java.protocol.handler.pkgs".
private static URLStreamHandlerFactory
factory
Constructors Summary
Methods Summary
protected intgetDefaultPort()
Returns the default HTTP port.

return
An int containing the default HTTP port.

        return DEFAULT_HTTP_PORT;
    
private static java.net.URLStreamHandlergetDefaultStreamHandler(java.lang.String protocol)

        synchronized (PROTOCOL_HANDLERS) {
            URLStreamHandler handler = (URLStreamHandler)
                    PROTOCOL_HANDLERS.get(protocol);
            if (handler != null) return handler;
            if (factory != null) {
                handler = factory.createURLStreamHandler(protocol);
            }
            if (handler == null) {
                String path = System.getProperty(HANDLER_PKGS_PROPERTY);
                StringTokenizer tokenizer = new StringTokenizer(path, "|");
                while (tokenizer.hasMoreTokens()) {
                    String provider = tokenizer.nextToken().trim();
                    if (provider.equals("jcifs")) continue;
                    String className = provider + "." + protocol + ".Handler";
                    try {
                        Class handlerClass = null;
                        try {
                            handlerClass = Class.forName(className);
                        } catch (Exception ex) { }
                        if (handlerClass == null) {
                            handlerClass = ClassLoader.getSystemClassLoader(
                                    ).loadClass(className);
                        }
                        handler = (URLStreamHandler) handlerClass.newInstance();
                        break;
                    } catch (Exception ex) { }
                }
            }
            if (handler == null) {
                for (int i = 0; i < JVM_VENDOR_DEFAULT_PKGS.length; i++) {
                    String className = JVM_VENDOR_DEFAULT_PKGS[i] + "." +
                            protocol + ".Handler";
                    try {
                        Class handlerClass = null;
                        try {
                            handlerClass = Class.forName(className);
                        } catch (Exception ex) { }
                        if (handlerClass == null) {
                            handlerClass = ClassLoader.getSystemClassLoader(
                                    ).loadClass(className);
                        }
                        handler = (URLStreamHandler) handlerClass.newInstance();
                    } catch (Exception ex) { }
                    if (handler != null) break;
                }
            }
            if (handler == null) {
                throw new IOException(
                        "Unable to find default handler for protocol: " +
                                protocol);
            }
            PROTOCOL_HANDLERS.put(protocol, handler);
            return handler;
        }
    
protected java.net.URLConnectionopenConnection(java.net.URL url)

        url = new URL(url, url.toExternalForm(),
                getDefaultStreamHandler(url.getProtocol()));
        return new NtlmHttpURLConnection((HttpURLConnection)
                url.openConnection());
    
public static voidsetURLStreamHandlerFactory(java.net.URLStreamHandlerFactory factory)
Sets the URL stream handler factory for the environment. This allows specification of the factory used in creating underlying stream handlers. This can be called once per JVM instance.

param
factory The URL stream handler factory.


                                               
       
              
        synchronized (PROTOCOL_HANDLERS) {
            if (Handler.factory != null) {
                throw new IllegalStateException(
                        "URLStreamHandlerFactory already set.");
            }
            PROTOCOL_HANDLERS.clear();
            Handler.factory = factory;
        }