1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.transport.http;
44
45 import java.io.IOException;
46 import java.io.InputStream;
47 import java.io.OutputStream;
48 import java.net.HttpURLConnection;
49 import java.net.MalformedURLException;
50 import java.net.ProtocolException;
51 import java.net.Proxy;
52 import java.net.URL;
53 import java.security.KeyManagementException;
54 import java.security.NoSuchAlgorithmException;
55 import java.security.SecureRandom;
56 import java.util.List;
57 import java.util.Map;
58
59 import javax.net.ssl.HostnameVerifier;
60 import javax.net.ssl.HttpsURLConnection;
61 import javax.net.ssl.KeyManager;
62 import javax.net.ssl.SSLContext;
63 import javax.net.ssl.TrustManager;
64
65
66
67
68
69
70
71 public class JDKHttpConnection implements HttpConnection {
72 HttpURLConnection wrappedUrlConnection;
73
74
75
76
77
78
79 protected JDKHttpConnection(URL url)
80 throws MalformedURLException,
81 IOException {
82 this.wrappedUrlConnection = (HttpURLConnection) url.openConnection();
83 }
84
85
86
87
88
89
90
91 protected JDKHttpConnection(URL url, Proxy proxy)
92 throws MalformedURLException, IOException {
93 this.wrappedUrlConnection = (HttpURLConnection) url
94 .openConnection(proxy);
95 }
96
97 public int getResponseCode() throws IOException {
98 return wrappedUrlConnection.getResponseCode();
99 }
100
101 public URL getURL() {
102 return wrappedUrlConnection.getURL();
103 }
104
105 public String getResponseMessage() throws IOException {
106 return wrappedUrlConnection.getResponseMessage();
107 }
108
109 public Map<String, List<String>> getHeaderFields() {
110 return wrappedUrlConnection.getHeaderFields();
111 }
112
113 public void setRequestProperty(String key, String value) {
114 wrappedUrlConnection.setRequestProperty(key, value);
115 }
116
117 public void setRequestMethod(String method) throws ProtocolException {
118 wrappedUrlConnection.setRequestMethod(method);
119 }
120
121 public void setUseCaches(boolean usecaches) {
122 wrappedUrlConnection.setUseCaches(usecaches);
123 }
124
125 public void setConnectTimeout(int timeout) {
126 wrappedUrlConnection.setConnectTimeout(timeout);
127 }
128
129 public void setReadTimeout(int timeout) {
130 wrappedUrlConnection.setReadTimeout(timeout);
131 }
132
133 public String getContentType() {
134 return wrappedUrlConnection.getContentType();
135 }
136
137 public InputStream getInputStream() throws IOException {
138 return wrappedUrlConnection.getInputStream();
139 }
140
141 public String getHeaderField(String name) {
142 return wrappedUrlConnection.getHeaderField(name);
143 }
144
145 public int getContentLength() {
146 return wrappedUrlConnection.getContentLength();
147 }
148
149 public void setInstanceFollowRedirects(boolean followRedirects) {
150 wrappedUrlConnection.setInstanceFollowRedirects(followRedirects);
151 }
152
153 public void setDoOutput(boolean dooutput) {
154 wrappedUrlConnection.setDoOutput(dooutput);
155 }
156
157 public void setFixedLengthStreamingMode(int contentLength) {
158 wrappedUrlConnection.setFixedLengthStreamingMode(contentLength);
159 }
160
161 public OutputStream getOutputStream() throws IOException {
162 return wrappedUrlConnection.getOutputStream();
163 }
164
165 public void setChunkedStreamingMode(int chunklen) {
166 wrappedUrlConnection.setChunkedStreamingMode(chunklen);
167 }
168
169 public String getRequestMethod() {
170 return wrappedUrlConnection.getRequestMethod();
171 }
172
173 public boolean usingProxy() {
174 return wrappedUrlConnection.usingProxy();
175 }
176
177 public void connect() throws IOException {
178 wrappedUrlConnection.connect();
179 }
180
181 public void setHostnameVerifier(HostnameVerifier hostnameverifier) {
182 ((HttpsURLConnection) wrappedUrlConnection)
183 .setHostnameVerifier(hostnameverifier);
184 }
185
186 public void configure(KeyManager[] km, TrustManager[] tm,
187 SecureRandom random) throws NoSuchAlgorithmException,
188 KeyManagementException {
189 SSLContext ctx = SSLContext.getInstance("TLS");
190 ctx.init(km, tm, random);
191 ((HttpsURLConnection) wrappedUrlConnection).setSSLSocketFactory(ctx
192 .getSocketFactory());
193 }
194 }