Ignore:
Timestamp:
2009-09-03T13:02:19+02:00 (15 years ago)
Author:
Gubaer
Message:

Improved user feedback in case of timed retries after InternalServerErrors
Improved user feedback in case of problems with closing changesets

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

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

    r2025 r2035  
    157157     * @exception OsmApiInitializationException thrown, if an exception occurs
    158158     */
    159     public void initialize() throws OsmApiInitializationException {
     159    public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException {
    160160        if (initialized)
    161161            return;
    162162        initAuthentication();
    163163        try {
    164             String s = sendRequest("GET", "capabilities", null);
     164            String s = sendRequest("GET", "capabilities", null,monitor);
    165165            InputSource inputSource = new InputSource(new StringReader(s));
    166166            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
     
    227227     * @throws OsmTransferException if something goes wrong
    228228     */
    229     public void createPrimitive(OsmPrimitive osm) throws OsmTransferException {
    230         initialize();
     229    public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
     230        initialize(monitor);
    231231        String ret = "";
    232232        try {
    233             ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true));
     233            ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor);
    234234            osm.id = Long.parseLong(ret.trim());
    235235            osm.version = 1;
     
    247247     * @throws OsmTransferException if something goes wrong
    248248     */
    249     public void modifyPrimitive(OsmPrimitive osm) throws OsmTransferException {
    250         initialize();
     249    public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
     250        initialize(monitor);
    251251        if (version.equals("0.5")) {
    252252            // legacy mode does not return the new object version.
    253             sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true));
     253            sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor);
    254254        } else {
    255255            String ret = null;
    256256            // normal mode (0.6 and up) returns new object version.
    257257            try {
    258                 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true));
     258                ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor);
    259259                osm.version = Integer.parseInt(ret.trim());
    260260            } catch(NumberFormatException e) {
     
    270270     */
    271271    public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
    272         initialize();
     272        initialize(monitor);
    273273        // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow
    274274        // submitting a DELETE request with content, the 0.6 API requires it, however. Falling back
     
    291291            changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
    292292            changeset.put("comment", comment);
    293             createPrimitive(changeset);
     293            createPrimitive(changeset, progressMonitor);
    294294        } finally {
    295295            progressMonitor.finishTask();
     
    305305        progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId()));
    306306        try {
    307             initialize();
    308             sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null);
     307            initialize(progressMonitor);
     308            sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor);
    309309            changeset = null;
    310310        } finally {
     
    327327                throw new OsmTransferException(tr("No changeset present for diff upload"));
    328328
    329             initialize();
     329            initialize(progressMonitor);
    330330            final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>();
    331331
     
    341341            String diff = duv.getDocument();
    342342            try {
    343                 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff);
     343                String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff,progressMonitor);
    344344                DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(),
    345345                        progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     
    358358
    359359
    360     private void sleepAndListen() throws OsmTransferCancelledException {
     360    private void sleepAndListen(int retry, ProgressMonitor monitor) throws OsmTransferCancelledException {
    361361        System.out.print(tr("Waiting 10 seconds ... "));
    362362        for(int i=0; i < 10; i++) {
     363            if (monitor != null) {
     364                monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry,getMaxRetries(), 10-i));
     365            }
    363366            if (cancel || isAuthCancelled())
    364367                throw new OsmTransferCancelledException();
     
    395398     *    been exhausted), or rewrapping a Java exception.
    396399     */
    397     private String sendRequest(String requestMethod, String urlSuffix,
    398             String requestBody) throws OsmTransferException {
     400    private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException {
    399401
    400402        StringBuffer responseBody = new StringBuffer();
     
    436438                if (retCode >= 500) {
    437439                    if (retries-- > 0) {
    438                         sleepAndListen();
    439                         int maxRetries = getMaxRetries();
    440                         System.out.println(tr("Starting retry {0} of {1}.", maxRetries - retries,maxRetries));
     440                        sleepAndListen(retries, monitor);
     441                        System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries,getMaxRetries()));
    441442                        continue;
    442443                    }
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r1875 r2035  
    4040    protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException  {
    4141        try {
    42             api.initialize();
     42            api.initialize(progressMonitor);
    4343            urlStr = api.getBaseUrl() + urlStr;
    4444            return getInputStreamRaw(urlStr, progressMonitor);
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r2025 r2035  
    125125                }
    126126            } catch(Exception e) {
    127                 Changeset changeset = api.getCurrentChangeset();
    128                 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId()));
    129                 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}",
    130                         changesetId, e.toString()));
     127                OsmChangesetCloseException closeException = new OsmChangesetCloseException(e);
     128                closeException.setChangeset(api.getCurrentChangeset());
     129                throw closeException;
    131130            }
    132131        }
     
    154153                api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
    155154            } catch (Exception ee) {
    156                 Changeset changeset = api.getCurrentChangeset();
    157                 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId()));
    158                 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}",
    159                         changesetId, ee.toString()));
     155                OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee);
     156                closeException.setChangeset(api.getCurrentChangeset());
     157                throw closeException;
    160158            }
    161159        }
     
    171169        processed = new LinkedList<OsmPrimitive>();
    172170
    173         api.initialize();
     171        api.initialize(progressMonitor);
    174172
    175173        try {
     
    199197            api.deletePrimitive(osm, progressMonitor);
    200198        } else if (osm.getId() == 0) {
    201             api.createPrimitive(osm);
     199            api.createPrimitive(osm, progressMonitor);
    202200        } else {
    203             api.modifyPrimitive(osm);
     201            api.modifyPrimitive(osm,progressMonitor);
    204202        }
    205203    }
Note: See TracChangeset for help on using the changeset viewer.