Changeset 3511 in josm


Ignore:
Timestamp:
Sep 3, 2010 11:12:56 PM (3 years ago)
Author:
stoecker
Message:

fix #5410 - server error message hidden from user

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

Legend:

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

    r3083 r3511  
    6161        sb.append("ResponseCode=") 
    6262        .append(responseCode); 
    63         if (errorHeader != null && errorBody != null && !errorBody.trim().equals("")) { 
    64             sb.append(", Error Header=<") 
    65             .append(tr(errorHeader)) 
    66             .append(">"); 
    67         } 
    68         if (errorBody != null && !errorBody.trim().equals("")) { 
    69             errorBody = errorBody.trim(); 
    70             if(!errorBody.equals(errorHeader)) { 
    71                 sb.append(", Error Body=<") 
    72                 .append(tr(errorBody)) 
     63        String eh = ""; 
     64        try 
     65        { 
     66            if(errorHeader != null) 
     67                eh = tr(errorHeader.trim()); 
     68            if (!eh.isEmpty()) { 
     69                sb.append(", Error Header=<") 
     70                .append(eh) 
    7371                .append(">"); 
    7472            } 
     73        } 
     74        catch (Exception e) { 
     75        } 
     76        try 
     77        { 
     78            String eb = errorBody != null ? tr(errorBody.trim()) : ""; 
     79            if (!eb.isEmpty() && !eb.equals(eh)) { 
     80                sb.append(", Error Body=<") 
     81                .append(eb) 
     82                .append(">"); 
     83            } 
     84        } 
     85        catch (Exception e) { 
    7586        } 
    7687        return sb.toString(); 
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r3021 r3511  
    55 
    66import java.io.BufferedReader; 
     7import java.io.IOException; 
    78import java.io.InputStream; 
    89import java.io.InputStreamReader; 
     
    9495                    throw new OsmTransferCancelledException(); 
    9596 
     97                String encoding = activeConnection.getContentEncoding(); 
    9698                if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { 
    9799                    String errorHeader = activeConnection.getHeaderField("Error"); 
    98                     InputStream i = null; 
    99                     i = activeConnection.getErrorStream(); 
    100100                    StringBuilder errorBody = new StringBuilder(); 
    101                     if (i != null) { 
    102                         BufferedReader in = new BufferedReader(new InputStreamReader(i)); 
    103                         String s; 
    104                         while((s = in.readLine()) != null) { 
    105                             errorBody.append(s); 
    106                             errorBody.append("\n"); 
     101                    try 
     102                    { 
     103                        InputStream i = FixEncoding(activeConnection.getErrorStream(), encoding); 
     104                        if (i != null) { 
     105                            BufferedReader in = new BufferedReader(new InputStreamReader(i)); 
     106                            String s; 
     107                            while((s = in.readLine()) != null) { 
     108                                errorBody.append(s); 
     109                                errorBody.append("\n"); 
     110                            } 
    107111                        } 
     112                    } 
     113                    catch(Exception e) { 
     114                        errorBody.append(tr("Reading error text failed.")); 
    108115                    } 
    109116 
     
    111118                } 
    112119 
    113                 String encoding = activeConnection.getContentEncoding(); 
    114                 InputStream inputStream = new ProgressInputStream(activeConnection, progressMonitor); 
    115                 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 
    116                     inputStream = new GZIPInputStream(inputStream); 
    117                 } 
    118                 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 
    119                     inputStream = new InflaterInputStream(inputStream, new Inflater(true)); 
    120                 } 
    121                 return inputStream; 
     120                return FixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding); 
    122121            } catch(Exception e) { 
    123122                if (e instanceof OsmTransferException) 
     
    130129            progressMonitor.invalidate(); 
    131130        } 
     131    } 
     132 
     133    private InputStream FixEncoding(InputStream stream, String encoding) throws IOException 
     134    { 
     135        if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 
     136            stream = new GZIPInputStream(stream); 
     137        } 
     138        else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 
     139            stream = new InflaterInputStream(stream, new Inflater(true)); 
     140        } 
     141        return stream; 
    132142    } 
    133143 
Note: See TracChangeset for help on using the changeset viewer.