Ignore:
Timestamp:
2015-07-04T22:52:23+02:00 (5 years ago)
Author:
wiktorn
Message:

Basic WMTS support.

  • added information about units and to_meter to EPSG projection definitions (needed for WMTS)
  • added WMTSTileSource and WMTSLayer classes
  • a bit of cleanup of AbstractTileSourceLayer and align so it will work properly with WMTS tile definitions
  • added Imagery Preferences panel for WMTS and icon for button
  • added removal of wms: / tms: / wmts: prefix, if user will paste them into the field
  • CachedFile - added possibility to send custom headers with request
  • added support for unit and to_meter in CustomProjection
  • AbstractTMSTileSource cleanups (change of Coordinate to ICoordinate)
  • moved JCSCachedTileLoaderJob.read() to Utils

Addresses: #10623

Tested with Polish WMTS service proivders, Walonnie needs still some debugging, as it is not working right now.

File:
1 edited

Legend:

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

    r8510 r8568  
    2020import java.util.Enumeration;
    2121import java.util.List;
     22import java.util.Map;
     23import java.util.Map.Entry;
     24import java.util.concurrent.ConcurrentHashMap;
    2225import java.util.zip.ZipEntry;
    2326import java.util.zip.ZipFile;
     
    7275    public static final long DAYS = 24*60*60; // factor to get caching time in days
    7376
     77    private Map<String, String> httpHeaders = new ConcurrentHashMap<>();
     78
    7479    /**
    7580     * Constructs a CachedFile object from a given filename, URL or internal resource.
     
    142147    public CachedFile setCachingStrategy(CachingStrategy cachingStrategy) {
    143148        this.cachingStrategy = cachingStrategy;
     149        return this;
     150    }
     151
     152    /**
     153     * Sets the http headers. Only applies to URL pointing to http or https resources
     154     * @param headers that should be sent together with request
     155     * @return this object
     156     */
     157    public CachedFile setHttpHeaders(Map<String, String> headers) {
     158        this.httpHeaders.putAll(headers);
    144159        return this;
    145160    }
     
    397412        destDirFile = new File(destDir, localPath + ".tmp");
    398413        try {
    399             HttpURLConnection con = connectFollowingRedirect(url, httpAccept, ifModifiedSince);
     414            HttpURLConnection con = connectFollowingRedirect(url, httpAccept, ifModifiedSince, httpHeaders);
    400415            if (ifModifiedSince != null && con.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
    401416                if (Main.isDebugEnabled()) {
     
    464479    public static HttpURLConnection connectFollowingRedirect(URL downloadUrl, String httpAccept, Long ifModifiedSince)
    465480            throws MalformedURLException, IOException {
     481        return connectFollowingRedirect(downloadUrl, httpAccept, ifModifiedSince, null);
     482    }
     483    /**
     484     * Opens a connection for downloading a resource.
     485     * <p>
     486     * Manually follows redirects because
     487     * {@link HttpURLConnection#setFollowRedirects(boolean)} fails if the redirect
     488     * is going from a http to a https URL, see <a href="https://bugs.openjdk.java.net/browse/JDK-4620571">bug report</a>.
     489     * <p>
     490     * This can cause problems when downloading from certain GitHub URLs.
     491     *
     492     * @param downloadUrl The resource URL to download
     493     * @param httpAccept The accepted MIME types sent in the HTTP Accept header. Can be {@code null}
     494     * @param ifModifiedSince The download time of the cache file, optional
     495     * @param headers http headers to be sent together with http request
     496     * @return The HTTP connection effectively linked to the resource, after all potential redirections
     497     * @throws MalformedURLException If a redirected URL is wrong
     498     * @throws IOException If any I/O operation goes wrong
     499     * @throws OfflineAccessException if resource is accessed in offline mode, in any protocol
     500     * @since TODO
     501     */
     502    public static HttpURLConnection connectFollowingRedirect(URL downloadUrl, String httpAccept, Long ifModifiedSince, Map<String, String> headers)
     503            throws MalformedURLException, IOException {
    466504        CheckParameterUtil.ensureParameterNotNull(downloadUrl, "downloadUrl");
    467505        String downloadString = downloadUrl.toExternalForm();
     
    474512            if (ifModifiedSince != null) {
    475513                con.setIfModifiedSince(ifModifiedSince);
     514            }
     515            if (headers != null) {
     516                for (Entry<String, String> header: headers.entrySet()) {
     517                    con.setRequestProperty(header.getKey(), header.getValue());
     518                }
    476519            }
    477520            con.setInstanceFollowRedirects(false);
Note: See TracChangeset for help on using the changeset viewer.