2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package sun.net.www.protocol.http;
20 import gov.nasa.jpf.CachedROHttpConnection;
22 import java.io.IOException;
23 import java.lang.reflect.Constructor;
24 import java.lang.reflect.InvocationTargetException;
25 import java.net.Proxy;
29 * replaced handler to support configured URLConnection classes
31 public class Handler extends java.net.URLStreamHandler {
33 protected String proxy;
34 protected int proxyPort;
41 public Handler(String proxy, int port) {
43 this.proxyPort = port;
47 protected int getDefaultPort() {
52 static Class<?>[] argTypes = { URL.class, Proxy.class };
53 private native Class<? extends java.net.URLConnection> getConnectionClass(String url);
57 protected java.net.URLConnection openConnection (URL u, Proxy p) throws IOException {
59 Class<? extends java.net.URLConnection> clazz = getConnectionClass(u.toString());
63 Constructor<? extends java.net.URLConnection> ctor = clazz.getConstructor(argTypes);
64 return ctor.newInstance(u, p);
66 } catch (NoSuchMethodException nmx){
67 throw new IOException("connection class has no suitabe ctor: " + clazz.getName());
68 } catch (IllegalAccessException iax){
69 throw new IOException("connection class has no public ctor: " + clazz.getName());
70 } catch (InvocationTargetException itx){
71 throw new IOException("exception initializing URLConnection", itx);
72 } catch (InstantiationException ix){
73 throw new IOException("connection class cannot be instantiated: " + clazz.getName());
77 // we just go with the standard thing, hoping that we have a modeled Socket layer
78 return new CachedROHttpConnection(u, p, this);
83 protected java.net.URLConnection openConnection(URL u) throws IOException {
84 return openConnection(u, null);
87 //... and a lot of methods still missing