Changeset 2035 in josm for trunk/src


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
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java

    r2025 r2035  
    1515import org.openstreetmap.josm.data.osm.Way;
    1616import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     17import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1718import org.openstreetmap.josm.io.OsmApi;
    1819import org.openstreetmap.josm.io.OsmApiInitializationException;
     
    2425        OsmApi api = OsmApi.getOsmApi();
    2526        try {
    26             api.initialize();
     27            api.initialize(NullProgressMonitor.INSTANCE);
    2728            long maxNodes = 0;
    2829            if (api.getCapabilities().isDefined("waynodes", "maximum")) {
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2031 r2035  
    4040import org.openstreetmap.josm.io.OsmApiException;
    4141import org.openstreetmap.josm.io.OsmApiInitializationException;
     42import org.openstreetmap.josm.io.OsmChangesetCloseException;
    4243import org.openstreetmap.josm.io.OsmServerWriter;
    4344import org.openstreetmap.josm.tools.GBC;
     
    343344        }
    344345
     346        if (e instanceof OsmChangesetCloseException) {
     347            ExceptionDialogUtil.explainOsmChangesetCloseException((OsmChangesetCloseException)e);
     348            return;
     349        }
    345350        if (e instanceof OsmApiException) {
    346351            OsmApiException ex = (OsmApiException)e;
     
    493498                );
    494499                dialog.setButtonIcons(new String[] {"upload.png", "cancel.png"});
    495                 dialog.setContent(p);
     500                dialog.setContent(p, false /* no scroll pane */);
    496501                dialog.showDialog();
    497502                int result = dialog.getValue();
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r2002 r2035  
    1717import org.openstreetmap.josm.io.OsmApiException;
    1818import org.openstreetmap.josm.io.OsmApiInitializationException;
     19import org.openstreetmap.josm.io.OsmChangesetCloseException;
    1920import org.openstreetmap.josm.io.OsmTransferException;
    2021
     
    3940        JOptionPane.showMessageDialog(
    4041                Main.parent,
    41                 tr(   "Failed to initialize communication with the OSM server {0}.\n"
    42                         + "Check the server URL in your preferences and your internet connection.",
     42                tr(   "<html>Failed to initialize communication with the OSM server {0}.<br>"
     43                        + "Check the server URL in your preferences and your internet connection.</html>",
     44                        Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
     45                ),
     46                tr("Error"),
     47                JOptionPane.ERROR_MESSAGE
     48        );
     49    }
     50
     51    /**
     52     * handles an exception caught during OSM API initialization
     53     *
     54     * @param e the exception
     55     */
     56    public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) {
     57        e.printStackTrace();
     58        String changsetId = e.getChangeset() == null ? tr("unknown") : Long.toString(e.getChangeset().getId());
     59        JOptionPane.showMessageDialog(
     60                Main.parent,
     61                tr(   "<html>Failed to close changeset ''{0}'' on the OSM server ''{1}''.<br>"
     62                        + "The changeset will automatically be closed by the server after a timeout.</html>",
     63                        changsetId,
    4364                        Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
    4465                ),
     
    275296            return;
    276297        }
     298        if (e instanceof OsmChangesetCloseException){
     299            explainOsmChangesetCloseException((OsmChangesetCloseException)e);
     300            return;
     301        }
     302
    277303        if (e instanceof OsmApiException) {
    278304            OsmApiException oae = (OsmApiException)e;
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r2031 r2035  
    44
    55import java.awt.Component;
     6import java.awt.Container;
    67import java.awt.Dimension;
    78import java.awt.Frame;
     
    4041    private final String[] bTexts;
    4142    private String[] bIcons;
     43    /**
     44     * set to true if the content of the extended dialog should
     45     * be placed in a {@see JScrollPane}
     46     */
     47    private boolean placeContentInScrollPane;
    4248
    4349    // For easy access when inherited
     
    136142     */
    137143    public void setContent(Component content) {
     144        setContent(content, true);
     145    }
     146
     147    /**
     148     * Sets the content that will be displayed in the message dialog.
     149     *
     150     * Note that depending on your other settings more UI elements may appear.
     151     * The content is played on top of the other elements though.
     152     *
     153     * @param content Any element that can be displayed in the message dialog
     154     * @param placeContentInScrollPane if  true, places  the content in a JScrollPane
     155     *
     156     */
     157    public void setContent(Component content, boolean placeContentInScrollPane) {
    138158        this.content = content;
     159        this.placeContentInScrollPane = placeContentInScrollPane;
    139160    }
    140161
     
    149170     */
    150171    public void setContent(String message) {
    151         setContent(string2label(message));
    152     }
    153 
    154 
     172        setContent(string2label(message), true);
     173    }
    155174
    156175    /**
     
    222241
    223242        cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5));
    224 
    225         JScrollPane pane = new JScrollPane(cp);
    226         pane.setBorder(null);
    227         setContentPane(pane);
    228 
     243        if (placeContentInScrollPane) {
     244            JScrollPane pane = new JScrollPane(cp);
     245            pane.setBorder(null);
     246            setContentPane(pane);
     247        } else {
     248            setContentPane(cp);
     249        }
    229250        pack();
    230251
  • 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.