Changeset 9935 in josm


Ignore:
Timestamp:
2016-03-05T21:36:33+01:00 (9 years ago)
Author:
simon04
Message:

see #12584 - Attempt to obtain the session cookie via CookieManager

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r9913 r9935  
    77import java.io.IOException;
    88import java.lang.reflect.Field;
     9import java.net.CookieHandler;
    910import java.net.HttpURLConnection;
     11import java.net.URISyntaxException;
    1012import java.net.URL;
    1113import java.nio.charset.StandardCharsets;
     14import java.util.Collections;
    1215import java.util.HashMap;
    1316import java.util.Iterator;
     
    199202    }
    200203
    201     protected SessionId extractOsmSession() {
    202         List<String> setCookies = connection.getResponse().getHeaderFields().get("Set-Cookie");
     204    protected SessionId extractOsmSession() throws IOException, URISyntaxException {
     205        // response headers might not contain the cookie, see #12584
     206        final List<String> setCookies = CookieHandler.getDefault()
     207                .get(connection.getURL().toURI(), Collections.<String, List<String>>emptyMap())
     208                .get("Cookie");
    203209        if (setCookies == null) {
    204210            Main.warn("No 'Set-Cookie' in response header!");
     
    267273                        tr("OSM website did not return a session cookie in response to ''{0}'',", url.toString()));
    268274            return sessionId;
    269         } catch (IOException e) {
     275        } catch (IOException | URISyntaxException e) {
    270276            throw new OsmOAuthAuthorizationException(e);
    271277        } finally {
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r9915 r9935  
    99import java.io.InputStream;
    1010import java.io.OutputStream;
     11import java.net.CookieHandler;
     12import java.net.CookieManager;
    1113import java.net.HttpRetryException;
    1214import java.net.HttpURLConnection;
     
    5153    private transient HttpURLConnection connection; // to allow disconnecting before `response` is set
    5254    private transient Response response;
     55
     56    static {
     57        CookieHandler.setDefault(new CookieManager());
     58    }
    5359
    5460    private HttpClient(URL url, String requestMethod) {
Note: See TracChangeset for help on using the changeset viewer.