Ignore:
Timestamp:
2009-12-04T15:53:55+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #3684: Add "chunked" upload mode
Removed support for API "0.5" when uploading (there are still 0.5-files around, but I'm not aware of any 0.5-servers)

File:
1 edited

Legend:

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

    r2512 r2569  
    145145
    146146    /**
    147      * Returns true if the negotiated version supports diff uploads.
    148      * @return true if the negotiated version supports diff uploads
    149      */
    150     public boolean hasSupportForDiffUploads() {
    151         return ((version != null) && (version.compareTo("0.6")>=0));
    152     }
    153 
    154     /**
    155147     * Initializes this component by negotiating a protocol version with the server.
    156148     *
     
    168160            if (capabilities.supportsVersion("0.6")) {
    169161                version = "0.6";
    170             } else if (capabilities.supportsVersion("0.5")) {
    171                 version = "0.5";
    172162            } else {
    173163                System.err.println(tr("This version of JOSM is incompatible with the configured server."));
    174                 System.err.println(tr("It supports protocol versions 0.5 and 0.6, while the server says it supports {0} to {1}.",
     164                System.err.println(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.",
    175165                        capabilities.get("version", "minimum"), capabilities.get("version", "maximum")));
    176166                initialized = false;
     
    256246
    257247    /**
    258      * Modifies an OSM primitive on the server. For protocols greater than 0.5,
    259      * the OsmPrimitive object passed in is modified by giving it the server-assigned
    260      * version.
    261      *
    262      * @param osm the primitive. Must not be null
     248     * Modifies an OSM primitive on the server.
     249     *
     250     * @param osm the primitive. Must not be null.
     251     * @param monitor the progress monitor
    263252     * @throws OsmTransferException if something goes wrong
    264253     */
     
    268257            ensureValidChangeset();
    269258            initialize(monitor);
    270             if (version.equals("0.5")) {
    271                 // legacy mode does not return the new object version.
    272                 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor);
    273             } else {
    274                 // normal mode (0.6 and up) returns new object version.
    275                 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor);
    276                 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim()));
    277             }
     259            // normal mode (0.6 and up) returns new object version.
     260            ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor);
     261            osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim()));
    278262        } catch(NumberFormatException e) {
    279263            throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret));
     
    359343            );
    360344        } catch(OsmApiException e) {
    361             if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT)
    362                 throw new ChangesetClosedException(e.getErrorHeader());
     345            if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT && ChangesetClosedException.errorHeaderMatchesPattern(e.getErrorHeader()))
     346                throw new ChangesetClosedException(e.getErrorHeader(), ChangesetClosedException.Source.UPDATE_CHANGESET);
    363347            throw e;
    364348        } finally {
     
    569553                case HttpURLConnection.HTTP_GONE:
    570554                    throw new OsmApiPrimitiveGoneException(errorHeader, errorBody);
     555                case HttpURLConnection.HTTP_CONFLICT:
     556                    if (ChangesetClosedException.errorHeaderMatchesPattern(errorHeader))
     557                        throw new ChangesetClosedException(errorBody, ChangesetClosedException.Source.UPLOAD_DATA);
     558                    else
     559                        throw new OsmApiException(retCode, errorHeader, errorBody);
    571560                default:
    572561                    throw new OsmApiException(retCode, errorHeader, errorBody);
     
    642631        this.changeset = changeset;
    643632    }
    644 
    645633}
Note: See TracChangeset for help on using the changeset viewer.