- Timestamp:
- 2015-12-27T15:39:07+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9174 r9177 26 26 /** 27 27 * Provides a uniform access for a HTTP/HTTPS server. This class should be used in favour of {@link HttpURLConnection}. 28 * @since 9168 28 29 */ 29 30 public final class HttpClient { … … 46 47 } 47 48 49 /** 50 * Opens the HTTP connection. 51 * @return HTTP response 52 * @throws IOException if any I/O error occurs 53 */ 48 54 public Response connect() throws IOException { 49 55 final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); … … 146 152 } 147 153 154 /** 155 * Sets whether {@link #getContent()} should uncompress the input stream according to {@code Content-Disposition} 156 * HTTP header. 157 * @param uncompressAccordingToContentDisposition whether the input stream should be uncompressed according to 158 * {@code Content-Disposition} 159 * @return {@code this} 160 */ 148 161 public Response uncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition) { 149 162 this.uncompressAccordingToContentDisposition = uncompressAccordingToContentDisposition; … … 152 165 153 166 /** 167 * Returns the URL. 168 * @return the URL 154 169 * @see HttpURLConnection#getURL() 155 170 */ … … 159 174 160 175 /** 176 * Returns the request method. 177 * @return the HTTP request method 161 178 * @see HttpURLConnection#getRequestMethod() 162 179 */ … … 168 185 * Returns an input stream that reads from this HTTP connection, or, 169 186 * error stream if the connection failed but the server sent useful data. 170 * 187 * <p> 171 188 * Note: the return value can be null, if both the input and the error stream are null. 172 189 * Seems to be the case if the OSM server replies a 401 Unauthorized, see #3887 190 * @return input or error stream 191 * @throws IOException if any I/O error occurs 173 192 * 174 193 * @see HttpURLConnection#getInputStream() … … 205 224 * 206 225 * Detects Unicode charset in use utilizing {@link UTFInputStreamReader}. 226 * @return buffered reader 227 * @throws IOException if any I/O error occurs 207 228 */ 208 229 public BufferedReader getContentReader() throws IOException { … … 215 236 * Fetches the HTTP response as String. 216 237 * @return the response 217 */ 238 * @throws IOException if any I/O error occurs 239 */ 240 @SuppressWarnings("resource") 218 241 public String fetchContent() throws IOException { 219 242 try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) { … … 224 247 /** 225 248 * Gets the response code from this HTTP connection. 249 * @return HTTP response code 226 250 * 227 251 * @see HttpURLConnection#getResponseCode() … … 233 257 /** 234 258 * Gets the response message from this HTTP connection. 259 * @return HTTP response message 235 260 * 236 261 * @see HttpURLConnection#getResponseMessage() … … 242 267 /** 243 268 * Returns the {@code Content-Encoding} header. 269 * @return {@code Content-Encoding} HTTP header 244 270 */ 245 271 public String getContentEncoding() { … … 249 275 /** 250 276 * Returns the {@code Content-Type} header. 277 * @return {@code Content-Type} HTTP header 251 278 */ 252 279 public String getContentType() { … … 256 283 /** 257 284 * Returns the {@code Content-Length} header. 285 * @return {@code Content-Length} HTTP header 258 286 */ 259 287 public long getContentLength() { … … 262 290 263 291 /** 292 * Returns the value of the named header field. 293 * @param name the name of a header field 294 * @return the value of the named header field, or {@code null} if there is no such field in the header 264 295 * @see HttpURLConnection#getHeaderField(String) 265 296 */ … … 269 300 270 301 /** 302 * Returns the list of Strings that represents the named header field values. 303 * @param name the name of a header field 304 * @return unmodifiable List of Strings that represents the corresponding field values 271 305 * @see HttpURLConnection#getHeaderFields() 272 306 */ … … 316 350 /** 317 351 * Returns the URL set for this connection. 352 * @return the URL 318 353 * @see #create(URL) 319 354 * @see #create(URL, String) … … 325 360 /** 326 361 * Returns the request method set for this connection. 362 * @return the HTTP request method 327 363 * @see #create(URL, String) 328 364 */ … … 333 369 /** 334 370 * Returns the set value for the given {@code header}. 371 * @param header HTTP header name 372 * @return HTTP header value 335 373 */ 336 374 public String getRequestHeader(String header) { … … 364 402 365 403 /** 404 * Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced 405 * by this URLConnection. If the timeout expires before the connection can be established, a 406 * {@link java.net.SocketTimeoutException} is raised. A timeout of zero is interpreted as an infinite timeout. 407 * @param connectTimeout an {@code int} that specifies the connect timeout value in milliseconds 366 408 * @return {@code this} 367 409 * @see HttpURLConnection#setConnectTimeout(int) … … 373 415 374 416 /** 417 * Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from 418 * input stream when a connection is established to a resource. If the timeout expires before there is data available for 419 * read, a {@link java.net.SocketTimeoutException} is raised. A timeout of zero is interpreted as an infinite timeout. 420 * @param readTimeout an {@code int} that specifies the read timeout value in milliseconds 375 421 * @return {@code this} 376 422 * @see HttpURLConnection#setReadTimeout(int) (int) 377 423 */ 378 379 424 public HttpClient setReadTimeout(int readTimeout) { 380 425 this.readTimeout = readTimeout; … … 384 429 /** 385 430 * Sets the {@code Accept} header. 431 * @param accept header value 386 432 * 387 433 * @return {@code this} … … 393 439 /** 394 440 * Sets the request body for {@code PUT}/{@code POST} requests. 441 * @param requestBody request body 395 442 * 396 443 * @return {@code this} … … 403 450 /** 404 451 * Sets the {@code If-Modified-Since} header. 452 * @param ifModifiedSince header value 405 453 * 406 454 * @return {@code this} … … 416 464 * Set {@code maxRedirects} to {@code -1} in order to ignore redirects, i.e., 417 465 * to not throw an {@link IOException} in {@link #connect()}. 466 * @param maxRedirects header value 418 467 * 419 468 * @return {@code this} … … 426 475 /** 427 476 * Sets an arbitrary HTTP header. 477 * @param key header name 478 * @param value header value 428 479 * 429 480 * @return {@code this} … … 436 487 /** 437 488 * Sets arbitrary HTTP headers. 489 * @param headers HTTP headers 438 490 * 439 491 * @return {@code this} … … 446 498 /** 447 499 * Sets a reason to show on console. Can be {@code null} if no reason is given. 500 * @param reasonForRequest Reason to show 501 * @return {@code this} 448 502 */ 449 503 public HttpClient setReasonForRequest(String reasonForRequest) { … … 464 518 } 465 519 } 466 467 520 }
Note:
See TracChangeset
for help on using the changeset viewer.