Changeset 35944 in osm for applications/editors


Ignore:
Timestamp:
2022-03-23T00:11:16+01:00 (3 years ago)
Author:
taylor.smock
Message:

DirectDownload: fix #21935 and #21952

#21935: "Error fetching URL" when trying to download a GPS track

This was caused due to a change in where OSM stores GPX data files.
OSM now uses s3 buckets, and redirects using a signed URL. S3 does
not like multiple authentication methods.

#21952: Only the first tag in the Tags column in "Download Track" window is shown

This was caused due to only keeping the last encountered tag.

Location:
applications/editors/josm/plugins/DirectDownload
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/DirectDownload/build.xml

    r35552 r35944  
    1313    <property name="plugin.description" value="Download your GPX tracks from openstreetmap.org"/>
    1414    <property name="plugin.icon" value="images/DownloadAction.svg"/>
     15    <property name="plugin.canloadatruntime" value="true"/>
    1516    <!-- <property name="plugin.link" value="..."/>-->
    1617    <!--<property name="plugin.early" value="..."/>-->
  • applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java

    r35221 r35944  
    55
    66import java.awt.event.ActionEvent;
     7import java.awt.event.KeyEvent;
    78import java.util.ArrayList;
    89import java.util.HashMap;
     10import java.util.List;
    911
    1012import org.openstreetmap.josm.actions.JosmAction;
     
    2022import org.openstreetmap.josm.plugins.PluginInformation;
    2123import org.openstreetmap.josm.spi.preferences.Config;
     24import org.openstreetmap.josm.tools.Shortcut;
    2225
    2326public class DirectDownload extends Plugin {
    24 
    25     private DownloadAction openaction;
    26 
    2727    /**
    2828     * Will be invoked by JOSM to bootstrap the plugin
     
    3333        super(info);
    3434
    35         openaction = new DownloadAction();
    36         MainMenu.add(MainApplication.getMenu().gpsMenu, openaction);
     35        MainMenu.add(MainApplication.getMenu().gpsMenu, new DownloadAction());
    3736    }
    3837
    3938    static class DownloadAction extends JosmAction {
    4039        DownloadAction() {
    41             super(tr("Download Track ..."), "DownloadAction",
    42                     tr("Download GPX track from openstreetmap.org"), null, false);
     40            super(tr("Download Track ..."), "DownloadAction", tr("Download GPX track from openstreetmap.org"),
     41                    Shortcut.registerShortcut("directdownload:downloadgpxaction", tr("DirectDownload: Download GPX Track"),
     42                            KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
    4343        }
    4444
     
    4848            go.setVisible(true);
    4949
    50             ArrayList<UserTrack> tracks = go.getSelectedUserTracks();
     50            List<UserTrack> tracks = go.getSelectedUserTracks();
    5151
    5252            if (!((go.getValue() == 1) && (tracks != null))) {
     
    8484                if (Config.getPref().getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
    8585                    MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer);
    86                     if (ml.data.size() > 0) {
     86                    if (!ml.data.isEmpty()) {
    8787                        MainApplication.getLayerManager().addLayer(ml);
    8888                    }
  • applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DownloadDataGui.java

    r34483 r35944  
    105105    }
    106106
    107     public ArrayList<UserTrack> getSelectedUserTracks() {
    108         ArrayList<UserTrack> DataArray = model.getDataArrayList();
     107    public List<UserTrack> getSelectedUserTracks() {
     108        List<UserTrack> dataArray = model.getDataArrayList();
    109109        int[] selected = tblSearchResults.getSelectedRows();
    110         ArrayList<UserTrack> selectedTracks = new ArrayList<>(selected.length);
    111         for (int i = 0; i < selected.length; i++) {
    112             selectedTracks.add(DataArray.get(selected[i]));
    113         }
     110        List<UserTrack> selectedTracks = new ArrayList<>(selected.length);
     111
     112        for (int i : selected) {
     113            selectedTracks.add(dataArray.get(i));
     114        }
     115
    114116        return selectedTracks;
    115117    }
     
    121123    static class NamedResultTableColumnModel extends DefaultTableColumnModel {
    122124        protected void createColumns() {
    123             TableColumn col = null;
     125            TableColumn col;
    124126            NamedResultCellRenderer renderer = new NamedResultCellRenderer();
    125127
     
    207209
    208210            case 3:
    209                 setText(sr.tags);
     211                setText(String.join(";", sr.tags));
    210212                break;
    211213
  • applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/GpxServerReader.java

    r34483 r35944  
    2323
    2424    public GpxData loadGpx(final long id) {
    25         final String urlString = OsmApi.getOsmApi().getBaseUrl() + "gpx/" + id + "/data";
     25        return fetchUrl(OsmApi.getOsmApi().getBaseUrl() + "gpx/" + id + "/data");
     26    }
    2627
     28    private GpxData fetchUrl(final String urlString) {
     29        HttpClient client = null;
    2730        try {
    28             final HttpClient client = HttpClient.create(new URL(urlString));
    29             addAuth(client);
     31            client = HttpClient.create(new URL(urlString));
     32            // At some point OSM started hosting the files on Amazon S3. S3 does not like multiple authentication methods.
     33            // See JOSM #21935.
     34            if (!urlString.contains("X-Amz-Algorithm") && !urlString.contains("Signature")) {
     35                addAuth(client);
     36            }
    3037
    3138            try (InputStream in = client.connect().uncompressAccordingToContentDisposition(true).getContent()) {
     
    3441                if (!parsedProperly) {
    3542                    JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    36                             tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", urlString));
     43                            tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.",
     44                                    urlString));
    3745                }
    3846                return r.getGpxData();
    3947            }
    4048        } catch (IOException | OsmTransferException e) {
     49            if (client != null && client.getResponse() != null
     50                    && !client.getResponse().getURL().toExternalForm().equals(urlString) /* Check if we were redirected */
     51                    && client.getRequestHeader("Authorization") != null) {
     52                // OK. We may have hit JOSM #21935.
     53                return fetchUrl(client.getResponse().getURL().toExternalForm());
     54            }
    4155            Logging.warn(e);
    4256            JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error fetching URL {0}", urlString));
  • applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/UserTrack.java

    r34381 r35944  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.directdownload;
     3
     4import java.util.ArrayList;
     5import java.util.List;
    36
    47class UserTrack {
     
    69    public String filename;
    710    public String description;
    8     public String tags;
     11    public final List<String> tags = new ArrayList<>();
    912    public String datetime;
    1013}
  • applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/UserTrackReader.java

    r34481 r35944  
    6666
    6767        @Override
    68         public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
     68        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    6969            if (qName.equals("gpx_file")) {
    7070                UserTrack track = new UserTrack();
     
    8080
    8181        @Override
    82         public void characters(char[] ch, int start, int length)
    83                 throws SAXException {
     82        public void characters(char[] ch, int start, int length) {
    8483            cdata += new String(ch, start, length);
    8584        }
    8685
    8786        @Override
    88         public void endElement(String uri, String localName, String qName) throws SAXException {
     87        public void endElement(String uri, String localName, String qName) {
    8988            if (qName.equals("description")) {
    9089                data.getFirst().description = cdata;
    9190            } else if (qName.equals("tag")) {
    92                 data.getFirst().tags = cdata;
    93                 cdata = new String();
     91                data.getFirst().tags.add(cdata);
     92                cdata = "";
    9493            }
    9594
Note: See TracChangeset for help on using the changeset viewer.