Changeset 31871 in osm for applications
- Timestamp:
- 2015-12-27T16:20:38+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/DirectUpload
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/DirectUpload/build.xml
r30416 r31871 5 5 <property name="commit.message" value="applied JOSM Ticket 4498 (patch by ax) - oauth support for gpx upload (I accidentally committed parts of the path in [24236])"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value=" 7001"/>7 <property name="plugin.main.version" value="9179"/> 8 8 9 9 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java
r30737 r31871 13 13 import java.awt.GridBagLayout; 14 14 import java.awt.event.ActionEvent; 15 import java.io.ByteArrayInputStream;16 15 import java.io.ByteArrayOutputStream; 17 16 import java.io.IOException; 18 import java.io.InputStream;19 import java.io.OutputStream;20 import java.net.HttpURLConnection;21 17 import java.net.URL; 22 18 import java.text.DecimalFormat; … … 45 41 import org.openstreetmap.josm.io.OsmApi; 46 42 import org.openstreetmap.josm.tools.GBC; 47 import org.openstreetmap.josm.tools.Utils; 43 import org.openstreetmap.josm.tools.HttpClient; 44 import org.openstreetmap.josm.tools.HttpClient.Response; 48 45 49 46 /** … … 236 233 writeString(baos, "--" + BOUNDARY + "--" + LINE_END); 237 234 238 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); 239 HttpURLConnection conn = setupConnection(baos.size()); 235 HttpClient conn = setupConnection(baos.size()); 240 236 241 237 progressMonitor.setTicksCount(baos.size()); 242 238 progressMonitor.subTask(null); 243 239 244 flushToServer(bais, conn.getOutputStream(), progressMonitor); 240 // FIXME previous method allowed to see real % progress (each 10 Kb of data) 241 //flushToServer(bais, conn.getOutputStream(), progressMonitor); 242 Response response = conn.setRequestBody(baos.toByteArray()).connect(progressMonitor); 245 243 246 244 if (canceled) { 247 conn.disconnect();245 response.disconnect(); 248 246 GuiHelper.runInEDT(new Runnable() { 249 247 @Override public void run() { … … 255 253 } 256 254 else { 257 final boolean success = finishUpConnection( conn);255 final boolean success = finishUpConnection(response); 258 256 GuiHelper.runInEDT(new Runnable() { 259 257 @Override public void run() { … … 285 283 * @return HttpURLConnection The set up conenction 286 284 */ 287 private Http URLConnectionsetupConnection(int contentLength) throws Exception {285 private HttpClient setupConnection(int contentLength) throws Exception { 288 286 289 287 // Upload URL … … 291 289 292 290 // Set up connection and log in 293 HttpURLConnection c = Utils.openHttpConnection(url); 294 c.setFixedLengthStreamingMode(contentLength); 295 c.setConnectTimeout(15000); 296 c.setRequestMethod("POST"); 297 c.setDoOutput(true); 291 HttpClient c = HttpClient.create(url, "POST").setFixedLengthStreamingMode(contentLength).setConnectTimeout(15000); 298 292 // unfortunately, addAuth() is protected, so we need to subclass OsmConnection 299 293 // XXX make addAuth public. 300 294 UploadOsmConnection.getInstance().addAuthHack(c); 301 295 302 c.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY); 303 c.addRequestProperty("Connection", "close"); // counterpart of keep-alive 304 c.addRequestProperty("Expect", ""); 305 c.connect(); 296 c.setHeader("Content-Type", "multipart/form-data; boundary=" + BOUNDARY); 297 c.setHeader("Connection", "close"); // counterpart of keep-alive 298 c.setHeader("Expect", ""); 306 299 307 300 return c; … … 314 307 * @param HttpURLConnection The connection to check/finish up 315 308 */ 316 private boolean finishUpConnection( HttpURLConnectionc) throws Exception {309 private boolean finishUpConnection(Response c) throws Exception { 317 310 String returnMsg = c.getResponseMessage(); 318 311 final boolean success = returnMsg.equals("OK"); … … 342 335 * @param OutputStream 343 336 */ 344 private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception {337 /* private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception { 345 338 // Upload in 10 kB chunks 346 339 byte[] buffer = new byte[10000]; … … 364 357 buffer = null; 365 358 } 366 359 */ 367 360 /** 368 361 * Generates the output string displayed in the PleaseWaitDialog. … … 373 366 int max = progressMonitor.getTicksCount(); 374 367 int percent = Math.round(cur * 100 / max); 368 // FIXME method kept because of translated string 375 369 return tr("Uploading GPX track: {0}% ({1} of {2})", 376 370 percent, formatBytes(cur), formatBytes(max)); -
applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java
r30347 r31871 3 3 package org.openstreetmap.josm.plugins.DirectUpload; 4 4 5 import java.net.HttpURLConnection;6 5 import java.util.List; 7 6 … … 14 13 import org.openstreetmap.josm.io.OsmConnection; 15 14 import org.openstreetmap.josm.io.OsmTransferException; 15 import org.openstreetmap.josm.tools.HttpClient; 16 16 17 17 /** 18 18 * Work-around and utility class for DirectUpload. 19 * 19 * 20 20 * @author ax 21 21 */ … … 34 34 35 35 // make protected OsmConnection::addAuth() available to others 36 public void addAuthHack(Http URLConnectionconnection) throws OsmTransferException {36 public void addAuthHack(HttpClient connection) throws OsmTransferException { 37 37 addAuth(connection); 38 38 } … … 40 40 /** 41 41 * find which gpx layer holds the trace to upload. layers are tried in this order: 42 * 42 * 43 43 * 1. selected (*not* active - think "zoom to layer"), from first to last 44 * 2. not selectd - if there is only one 44 * 2. not selectd - if there is only one 45 45 * 3. active 46 46 * … … 65 65 // if there is none, try the none selected gpx layers. if there is only one, use it. 66 66 if (gpxLayersRemaining.size() == 1) { 67 traceLayer = gpxLayersRemaining.get(0); 67 traceLayer = gpxLayersRemaining.get(0); 68 68 } 69 69 // active layer 70 70 else if (mv.getActiveLayer() instanceof GpxLayer) { 71 traceLayer = (GpxLayer) mv.getActiveLayer(); 71 traceLayer = (GpxLayer) mv.getActiveLayer(); 72 72 } 73 73 } … … 78 78 } 79 79 } 80 80 81 81 return null; 82 82 }
Note:
See TracChangeset
for help on using the changeset viewer.