Ignore:
Timestamp:
2012-11-18T00:44:10+01:00 (11 years ago)
Author:
Don-vip
Message:

Single entry point in Utils to open HTTP connections

File:
1 edited

Legend:

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

    r5422 r5587  
    3030
    3131import org.openstreetmap.josm.Main;
    32 import org.openstreetmap.josm.data.Version;
    3332import org.openstreetmap.josm.data.oauth.OAuthParameters;
    3433import org.openstreetmap.josm.data.oauth.OAuthToken;
     
    3837import org.openstreetmap.josm.io.OsmTransferCanceledException;
    3938import org.openstreetmap.josm.tools.CheckParameterUtil;
     39import org.openstreetmap.josm.tools.Utils;
    4040
    4141/**
     
    325325            URL url = new URL(sb.toString());
    326326            synchronized(this) {
    327                 connection = (HttpURLConnection)url.openConnection();
     327                connection = Utils.openHttpConnection(url);
    328328            }
    329329            connection.setRequestMethod("GET");
    330330            connection.setDoInput(true);
    331331            connection.setDoOutput(false);
    332             setHttpRequestParameters(connection);
    333332            connection.connect();
    334333            SessionId sessionId = extractOsmSession(connection);
     
    355354            URL url = new URL(getAuthoriseUrl(requestToken));
    356355            synchronized(this) {
    357                 connection = (HttpURLConnection)url.openConnection();
     356                connection = Utils.openHttpConnection(url);
    358357            }
    359358            connection.setRequestMethod("GET");
     
    361360            connection.setDoOutput(false);
    362361            connection.setRequestProperty("Cookie", "_osm_session=" + sessionId.id + "; _osm_username=" + sessionId.userName);
    363             setHttpRequestParameters(connection);
    364362            connection.connect();
    365363            sessionId.token = extractToken(connection);
     
    380378            URL url = new URL(buildOsmLoginUrl());
    381379            synchronized(this) {
    382                 connection = (HttpURLConnection)url.openConnection();
     380                connection = Utils.openHttpConnection(url);
    383381            }
    384382            connection.setRequestMethod("POST");
     
    401399            // make sure we can catch 302 Moved Temporarily below
    402400            connection.setInstanceFollowRedirects(false);
    403             setHttpRequestParameters(connection);
    404401
    405402            connection.connect();
     
    437434            URL url = new URL(buildOsmLogoutUrl());
    438435            synchronized(this) {
    439                 connection = (HttpURLConnection)url.openConnection();
     436                connection = Utils.openHttpConnection(url);
    440437            }
    441438            connection.setRequestMethod("GET");
    442439            connection.setDoInput(true);
    443440            connection.setDoOutput(false);
    444             setHttpRequestParameters(connection);
    445441            connection.connect();
    446         }catch(MalformedURLException e) {
     442        } catch(MalformedURLException e) {
    447443            throw new OsmOAuthAuthorizationException(e);
    448444        } catch(IOException e) {
     
    484480            URL url = new URL(oauthProviderParameters.getAuthoriseUrl());
    485481            synchronized(this) {
    486                 connection = (HttpURLConnection)url.openConnection();
     482                connection = Utils.openHttpConnection(url);
    487483            }
    488484            connection.setRequestMethod("POST");
     
    494490            connection.setRequestProperty("Cookie", "_osm_session=" + sessionId.id + "; _osm_username=" + sessionId.userName);
    495491            connection.setInstanceFollowRedirects(false);
    496             setHttpRequestParameters(connection);
    497492
    498493            connection.connect();
     
    520515            }
    521516        }
    522     }
    523 
    524     protected void setHttpRequestParameters(HttpURLConnection connection) {
    525         connection.setRequestProperty("User-Agent", Version.getInstance().getAgentString());
    526         connection.setRequestProperty("Host", connection.getURL().getHost());
    527517    }
    528518
Note: See TracChangeset for help on using the changeset viewer.