You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HttpConnection.java 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2013 Christian Halstrick <christian.halstrick@sap.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.transport.http;
  44. import java.io.IOException;
  45. import java.io.InputStream;
  46. import java.io.OutputStream;
  47. import java.net.HttpURLConnection;
  48. import java.net.ProtocolException;
  49. import java.net.URL;
  50. import java.security.KeyManagementException;
  51. import java.security.NoSuchAlgorithmException;
  52. import java.security.SecureRandom;
  53. import java.util.List;
  54. import java.util.Map;
  55. import javax.net.ssl.HostnameVerifier;
  56. import javax.net.ssl.KeyManager;
  57. import javax.net.ssl.SSLContext;
  58. import javax.net.ssl.TrustManager;
  59. /**
  60. * The interface of connections used during HTTP communication. This interface
  61. * is that subset of the interface exposed by {@link HttpURLConnection} which is
  62. * used by JGit
  63. *
  64. * @since 3.3
  65. */
  66. public interface HttpConnection {
  67. /**
  68. * @see HttpURLConnection#HTTP_OK
  69. */
  70. public static final int HTTP_OK = java.net.HttpURLConnection.HTTP_OK;
  71. /**
  72. * @see HttpURLConnection#HTTP_NOT_FOUND
  73. */
  74. public static final int HTTP_NOT_FOUND = java.net.HttpURLConnection.HTTP_NOT_FOUND;
  75. /**
  76. * @see HttpURLConnection#HTTP_UNAUTHORIZED
  77. */
  78. public static final int HTTP_UNAUTHORIZED = java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
  79. /**
  80. * @see HttpURLConnection#HTTP_FORBIDDEN
  81. */
  82. public static final int HTTP_FORBIDDEN = java.net.HttpURLConnection.HTTP_FORBIDDEN;
  83. /**
  84. * @see HttpURLConnection#getResponseCode()
  85. * @return the HTTP Status-Code, or -1
  86. * @throws IOException
  87. */
  88. public int getResponseCode() throws IOException;
  89. /**
  90. * @see HttpURLConnection#getURL()
  91. * @return the URL.
  92. */
  93. public URL getURL();
  94. /**
  95. * @see HttpURLConnection#getResponseMessage()
  96. * @return the HTTP response message, or <code>null</code>
  97. * @throws IOException
  98. */
  99. public String getResponseMessage() throws IOException;
  100. /**
  101. * @see HttpURLConnection#getHeaderFields()
  102. * @return a Map of header fields
  103. */
  104. public Map<String, List<String>> getHeaderFields();
  105. /**
  106. * @see HttpURLConnection#setRequestProperty(String, String)
  107. * @param key
  108. * the keyword by which the request is known (e.g., "
  109. * <code>Accept</code>").
  110. * @param value
  111. * the value associated with it.
  112. */
  113. public void setRequestProperty(String key, String value);
  114. /**
  115. * @see HttpURLConnection#setRequestMethod(String)
  116. * @param method
  117. * the HTTP method
  118. * @exception ProtocolException
  119. * if the method cannot be reset or if the requested method
  120. * isn't valid for HTTP.
  121. */
  122. public void setRequestMethod(String method)
  123. throws ProtocolException;
  124. /**
  125. * @see HttpURLConnection#setUseCaches(boolean)
  126. * @param usecaches
  127. * a <code>boolean</code> indicating whether or not to allow
  128. * caching
  129. */
  130. public void setUseCaches(boolean usecaches);
  131. /**
  132. * @see HttpURLConnection#setConnectTimeout(int)
  133. * @param timeout
  134. * an <code>int</code> that specifies the connect timeout value
  135. * in milliseconds
  136. */
  137. public void setConnectTimeout(int timeout);
  138. /**
  139. * @see HttpURLConnection#setReadTimeout(int)
  140. * @param timeout
  141. * an <code>int</code> that specifies the timeout value to be
  142. * used in milliseconds
  143. */
  144. public void setReadTimeout(int timeout);
  145. /**
  146. * @see HttpURLConnection#getContentType()
  147. * @return the content type of the resource that the URL references, or
  148. * <code>null</code> if not known.
  149. */
  150. public String getContentType();
  151. /**
  152. * @see HttpURLConnection#getInputStream()
  153. * @return an input stream that reads from this open connection.
  154. * @exception IOException
  155. * if an I/O error occurs while creating the input stream.
  156. */
  157. public InputStream getInputStream() throws IOException;
  158. /**
  159. * @see HttpURLConnection#getHeaderField(String)
  160. * @param name
  161. * the name of a header field.
  162. * @return the value of the named header field, or <code>null</code> if
  163. * there is no such field in the header.
  164. */
  165. public String getHeaderField(String name);
  166. /**
  167. * @see HttpURLConnection#getContentLength()
  168. * @return the content length of the resource that this connection's URL
  169. * references, {@code -1} if the content length is not known, or if
  170. * the content length is greater than Integer.MAX_VALUE.
  171. */
  172. public int getContentLength();
  173. /**
  174. * @see HttpURLConnection#setInstanceFollowRedirects(boolean)
  175. * @param followRedirects
  176. * a <code>boolean</code> indicating whether or not to follow
  177. * HTTP redirects.
  178. */
  179. public void setInstanceFollowRedirects(boolean followRedirects);
  180. /**
  181. * @see HttpURLConnection#setDoOutput(boolean)
  182. * @param dooutput the new value.
  183. */
  184. public void setDoOutput(boolean dooutput);
  185. /**
  186. * @see HttpURLConnection#setFixedLengthStreamingMode(int)
  187. * @param contentLength
  188. * The number of bytes which will be written to the OutputStream.
  189. *
  190. */
  191. public void setFixedLengthStreamingMode(int contentLength);
  192. /**
  193. * @see HttpURLConnection#getOutputStream()
  194. * @return an output stream that writes to this connection.
  195. * @throws IOException
  196. */
  197. public OutputStream getOutputStream() throws IOException;
  198. /**
  199. * @see HttpURLConnection#setChunkedStreamingMode(int)
  200. * @param chunklen
  201. * The number of bytes to write in each chunk. If chunklen is
  202. * less than or equal to zero, a default value will be used.
  203. */
  204. public void setChunkedStreamingMode(int chunklen);
  205. /**
  206. * @see HttpURLConnection#getRequestMethod()
  207. * @return the HTTP request method
  208. */
  209. public String getRequestMethod();
  210. /**
  211. * @see HttpURLConnection#usingProxy()
  212. * @return a boolean indicating if the connection is using a proxy.
  213. */
  214. public boolean usingProxy();
  215. /**
  216. * @see HttpURLConnection#connect()
  217. * @throws IOException
  218. */
  219. public void connect() throws IOException;
  220. /**
  221. * Configure the connection so that it can be used for https communication.
  222. *
  223. * @param km
  224. * the keymanager managing the key material used to authenticate
  225. * the local SSLSocket to its peer
  226. * @param tm
  227. * the trustmanager responsible for managing the trust material
  228. * that is used when making trust decisions, and for deciding
  229. * whether credentials presented by a peer should be accepted.
  230. * @param random
  231. * the source of randomness for this generator or null. See
  232. * {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
  233. *
  234. * @throws NoSuchAlgorithmException
  235. * @throws KeyManagementException
  236. */
  237. public void configure(KeyManager[] km, TrustManager[] tm,
  238. SecureRandom random) throws NoSuchAlgorithmException,
  239. KeyManagementException;
  240. /**
  241. * Set the {@link HostnameVerifier} used during https communication
  242. *
  243. * @param hostnameverifier
  244. * @throws NoSuchAlgorithmException
  245. * @throws KeyManagementException
  246. */
  247. public void setHostnameVerifier(HostnameVerifier hostnameverifier)
  248. throws NoSuchAlgorithmException, KeyManagementException;
  249. }