Source Code Cross Referenced for Handler.java in  » Net » jCIFS » jcifs » http » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » jCIFS » jcifs.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* jcifs smb client library in Java
002:         * Copyright (C) 2002  "Michael B. Allen" <jcifs at samba dot org>
003:         *                   "Eric Glass" <jcifs at samba dot org>
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:
020:        package jcifs.http;
021:
022:        import java.io.IOException;
023:
024:        import java.net.HttpURLConnection;
025:        import java.net.URL;
026:        import java.net.URLConnection;
027:        import java.net.URLStreamHandler;
028:        import java.net.URLStreamHandlerFactory;
029:
030:        import java.util.HashMap;
031:        import java.util.Map;
032:        import java.util.StringTokenizer;
033:
034:        /**
035:         * A <code>URLStreamHandler</code> used to provide NTLM authentication
036:         * capabilities to the default HTTP handler.  This acts as a wrapper,
037:         * handling authentication and passing control to the underlying
038:         * stream handler.
039:         */
040:        public class Handler extends URLStreamHandler {
041:
042:            /**
043:             * The default HTTP port (<code>80</code>).
044:             */
045:            public static final int DEFAULT_HTTP_PORT = 80;
046:
047:            private static final Map PROTOCOL_HANDLERS = new HashMap();
048:
049:            private static final String HANDLER_PKGS_PROPERTY = "java.protocol.handler.pkgs";
050:
051:            /**
052:             * Vendor-specific default packages.  If no packages are specified in
053:             * "java.protocol.handler.pkgs", the VM uses one or more default
054:             * packages, which are vendor specific.  Sun's is included below
055:             * for convenience; others could be as well.  If a particular vendor's
056:             * package isn't listed, it can be specified in
057:             * "java.protocol.handler.pkgs".
058:             */
059:            private static final String[] JVM_VENDOR_DEFAULT_PKGS = new String[] { "sun.net.www.protocol" };
060:
061:            private static URLStreamHandlerFactory factory;
062:
063:            /**
064:             * Sets the URL stream handler factory for the environment.  This
065:             * allows specification of the factory used in creating underlying
066:             * stream handlers.  This can be called once per JVM instance.
067:             *
068:             * @param factory The URL stream handler factory.
069:             */
070:            public static void setURLStreamHandlerFactory(
071:                    URLStreamHandlerFactory factory) {
072:                synchronized (PROTOCOL_HANDLERS) {
073:                    if (Handler.factory != null) {
074:                        throw new IllegalStateException(
075:                                "URLStreamHandlerFactory already set.");
076:                    }
077:                    PROTOCOL_HANDLERS.clear();
078:                    Handler.factory = factory;
079:                }
080:            }
081:
082:            /**
083:             * Returns the default HTTP port.
084:             *
085:             * @return An <code>int</code> containing the default HTTP port.
086:             */
087:            protected int getDefaultPort() {
088:                return DEFAULT_HTTP_PORT;
089:            }
090:
091:            protected URLConnection openConnection(URL url) throws IOException {
092:                url = new URL(url, url.toExternalForm(),
093:                        getDefaultStreamHandler(url.getProtocol()));
094:                return new NtlmHttpURLConnection((HttpURLConnection) url
095:                        .openConnection());
096:            }
097:
098:            private static URLStreamHandler getDefaultStreamHandler(
099:                    String protocol) throws IOException {
100:                synchronized (PROTOCOL_HANDLERS) {
101:                    URLStreamHandler handler = (URLStreamHandler) PROTOCOL_HANDLERS
102:                            .get(protocol);
103:                    if (handler != null)
104:                        return handler;
105:                    if (factory != null) {
106:                        handler = factory.createURLStreamHandler(protocol);
107:                    }
108:                    if (handler == null) {
109:                        String path = System.getProperty(HANDLER_PKGS_PROPERTY);
110:                        StringTokenizer tokenizer = new StringTokenizer(path,
111:                                "|");
112:                        while (tokenizer.hasMoreTokens()) {
113:                            String provider = tokenizer.nextToken().trim();
114:                            if (provider.equals("jcifs"))
115:                                continue;
116:                            String className = provider + "." + protocol
117:                                    + ".Handler";
118:                            try {
119:                                Class handlerClass = null;
120:                                try {
121:                                    handlerClass = Class.forName(className);
122:                                } catch (Exception ex) {
123:                                }
124:                                if (handlerClass == null) {
125:                                    handlerClass = ClassLoader
126:                                            .getSystemClassLoader().loadClass(
127:                                                    className);
128:                                }
129:                                handler = (URLStreamHandler) handlerClass
130:                                        .newInstance();
131:                                break;
132:                            } catch (Exception ex) {
133:                            }
134:                        }
135:                    }
136:                    if (handler == null) {
137:                        for (int i = 0; i < JVM_VENDOR_DEFAULT_PKGS.length; i++) {
138:                            String className = JVM_VENDOR_DEFAULT_PKGS[i] + "."
139:                                    + protocol + ".Handler";
140:                            try {
141:                                Class handlerClass = null;
142:                                try {
143:                                    handlerClass = Class.forName(className);
144:                                } catch (Exception ex) {
145:                                }
146:                                if (handlerClass == null) {
147:                                    handlerClass = ClassLoader
148:                                            .getSystemClassLoader().loadClass(
149:                                                    className);
150:                                }
151:                                handler = (URLStreamHandler) handlerClass
152:                                        .newInstance();
153:                            } catch (Exception ex) {
154:                            }
155:                            if (handler != null)
156:                                break;
157:                        }
158:                    }
159:                    if (handler == null) {
160:                        throw new IOException(
161:                                "Unable to find default handler for protocol: "
162:                                        + protocol);
163:                    }
164:                    PROTOCOL_HANDLERS.put(protocol, handler);
165:                    return handler;
166:                }
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.