Ignore:
Timestamp:
2018-05-30T19:04:15+02:00 (6 years ago)
Author:
wiktorn
Message:

Fix WMS_ENDPOINT headers.

  • Use custom headers when calling GetCapabilities on server
  • Pass custom headers and other imagery attributes after layer selection
  • if GetCapabilities document defines GetMap url, ensure that it ends with '?'

Closes: #16330

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java

    r13757 r13872  
    88import java.util.Arrays;
    99
     10import org.fest.util.Collections;
    1011import org.junit.Rule;
    1112import org.junit.Test;
    1213import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.TestUtils;
     15import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    1416import org.openstreetmap.josm.data.projection.Projections;
    1517import org.openstreetmap.josm.spi.preferences.Config;
     
    8385                + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
    8486    }
     87
     88    @Test
     89    public void testCustomHeaders() throws Exception {
     90        tileServer.stubFor(
     91                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
     92                .willReturn(
     93                        WireMock.aResponse()
     94                        .withBody(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/webatlas.no.xml")))
     95                        )
     96                );
     97
     98        tileServer.stubFor(WireMock.get(WireMock.urlEqualTo("//maps")).willReturn(WireMock.aResponse().withBody(
     99                "<?xml version='1.0' encoding='UTF-8'?>\n" +
     100                "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
     101                "  <entry>\n" +
     102                "        <name>Norway Orthophoto (historic)</name>\n" +
     103                "        <name lang=\"nb\">Norge i Bilder (historisk)</name>\n" +
     104                "        <id>geovekst-nib-historic</id>\n" +
     105                "        <type>wms_endpoint</type>\n" +
     106                "        <country-code>NO</country-code>\n" +
     107                "        <description lang=\"en\">Historic Norwegian orthophotos and maps, courtesy of Geovekst and Norkart.</description>\n" +
     108                "        <url><![CDATA[" + tileServer.url("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities") + "]]></url>\n" +
     109                "        <custom-http-header header-name=\"X-WAAPI-TOKEN\" header-value=\"b8e36d51-119a-423b-b156-d744d54123d5\" />\n" +
     110                "        <attribution-text>© Geovekst</attribution-text>\n" +
     111                "        <attribution-url>https://www.norgeibilder.no/</attribution-url>\n" +
     112                "        <permission-ref>https://forum.openstreetmap.org/viewtopic.php?id=62083</permission-ref>\n" +
     113                "        <icon>https://register.geonorge.no/data/organizations/_L_norgeibilder96x96.png</icon>\n" +
     114                "        <max-zoom>21</max-zoom>\n" +
     115                "        <valid-georeference>true</valid-georeference>\n" +
     116                "</entry>\n" +
     117                "</imagery>"
     118                )));
     119
     120        Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
     121        ImageryLayerInfo.instance.loadDefaults(true, null, false);
     122        ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
     123        wmsImageryInfo.setDefaultLayers(Collections.list(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
     124        WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
     125        tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
     126        assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", wmsImageryInfo.getCustomHttpHeaders().get("X-WAAPI-TOKEN"));
     127        assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", tileSource.getHeaders().get("X-WAAPI-TOKEN"));
     128        assertEquals(true, wmsImageryInfo.isGeoreferenceValid());
     129        tileServer.verify(
     130                WireMock.getRequestedFor(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
     131                .withHeader("X-WAAPI-TOKEN", WireMock.equalTo("b8e36d51-119a-423b-b156-d744d54123d5")));
     132        assertEquals("http://waapi.webatlas.no/wms-orto-hist/?"
     133                + "FORMAT=image/png&"
     134                + "TRANSPARENT=TRUE&"
     135                + "VERSION=1.1.1&"
     136                + "SERVICE=WMS&"
     137                + "REQUEST=GetMap&"
     138                + "LAYERS=historiske-ortofoto&"
     139                + "STYLES=&"
     140                + "SRS=EPSG:3857&"
     141                + "WIDTH=512&"
     142                + "HEIGHT=512&"
     143                + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108",
     144                tileSource.getTileUrl(1, 1, 1));
     145
     146    }
    85147}
Note: See TracChangeset for help on using the changeset viewer.