Changeset 9227 in josm for trunk/src/oauth/signpost


Ignore:
Timestamp:
2015-12-31T03:24:56+01:00 (4 years ago)
Author:
Don-vip
Message:

OAuth: add robustness, basic unit test, code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oauth/signpost/AbstractOAuthProvider.java

    r6849 r9227  
    1212
    1313import java.io.BufferedReader;
     14import java.io.InputStream;
    1415import java.io.InputStreamReader;
    1516import java.util.HashMap;
     
    2829 * you will probably inherit from this class, since it takes a lot of work from
    2930 * you.
    30  * 
     31 *
    3132 * @author Matthias Kaeppler
    3233 */
     
    128129     * </ul>
    129130     * </p>
    130      * 
     131     *
    131132     * @param consumer
    132133     *        the {@link OAuthConsumer} that should be used to sign the request
     
    168169                consumer.setAdditionalParameters(customOAuthParams);
    169170            }
    170            
     171
    171172            if (this.listener != null) {
    172173                this.listener.prepareRequest(request);
     
    174175
    175176            consumer.sign(request);
    176            
     177
    177178            if (this.listener != null) {
    178179                this.listener.prepareSubmission(request);
     
    230231            return;
    231232        }
    232         BufferedReader reader = new BufferedReader(new InputStreamReader(response.getContent()));
    233233        StringBuilder responseBody = new StringBuilder();
    234 
    235         String line = reader.readLine();
    236         while (line != null) {
    237             responseBody.append(line);
    238             line = reader.readLine();
     234        InputStream content = response.getContent();
     235        if (content != null) {
     236            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
     237
     238            String line = reader.readLine();
     239            while (line != null) {
     240                responseBody.append(line);
     241                line = reader.readLine();
     242            }
    239243        }
    240244
     
    251255     * Overrride this method if you want to customize the logic for building a
    252256     * request object for the given endpoint URL.
    253      * 
     257     *
    254258     * @param endpointUrl
    255259     *        the URL to which the request will go
     
    263267     * Override this method if you want to customize the logic for how the given
    264268     * request is sent to the server.
    265      * 
     269     *
    266270     * @param request
    267271     *        the request to send
     
    275279     * Called when the connection is being finalized after receiving the
    276280     * response. Use this to do any cleanup / resource freeing.
    277      * 
     281     *
    278282     * @param request
    279283     *        the request that has been sent
     
    295299     * token reply. You must call {@link #setResponseParameters} with the set of
    296300     * parameters before using this method.
    297      * 
     301     *
    298302     * @param key
    299303     *        the parameter name
Note: See TracChangeset for help on using the changeset viewer.