- Timestamp:
- 2009-11-19T10:12:31+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2273 r2478 473 473 * but including any object ids (e.g. "/way/1234/history"). 474 474 * @param requestBody the body of the HTTP request, if any. 475 * @param monitor the progress monitor 476 * @param doAuthenticate set to true, if the request sent to the server shall include authentication 477 * credentials; 475 478 * 476 479 * @return the body of the HTTP response, if and only if the response code was "200 OK". … … 499 502 500 503 // It seems that certain bits of the Ruby API are very unhappy upon 501 // receipt of a PUT/POST message with tout a Content-length header,504 // receipt of a PUT/POST message without a Content-length header, 502 505 // even if the request has no payload. 503 506 // Since Java will not generate a Content-length header unless … … 535 538 i = activeConnection.getErrorStream(); 536 539 } 537 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 538 539 String s; 540 while((s = in.readLine()) != null) { 541 responseBody.append(s); 542 responseBody.append("\n"); 540 if (i != null) { 541 // the input stream can be null if both the input and the error stream 542 // are null. Seems to be the case if the OSM server replies a 401 543 // Unauthorized, see #3887. 544 // 545 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 546 String s; 547 while((s = in.readLine()) != null) { 548 responseBody.append(s); 549 responseBody.append("\n"); 550 } 543 551 } 544 552 String errorHeader = null; … … 553 561 554 562 errorHeader = errorHeader == null? null : errorHeader.trim(); 555 String errorBody = responseBody == null? null : responseBody.toString().trim();563 String errorBody = responseBody.length() == 0? null : responseBody.toString().trim(); 556 564 switch(retCode) { 557 565 case HttpURLConnection.HTTP_OK: 558 break; // do nothing566 return responseBody.toString(); 559 567 case HttpURLConnection.HTTP_GONE: 560 568 throw new OsmApiPrimitiveGoneException(errorHeader, errorBody); 561 569 default: 562 570 throw new OsmApiException(retCode, errorHeader, errorBody); 563 564 } 565 return responseBody.toString(); 571 } 566 572 } catch (UnknownHostException e) { 567 573 throw new OsmTransferException(e);
Note:
See TracChangeset
for help on using the changeset viewer.