Changeset 31871 in osm for applications


Ignore:
Timestamp:
2015-12-27T16:20:38+01:00 (9 years ago)
Author:
donvip
Message:

[josm_directupload] update to JOSM 9179

Location:
applications/editors/josm/plugins/DirectUpload
Files:
3 edited

Legend:

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

    r30416 r31871  
    55    <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])"/>
    66    <!-- 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"/>
    88
    99    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java

    r30737 r31871  
    1313import java.awt.GridBagLayout;
    1414import java.awt.event.ActionEvent;
    15 import java.io.ByteArrayInputStream;
    1615import java.io.ByteArrayOutputStream;
    1716import java.io.IOException;
    18 import java.io.InputStream;
    19 import java.io.OutputStream;
    20 import java.net.HttpURLConnection;
    2117import java.net.URL;
    2218import java.text.DecimalFormat;
     
    4541import org.openstreetmap.josm.io.OsmApi;
    4642import org.openstreetmap.josm.tools.GBC;
    47 import org.openstreetmap.josm.tools.Utils;
     43import org.openstreetmap.josm.tools.HttpClient;
     44import org.openstreetmap.josm.tools.HttpClient.Response;
    4845
    4946/**
     
    236233            writeString(baos, "--" + BOUNDARY + "--" + LINE_END);
    237234
    238             ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    239             HttpURLConnection conn = setupConnection(baos.size());
     235            HttpClient conn = setupConnection(baos.size());
    240236
    241237            progressMonitor.setTicksCount(baos.size());
    242238            progressMonitor.subTask(null);
    243239
    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);
    245243
    246244            if (canceled) {
    247                 conn.disconnect();
     245                response.disconnect();
    248246                GuiHelper.runInEDT(new Runnable() {
    249247                    @Override public void run() {
     
    255253            }
    256254            else {
    257                 final boolean success = finishUpConnection(conn);
     255                final boolean success = finishUpConnection(response);
    258256                GuiHelper.runInEDT(new Runnable() {
    259257                    @Override public void run() {
     
    285283     * @return HttpURLConnection The set up conenction
    286284     */
    287     private HttpURLConnection setupConnection(int contentLength) throws Exception {
     285    private HttpClient setupConnection(int contentLength) throws Exception {
    288286
    289287        // Upload URL
     
    291289
    292290        // 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);
    298292        // unfortunately, addAuth() is protected, so we need to subclass OsmConnection
    299293        // XXX make addAuth public.
    300294        UploadOsmConnection.getInstance().addAuthHack(c);
    301295
    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", "");
    306299
    307300        return c;
     
    314307     * @param HttpURLConnection The connection to check/finish up
    315308     */
    316     private boolean finishUpConnection(HttpURLConnection c) throws Exception {
     309    private boolean finishUpConnection(Response c) throws Exception {
    317310        String returnMsg = c.getResponseMessage();
    318311        final boolean success = returnMsg.equals("OK");
     
    342335     * @param OutputStream
    343336     */
    344     private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception {
     337/*    private void flushToServer(InputStream in, OutputStream out, ProgressMonitor progressMonitor) throws Exception {
    345338        // Upload in 10 kB chunks
    346339        byte[] buffer = new byte[10000];
     
    364357        buffer = null;
    365358    }
    366 
     359*/
    367360    /**
    368361     * Generates the output string displayed in the PleaseWaitDialog.
     
    373366        int max = progressMonitor.getTicksCount();
    374367        int percent = Math.round(cur * 100 / max);
     368        // FIXME method kept because of translated string
    375369        return tr("Uploading GPX track: {0}% ({1} of {2})",
    376370                        percent, formatBytes(cur), formatBytes(max));
  • applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadOsmConnection.java

    r30347 r31871  
    33package org.openstreetmap.josm.plugins.DirectUpload;
    44
    5 import java.net.HttpURLConnection;
    65import java.util.List;
    76
     
    1413import org.openstreetmap.josm.io.OsmConnection;
    1514import org.openstreetmap.josm.io.OsmTransferException;
     15import org.openstreetmap.josm.tools.HttpClient;
    1616
    1717/**
    1818 * Work-around and utility class for DirectUpload.
    19  * 
     19 *
    2020 * @author ax
    2121 */
     
    3434
    3535    // make protected OsmConnection::addAuth() available to others
    36     public void addAuthHack(HttpURLConnection connection) throws OsmTransferException {
     36    public void addAuthHack(HttpClient connection) throws OsmTransferException {
    3737        addAuth(connection);
    3838    }
     
    4040    /**
    4141     * find which gpx layer holds the trace to upload. layers are tried in this order:
    42      * 
     42     *
    4343     * 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
    4545     * 3. active
    4646     *
     
    6565                // if there is none, try the none selected gpx layers. if there is only one, use it.
    6666                if (gpxLayersRemaining.size() == 1) {
    67                     traceLayer = gpxLayersRemaining.get(0); 
     67                    traceLayer = gpxLayersRemaining.get(0);
    6868                }
    6969                // active layer
    7070                else if (mv.getActiveLayer() instanceof GpxLayer) {
    71                     traceLayer = (GpxLayer) mv.getActiveLayer(); 
     71                    traceLayer = (GpxLayer) mv.getActiveLayer();
    7272                }
    7373            }
     
    7878            }
    7979        }
    80        
     80
    8181        return null;
    8282    }
Note: See TracChangeset for help on using the changeset viewer.