1 /*
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
64 private static HttpServerProvider provider = null;
65
66 /**
67 * Initializes a new instance of this class. </p>
68 *
69 * @throws SecurityException
70 * If a security manager has been installed and it denies
71 * {@link RuntimePermission}<tt>("httpServerProvider")</tt>
72 */
73 protected HttpServerProvider() {
74 SecurityManager sm = System.getSecurityManager();
75 if (sm != null)
76 sm.checkPermission(new RuntimePermission("httpServerProvider"));
77 }
78
79 private static boolean loadProviderFromProperty() {
80 String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
81 if (cn == null)
82 return false;
83 try {
84 Class c = Class.forName(cn, true,
85 ClassLoader.getSystemClassLoader());
86 provider = (HttpServerProvider)c.newInstance();
87 return true;
88 } catch (ClassNotFoundException x) {
89 throw new ServiceConfigurationError(x);
90 } catch (IllegalAccessException x) {
91 throw new ServiceConfigurationError(x);
92 } catch (InstantiationException x) {
93 throw new ServiceConfigurationError(x);
94 } catch (SecurityException x) {
95 throw new ServiceConfigurationError(x);
96 }
97 }
98
99 private static boolean loadProviderAsService() {
100 Iterator i = Service.providers(HttpServerProvider.class,
101 ClassLoader.getSystemClassLoader());
102 for (;;) {
103 try {
104 if (!i.hasNext())
105 return false;
106 provider = (HttpServerProvider)i.next();
107 return true;
108 } catch (ServiceConfigurationError sce) {
109 if (sce.getCause() instanceof SecurityException) {
110 // Ignore the security exception, try the next provider
111 continue;
112 }
113 throw sce;
114 }
115 }
116 }
117
118 /**
119 * Returns the system wide default HttpServerProvider for this invocation of
120 * the Java virtual machine.
121 *
122 * <p> The first invocation of this method locates the default provider
123 * object as follows: </p>
124 *
125 * <ol>
126 *
|
1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
64 private static HttpServerProvider provider = null;
65
66 /**
67 * Initializes a new instance of this class. </p>
68 *
69 * @throws SecurityException
70 * If a security manager has been installed and it denies
71 * {@link RuntimePermission}<tt>("httpServerProvider")</tt>
72 */
73 protected HttpServerProvider() {
74 SecurityManager sm = System.getSecurityManager();
75 if (sm != null)
76 sm.checkPermission(new RuntimePermission("httpServerProvider"));
77 }
78
79 private static boolean loadProviderFromProperty() {
80 String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
81 if (cn == null)
82 return false;
83 try {
84 Class<?> c = Class.forName(cn, true,
85 ClassLoader.getSystemClassLoader());
86 provider = (HttpServerProvider)c.newInstance();
87 return true;
88 } catch (ClassNotFoundException x) {
89 throw new ServiceConfigurationError(x);
90 } catch (InstantiationException x) {
91 throw new ServiceConfigurationError(x);
92 } catch (IllegalAccessException x) {
93 throw new ServiceConfigurationError(x);
94 } catch (SecurityException x) {
95 throw new ServiceConfigurationError(x);
96 }
97 }
98
99 private static boolean loadProviderAsService() {
100 @SuppressWarnings("unchecked")
101 Iterator<HttpServerProvider> i = Service.providers(HttpServerProvider.class,
102 ClassLoader.getSystemClassLoader());
103 for (;;) {
104 try {
105 if (!i.hasNext())
106 return false;
107 provider = i.next();
108 return true;
109 } catch (ServiceConfigurationError sce) {
110 if (sce.getCause() instanceof SecurityException) {
111 // Ignore the security exception, try the next provider
112 continue;
113 }
114 throw sce;
115 }
116 }
117 }
118
119 /**
120 * Returns the system wide default HttpServerProvider for this invocation of
121 * the Java virtual machine.
122 *
123 * <p> The first invocation of this method locates the default provider
124 * object as follows: </p>
125 *
126 * <ol>
127 *
|