Ignore:
Timestamp:
2016-01-04T20:51:45+01:00 (4 years ago)
Author:
simon04
Message:

see #12292 - Allow to disconnect HttpClient in connecting phase

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r9182 r9309  
    618618                url = new URL(new URL(getBaseUrl()), urlSuffix);
    619619                final HttpClient client = HttpClient.create(url, requestMethod).keepAlive(false);
     620                activeConnection = client;
    620621                if (fastFail) {
    621622                    client.setConnectTimeout(1000);
     
    640641                }
    641642
    642                 activeConnection = client.connect();
    643                 Main.info(activeConnection.getResponseMessage());
    644                 int retCode = activeConnection.getResponseCode();
     643                final HttpClient.Response response = client.connect();
     644                Main.info(response.getResponseMessage());
     645                int retCode = response.getResponseCode();
    645646
    646647                if (retCode >= 500) {
     
    652653                }
    653654
    654                 final String responseBody = activeConnection.fetchContent();
     655                final String responseBody = response.fetchContent();
    655656
    656657                String errorHeader = null;
    657658                // Look for a detailed error message from the server
    658                 if (activeConnection.getHeaderField("Error") != null) {
    659                     errorHeader = activeConnection.getHeaderField("Error");
     659                if (response.getHeaderField("Error") != null) {
     660                    errorHeader = response.getHeaderField("Error");
    660661                    Main.error("Error header: " + errorHeader);
    661662                } else if (retCode != HttpURLConnection.HTTP_OK && responseBody.length() > 0) {
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r9172 r9309  
    3131public class OsmConnection {
    3232    protected boolean cancel;
    33     protected HttpClient.Response activeConnection;
     33    protected HttpClient activeConnection;
    3434    protected OAuthParameters oauthParameters;
    3535
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r9308 r9309  
    123123
    124124            final HttpClient client = HttpClient.create(url);
     125            activeConnection = client;
    125126            client.setReasonForRequest(reason);
    126127            adaptRequest(client);
     
    131132                throw new OsmTransferCanceledException("Operation canceled");
    132133
     134            final HttpClient.Response response;
    133135            try {
    134                 activeConnection = client.connect(progressMonitor);
     136                response = client.connect(progressMonitor);
    135137            } catch (Exception e) {
    136138                Main.error(e);
     
    141143            }
    142144            try {
    143                 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
     145                if (response.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
    144146                    throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null, null);
    145147
    146                 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH)
     148                if (response.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH)
    147149                    throw new OsmTransferCanceledException("Proxy Authentication Required");
    148150
    149                 if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
    150                     String errorHeader = activeConnection.getHeaderField("Error");
     151                if (response.getResponseCode() != HttpURLConnection.HTTP_OK) {
     152                    String errorHeader = response.getHeaderField("Error");
    151153                    String errorBody;
    152154                    try {
    153                         errorBody = activeConnection.fetchContent();
     155                        errorBody = response.fetchContent();
    154156                    } catch (Exception e) {
    155157                        errorBody = tr("Reading error text failed.");
    156158                    }
    157                     throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody, url.toString());
     159                    throw new OsmApiException(response.getResponseCode(), errorHeader, errorBody, url.toString());
    158160                }
    159161
    160                 activeConnection.uncompressAccordingToContentDisposition(uncompressAccordingToContentDisposition);
    161                 return activeConnection.getContent();
     162                response.uncompressAccordingToContentDisposition(uncompressAccordingToContentDisposition);
     163                return response.getContent();
    162164            } catch (OsmTransferException e) {
    163165                throw e;
Note: See TracChangeset for help on using the changeset viewer.