Index: applications/editors/josm/plugins/DirectUpload/build.xml
===================================================================
--- applications/editors/josm/plugins/DirectUpload/build.xml	(revision 31870)
+++ applications/editors/josm/plugins/DirectUpload/build.xml	(revision 31871)
@@ -5,5 +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])"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
-    <property name="plugin.main.version" value="7001"/>
+    <property name="plugin.main.version" value="9179"/>
 
     <!-- Configure these properties (replace "..." accordingly).
Index: applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java
===================================================================
--- applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java	(revision 31870)
+++ applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java	(revision 31871)
@@ -13,10 +13,6 @@
 import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.DecimalFormat;
@@ -45,5 +41,6 @@
 import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.tools.GBC;
-import org.openstreetmap.josm.tools.Utils;
+import org.openstreetmap.josm.tools.HttpClient;
+import org.openstreetmap.josm.tools.HttpClient.Response;
 
 /**
@@ -236,14 +233,15 @@
             writeString(baos, "--" + BOUNDARY + "--" + LINE_END);
 
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            HttpURLConnection conn = setupConnection(baos.size());
+            HttpClient conn = setupConnection(baos.size());
 
             progressMonitor.setTicksCount(baos.size());
             progressMonitor.subTask(null);
 
-            flushToServer(bais, conn.getOutputStream(), progressMonitor);
+            // FIXME previous method allowed to see real % progress (each 10 Kb of data)
+            //flushToServer(bais, conn.getOutputStream(), progressMonitor);
+            Response response = conn.setRequestBody(baos.toByteArray()).connect(progressMonitor);
 
             if (canceled) {
-                conn.disconnect();
+            	response.disconnect();
                 GuiHelper.runInEDT(new Runnable() {
                     @Override public void run() {
@@ -255,5 +253,5 @@
             }
             else {
-                final boolean success = finishUpConnection(conn);
+                final boolean success = finishUpConnection(response);
                 GuiHelper.runInEDT(new Runnable() {
                     @Override public void run() {
@@ -285,5 +283,5 @@
      * @return HttpURLConnection The set up conenction
      */
-    private HttpURLConnection setupConnection(int contentLength) throws Exception {
+    private HttpClient setupConnection(int contentLength) throws Exception {
 
         // Upload URL
@@ -291,17 +289,12 @@
 
         // Set up connection and log in
-        HttpURLConnection c = Utils.openHttpConnection(url);
-        c.setFixedLengthStreamingMode(contentLength);
-        c.setConnectTimeout(15000);
-        c.setRequestMethod("POST");
-        c.setDoOutput(true);
+        HttpClient c = HttpClient.create(url, "POST").setFixedLengthStreamingMode(contentLength).setConnectTimeout(15000);
         // unfortunately, addAuth() is protected, so we need to subclass OsmConnection
         // XXX make addAuth public.
         UploadOsmConnection.getInstance().addAuthHack(c);
 
-        c.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
-        c.addRequestProperty("Connection", "close"); // counterpart of keep-alive
-        c.addRequestProperty("Expect", "");
-        c.connect();
+        c.setHeader("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
+        c.setHeader("Connection", "close"); // counterpart of keep-alive
+        c.setHeader("Expect", "");
 
         return c;
@@ -314,5 +307,5 @@
      * @param HttpURLConnection The connection to check/finish up
      */
-    private boolean finishUpConnection(HttpURLConnection c) throws Exception {
+    private boolean finishUpConnection(Response c) throws Exception {
         String returnMsg = c.getResponseMessage();
         final boolean success = returnMsg.equals("OK");
@@ -342,5 +335,5 @@
      * @param OutputStream
      */
-    private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception {
+/*    private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception {
         // Upload in 10 kB chunks
         byte[] buffer = new byte[10000];
@@ -364,5 +357,5 @@
         buffer = null;
     }
-
+*/
     /**
      * Generates the output string displayed in the PleaseWaitDialog.
@@ -373,4 +366,5 @@
         int max = progressMonitor.getTicksCount();
         int percent = Math.round(cur * 100 / max);
+        // FIXME method kept because of translated string
         return tr("Uploading GPX track: {0}% ({1} of {2})",
                         percent, formatBytes(cur), formatBytes(max));
Index: applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java
===================================================================
--- applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java	(revision 31870)
+++ applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java	(revision 31871)
@@ -3,5 +3,4 @@
 package org.openstreetmap.josm.plugins.DirectUpload;
 
-import java.net.HttpURLConnection;
 import java.util.List;
 
@@ -14,8 +13,9 @@
 import org.openstreetmap.josm.io.OsmConnection;
 import org.openstreetmap.josm.io.OsmTransferException;
+import org.openstreetmap.josm.tools.HttpClient;
 
 /**
  * Work-around and utility class for DirectUpload.
- * 
+ *
  * @author ax
  */
@@ -34,5 +34,5 @@
 
     // make protected OsmConnection::addAuth() available to others
-    public void addAuthHack(HttpURLConnection connection) throws OsmTransferException {
+    public void addAuthHack(HttpClient connection) throws OsmTransferException {
         addAuth(connection);
     }
@@ -40,7 +40,7 @@
     /**
      * find which gpx layer holds the trace to upload. layers are tried in this order:
-     * 
+     *
      * 1. selected (*not* active - think "zoom to layer"), from first to last
-     * 2. not selectd - if there is only one 
+     * 2. not selectd - if there is only one
      * 3. active
      *
@@ -65,9 +65,9 @@
                 // if there is none, try the none selected gpx layers. if there is only one, use it.
                 if (gpxLayersRemaining.size() == 1) {
-                    traceLayer = gpxLayersRemaining.get(0); 
+                    traceLayer = gpxLayersRemaining.get(0);
                 }
                 // active layer
                 else if (mv.getActiveLayer() instanceof GpxLayer) {
-                    traceLayer = (GpxLayer) mv.getActiveLayer(); 
+                    traceLayer = (GpxLayer) mv.getActiveLayer();
                 }
             }
@@ -78,5 +78,5 @@
             }
         }
-        
+
         return null;
     }
