Changeset 17498 in josm for trunk/src/org


Ignore:
Timestamp:
2021-02-20T22:03:24+01:00 (4 years ago)
Author:
Don-vip
Message:

code refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r17333 r17498  
    458458            String ret = "";
    459459            try {
    460                 ret = sendRequest("PUT", "changeset/create", toXml(changeset), progressMonitor);
     460                ret = sendPutRequest("changeset/create", toXml(changeset), progressMonitor);
    461461                changeset.setId(Integer.parseInt(ret.trim()));
    462462                changeset.setOpen(true);
     
    493493            initialize(monitor);
    494494            monitor.setCustomText(tr("Updating changeset {0}...", changeset.getId()));
    495             sendRequest(
    496                     "PUT",
    497                     "changeset/" + changeset.getId(),
    498                     toXml(changeset),
    499                     monitor
    500             );
     495            sendPutRequest("changeset/" + changeset.getId(), toXml(changeset), monitor);
    501496        } catch (ChangesetClosedException e) {
    502497            e.setSource(ChangesetClosedException.Source.UPDATE_CHANGESET);
     
    532527            monitor.beginTask(tr("Closing changeset..."));
    533528            initialize(monitor);
    534             /* send "\r\n" instead of empty string, so we don't send zero payload - works around bugs
    535                in proxy software */
    536             sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", "\r\n", monitor);
     529            // send "\r\n" instead of empty string, so we don't send zero payload - workaround bugs in proxy software
     530            sendPutRequest("changeset/" + changeset.getId() + "/close", "\r\n", monitor);
    537531            changeset.setOpen(false);
    538532        } finally {
     
    571565            monitor.indeterminateSubTask(
    572566                    trn("Uploading {0} object...", "Uploading {0} objects...", list.size(), list.size()));
    573             String diffUploadResponse = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diffUploadRequest, monitor);
     567            String diffUploadResponse = sendPostRequest("changeset/" + changeset.getId() + "/upload", diffUploadRequest, monitor);
    574568
    575569            // Process the response from the server
     
    633627    public static String getAuthMethod() {
    634628        return Config.getPref().get("osm-server.auth-method", "oauth");
     629    }
     630
     631    protected final String sendPostRequest(String urlSuffix, String requestBody, ProgressMonitor monitor) throws OsmTransferException {
     632        // Send a POST request that includes authentication credentials
     633        return sendRequest("POST", urlSuffix, requestBody, monitor);
     634    }
     635
     636    protected final String sendPutRequest(String urlSuffix, String requestBody, ProgressMonitor monitor) throws OsmTransferException {
     637        // Send a PUT request that includes authentication credentials
     638        return sendRequest("PUT", urlSuffix, requestBody, monitor);
    635639    }
    636640
     
    820824            .append(Utils.encodeUrl(text)).toString();
    821825
    822         String response = sendRequest("POST", noteUrl, null, monitor, true, false);
    823         return parseSingleNote(response);
     826        return parseSingleNote(sendPostRequest(noteUrl, null, monitor));
    824827    }
    825828
     
    838841            .append(Utils.encodeUrl(comment)).toString();
    839842
    840         String response = sendRequest("POST", noteUrl, null, monitor, true, false);
    841         return parseSingleNote(response);
     843        return parseSingleNote(sendPostRequest(noteUrl, null, monitor));
    842844    }
    843845
     
    860862        }
    861863
    862         String response = sendRequest("POST", urlBuilder.toString(), null, monitor, true, false);
    863         return parseSingleNote(response);
     864        return parseSingleNote(sendPostRequest(urlBuilder.toString(), null, monitor));
    864865    }
    865866
     
    882883        }
    883884
    884         String response = sendRequest("POST", urlBuilder.toString(), null, monitor, true, false);
    885         return parseSingleNote(response);
     885        return parseSingleNote(sendPostRequest(urlBuilder.toString(), null, monitor));
    886886    }
    887887
Note: See TracChangeset for help on using the changeset viewer.