Changeset 1875 in josm for trunk/src/org
- Timestamp:
- 2009-07-31T07:29:19+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/progress/AbstractProgressMonitor.java
r1872 r1875 98 98 99 99 public synchronized void invalidate() { 100 checkState(State.INIT); 101 state = State.FINISHED; 102 doFinishTask(); 100 if (state == State.INIT) { 101 state = State.FINISHED; 102 doFinishTask(); 103 } 103 104 } 104 105 -
trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java
r1812 r1875 59 59 * Can be used if method receive ProgressMonitor but it's not interested progress monitoring. 60 60 * Basically replaces {@link #beginTask(String)} and {@link #finishTask()} 61 * 62 * This method can be also used in finally section if method expects that some exception 63 * might prevent it from passing progressMonitor away. If {@link #beginTask(String)} was 64 * already called then this method does nothing. 61 65 */ 62 66 void invalidate(); -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1811 r1875 39 39 */ 40 40 protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 41 api.initialize(); 42 urlStr = api.getBaseUrl() + urlStr; 43 return getInputStreamRaw(urlStr, progressMonitor); 41 try { 42 api.initialize(); 43 urlStr = api.getBaseUrl() + urlStr; 44 return getInputStreamRaw(urlStr, progressMonitor); 45 } finally { 46 progressMonitor.invalidate(); 47 } 44 48 } 45 49 46 50 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 47 URL url = null;48 51 try { 49 url = new URL(urlStr); 50 } catch(MalformedURLException e) { 51 throw new OsmTransferException(e); 52 } 53 try { 54 activeConnection = (HttpURLConnection)url.openConnection(); 55 } catch(Exception e) { 56 throw new OsmTransferException(tr("Failed to open connection to API {0}", url.toExternalForm()), e); 57 } 58 if (cancel) { 59 activeConnection.disconnect(); 60 return null; 61 } 52 URL url = null; 53 try { 54 url = new URL(urlStr); 55 } catch(MalformedURLException e) { 56 throw new OsmTransferException(e); 57 } 58 try { 59 activeConnection = (HttpURLConnection)url.openConnection(); 60 } catch(Exception e) { 61 throw new OsmTransferException(tr("Failed to open connection to API {0}", url.toExternalForm()), e); 62 } 63 if (cancel) { 64 activeConnection.disconnect(); 65 return null; 66 } 62 67 63 if (Main.pref.getBoolean("osm-server.use-compression", true)) {64 activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");65 }68 if (Main.pref.getBoolean("osm-server.use-compression", true)) { 69 activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate"); 70 } 66 71 67 activeConnection.setConnectTimeout(15000);72 activeConnection.setConnectTimeout(15000); 68 73 69 try {70 System.out.println("GET " + url);71 activeConnection.connect();72 } catch (Exception e) {73 throw new OsmTransferException(tr("Couldn't connect to the osm server. Please check your internet connection."), e);74 }75 try {76 if (isAuthCancelled() && activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)77 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null);74 try { 75 System.out.println("GET " + url); 76 activeConnection.connect(); 77 } catch (Exception e) { 78 throw new OsmTransferException(tr("Couldn't connect to the osm server. Please check your internet connection."), e); 79 } 80 try { 81 if (isAuthCancelled() && activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) 82 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null); 78 83 79 if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { 80 String errorHeader = activeConnection.getHeaderField("Error"); 81 InputStream i = null; 82 i = activeConnection.getErrorStream(); 83 StringBuilder errorBody = new StringBuilder(); 84 if (i != null) { 85 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 86 String s; 87 while((s = in.readLine()) != null) { 88 errorBody.append(s); 89 errorBody.append("\n"); 84 if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { 85 String errorHeader = activeConnection.getHeaderField("Error"); 86 InputStream i = null; 87 i = activeConnection.getErrorStream(); 88 StringBuilder errorBody = new StringBuilder(); 89 if (i != null) { 90 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 91 String s; 92 while((s = in.readLine()) != null) { 93 errorBody.append(s); 94 errorBody.append("\n"); 95 } 90 96 } 97 98 throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString()); 91 99 } 92 100 93 throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString()); 101 String encoding = activeConnection.getContentEncoding(); 102 InputStream inputStream = new ProgressInputStream(activeConnection, progressMonitor); 103 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 104 inputStream = new GZIPInputStream(inputStream); 105 } 106 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 107 inputStream = new InflaterInputStream(inputStream, new Inflater(true)); 108 } 109 return inputStream; 110 } catch(Exception e) { 111 if (e instanceof OsmTransferException) 112 throw (OsmTransferException)e; 113 else 114 throw new OsmTransferException(e); 115 94 116 } 95 96 String encoding = activeConnection.getContentEncoding(); 97 InputStream inputStream = new ProgressInputStream(activeConnection, progressMonitor); 98 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 99 inputStream = new GZIPInputStream(inputStream); 100 } 101 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 102 inputStream = new InflaterInputStream(inputStream, new Inflater(true)); 103 } 104 return inputStream; 105 } catch(Exception e) { 106 if (e instanceof OsmTransferException) 107 throw (OsmTransferException)e; 108 else 109 throw new OsmTransferException(e); 110 117 } finally { 118 progressMonitor.invalidate(); 111 119 } 112 120 } -
trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java
r1811 r1875 36 36 this.in = con.getInputStream(); 37 37 } catch (IOException e) { 38 progressMonitor.finishTask(); 38 39 if (con.getHeaderField("Error") != null) 39 40 throw new OsmTransferException(tr(con.getHeaderField("Error")));
Note:
See TracChangeset
for help on using the changeset viewer.