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

see #12292 - Allow to disconnect HttpClient in connecting phase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java

    r9301 r9309  
    4444    private final OAuthProvider provider;
    4545    private boolean canceled;
    46     private HttpClient.Response connection;
     46    private HttpClient connection;
    4747
    4848    private static class SessionId {
     
    183183
    184184    protected String extractToken() {
    185         try (BufferedReader r = connection.getContentReader()) {
     185        try (BufferedReader r = connection.getResponse().getContentReader()) {
    186186            String c;
    187187            Pattern p = Pattern.compile(".*authenticity_token.*value=\"([^\"]+)\".*");
     
    200200
    201201    protected SessionId extractOsmSession() {
    202         List<String> setCookies = connection.getHeaderFields().get("Set-Cookie");
     202        List<String> setCookies = connection.getResponse().getHeaderFields().get("Set-Cookie");
    203203        if (setCookies == null)
    204204            // no cookies set
     
    293293            URL url = new URL(sb.toString());
    294294            synchronized (this) {
    295                 connection = HttpClient.create(url).connect();
     295                connection = HttpClient.create(url);
     296                connection.connect();
    296297            }
    297298            SessionId sessionId = extractOsmSession();
     
    322323            synchronized (this) {
    323324                connection = HttpClient.create(url)
    324                         .setHeader("Cookie", "_osm_session=" + sessionId.id + "; _osm_username=" + sessionId.userName)
    325                         .connect();
     325                        .setHeader("Cookie", "_osm_session=" + sessionId.id + "; _osm_username=" + sessionId.userName);
     326                connection.connect();
    326327            }
    327328            sessionId.token = extractToken();
     
    357358
    358359            synchronized (this) {
    359                 connection = client.connect();
     360                connection = client;
     361                connection.connect();
    360362            }
    361363
     
    364366            // an error page is sent to back to the user.
    365367            //
    366             int retCode = connection.getResponseCode();
     368            int retCode = connection.getResponse().getResponseCode();
    367369            if (retCode != HttpURLConnection.HTTP_MOVED_TEMP)
    368370                throw new OsmOAuthAuthorizationException(tr("Failed to authenticate user ''{0}'' with password ''***'' as OAuth user",
     
    383385            URL url = new URL(buildOsmLogoutUrl());
    384386            synchronized (this) {
    385                 connection = HttpClient.create(url).setMaxRedirects(-1).connect();
     387                connection = HttpClient.create(url).setMaxRedirects(-1);
     388                connection.connect();
    386389            }
    387390        } catch (IOException e) {
     
    432435
    433436            synchronized (this) {
    434                 connection = client.connect();
    435             }
    436 
    437             int retCode = connection.getResponseCode();
     437                connection = client;
     438                connection.connect();
     439            }
     440
     441            int retCode = connection.getResponse().getResponseCode();
    438442            if (retCode != HttpURLConnection.HTTP_OK)
    439443                throw new OsmOAuthAuthorizationException(tr("Failed to authorize OAuth request  ''{0}''", requestToken.getKey()));
Note: See TracChangeset for help on using the changeset viewer.