Changeset 11250 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-11-13T13:12:47+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r10420 r11250 6 6 import java.io.BufferedOutputStream; 7 7 import java.io.BufferedReader; 8 import java.io.ByteArrayInputStream; 8 9 import java.io.IOException; 9 10 import java.io.InputStream; … … 190 191 private boolean uncompress; 191 192 private boolean uncompressAccordingToContentDisposition; 193 private String responseData = null; 192 194 193 195 private Response(HttpURLConnection connection, ProgressMonitor monitor) throws IOException { … … 198 200 this.responseCode = connection.getResponseCode(); 199 201 this.responseMessage = connection.getResponseMessage(); 202 if (this.responseCode >= 300) { 203 String contentType = getContentType(); 204 if (contentType == null || ( 205 contentType.contains("text") || 206 contentType.contains("html") || 207 contentType.contains("xml")) 208 ) { 209 String content = this.fetchContent(); 210 if (content == null || content.isEmpty()) { 211 Main.debug("Server did not return any body"); 212 } else { 213 Main.debug("Response body: "); 214 Main.debug(this.fetchContent()); 215 } 216 } else { 217 Main.debug("Server returned content: {0} of length: {1}. Not printing.", contentType, this.getContentLength()); 218 } 219 } 200 220 } 201 221 … … 264 284 Main.debug(ioe); 265 285 in = connection.getErrorStream(); 286 if (in == null) { 287 in = new ByteArrayInputStream(new byte[]{}); 288 } 266 289 } 267 290 if (in != null) { … … 306 329 * @throws IOException if any I/O error occurs 307 330 */ 308 @SuppressWarnings("resource") 309 public String fetchContent() throws IOException { 310 try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) { 311 return scanner.hasNext() ? scanner.next() : ""; 312 } 331 public synchronized String fetchContent() throws IOException { 332 if (responseData == null) { 333 try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) { // \A - beginning of input 334 responseData = scanner.hasNext() ? scanner.next() : ""; 335 } 336 } 337 return responseData; 313 338 } 314 339
Note:
See TracChangeset
for help on using the changeset viewer.