Changeset 9171 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2015-12-26T23:42:00+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r9062 r9171 6 6 import java.awt.Dimension; 7 7 import java.awt.GridBagLayout; 8 import java.io.BufferedReader;9 8 import java.io.ByteArrayInputStream; 10 9 import java.io.File; … … 13 12 import java.io.IOException; 14 13 import java.io.InputStream; 15 import java.io.InputStreamReader;16 14 import java.io.OutputStreamWriter; 17 15 import java.io.PrintWriter; 18 import java.net.HttpURLConnection;19 16 import java.net.MalformedURLException; 20 17 import java.net.URL; … … 42 39 import org.openstreetmap.josm.io.OsmTransferException; 43 40 import org.openstreetmap.josm.tools.GBC; 41 import org.openstreetmap.josm.tools.HttpClient; 44 42 import org.openstreetmap.josm.tools.Utils; 45 43 import org.xml.sax.SAXException; … … 53 51 private Collection<String> sites; 54 52 private boolean canceled; 55 private Http URLConnectionconnection;53 private HttpClient.Response connection; 56 54 private List<PluginInformation> availablePlugins; 57 55 private boolean displayErrMsg; … … 153 151 } 154 152 153 String content = null; 155 154 try { 156 155 monitor.beginTask(""); … … 158 157 159 158 URL url = new URL(site); 160 synchronized (this) { 161 connection = Utils.openHttpConnection(url); 162 connection.setRequestProperty("Cache-Control", "no-cache"); 163 connection.setRequestProperty("Accept-Charset", "utf-8"); 164 } 165 try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { 166 StringBuilder sb = new StringBuilder(); 167 String line; 168 while ((line = in.readLine()) != null) { 169 sb.append(line).append('\n'); 170 } 171 return sb.toString(); 172 } 159 connection = HttpClient.create(url).useCache(false).connect(); 160 content = connection.fetchContent(); 161 if (connection.getResponseCode() != 200) { 162 throw new IOException(tr("Unsuccessful HTTP request")); 163 } 164 return content; 173 165 } catch (MalformedURLException e) { 174 166 if (canceled) return null; … … 177 169 } catch (IOException e) { 178 170 if (canceled) return null; 179 Main.addNetworkError(site, e); 180 handleIOException(monitor, e, tr("Plugin list download error"), tr("JOSM failed to download plugin list:"), displayErrMsg); 171 handleIOException(monitor, e, content); 181 172 return null; 182 173 } finally { … … 191 182 } 192 183 193 private void handleIOException(final ProgressMonitor monitor, IOException e, final String title, final String firstMessage, 194 boolean displayMsg) { 195 StringBuilder sb = new StringBuilder(); 196 try (InputStream errStream = connection.getErrorStream()) { 197 if (errStream != null) { 198 try (BufferedReader err = new BufferedReader(new InputStreamReader(errStream, StandardCharsets.UTF_8))) { 199 String line; 200 while ((line = err.readLine()) != null) { 201 sb.append(line).append('\n'); 202 } 203 } catch (Exception ex) { 204 Main.error(e); 205 Main.error(ex); 206 } 207 } 208 } catch (IOException ex) { 209 Main.warn(ex); 210 } 184 private void handleIOException(final ProgressMonitor monitor, IOException e, String details) { 211 185 final String msg = e.getMessage(); 212 final String details = sb.toString();213 186 if (details.isEmpty()) { 214 187 Main.error(e.getClass().getSimpleName()+": " + msg); … … 217 190 } 218 191 219 if (displayMsg) { 220 displayErrorMessage(monitor, msg, details, t itle, firstMessage);192 if (displayErrMsg) { 193 displayErrorMessage(monitor, msg, details, tr("Plugin list download error"), tr("JOSM failed to download plugin list:")); 221 194 } 222 195 }
Note:
See TracChangeset
for help on using the changeset viewer.