Index: /applications/editors/josm/plugins/DirectUpload/build.xml
===================================================================
--- /applications/editors/josm/plugins/DirectUpload/build.xml	(revision 24238)
+++ /applications/editors/josm/plugins/DirectUpload/build.xml	(revision 24239)
@@ -27,5 +27,5 @@
 <project name="DirectUpload" default="dist" basedir=".">
 
-	<property name="commit.message" value="Changed constructor signature of plugin main class" />
+	<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])" />
 	<property name="plugin.main.version" value="3338" />
 
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 24239)
+++ /applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java	(revision 24239)
@@ -0,0 +1,83 @@
+// ...
+
+package org.openstreetmap.josm.plugins.DirectUpload;
+
+import java.net.HttpURLConnection;
+import java.util.List;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.io.OsmConnection;
+import org.openstreetmap.josm.io.OsmTransferException;
+
+/**
+ * Work-around and utility class for DirectUpload.
+ * 
+ * @author ax
+ */
+public class UploadOsmConnection extends OsmConnection {
+
+	// singleton, see http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way
+	private static final UploadOsmConnection INSTANCE = new UploadOsmConnection();
+
+	// Private constructor prevents instantiation from other classes
+	private UploadOsmConnection() {
+	}
+
+	public static UploadOsmConnection getInstance() {
+		return UploadOsmConnection.INSTANCE;
+	}
+
+	// make protected OsmConnection::addAuth() available to others
+	public void addAuthHack(HttpURLConnection connection) throws OsmTransferException {
+		addAuth(connection);
+	}
+
+    /**
+     * 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 
+     * 3. active
+     *
+     * @return data of the selected gpx layer, or null if there is none
+     */
+    GpxData autoSelectTrace() {
+        if (Main.map != null && Main.map.mapView != null) {
+            MapView mv = Main.map.mapView;
+//            List<Layer> allLayers = new ArrayList<Layer>(mv.getAllLayersAsList());  // modifiable
+            List<Layer> selectedLayers = LayerListDialog.getInstance().getModel().getSelectedLayers();
+            List<GpxLayer> gpxLayersRemaining = mv.getLayersOfType(GpxLayer.class);
+            gpxLayersRemaining.removeAll(selectedLayers);
+            GpxLayer traceLayer = null;
+            // find the first gpx layer inside selected layers
+            for (Layer l : LayerListDialog.getInstance().getModel().getSelectedLayers()) {
+                if (l instanceof GpxLayer) {
+                    traceLayer = (GpxLayer) l;
+                    break;
+                }
+            }
+            if (traceLayer == null) {
+                // 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); 
+                }
+                // active layer
+                else if (mv.getActiveLayer() instanceof GpxLayer) {
+                    traceLayer = (GpxLayer) mv.getActiveLayer(); 
+                }
+            }
+
+            if (traceLayer != null) {
+                GpxData data = traceLayer.data;
+                return data;
+            }
+        }
+        
+        return null;
+    }
+}
