<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JSAPI 4 requesting wrong url when loading WMS from third party geoserver in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1059307#M73174</link>
    <description>&lt;P&gt;I think the problem is that Mekong service is not set up properly.&amp;nbsp; The GetCapabilities is not giving a full URL in the resources' &lt;STRONG&gt;xlink:href&lt;/STRONG&gt; .&amp;nbsp;&lt;BR /&gt;&lt;A href="https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms?SERVICE=WMS&amp;amp;REQUEST=GetCapabilities" target="_blank"&gt;https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms?SERVICE=WMS&amp;amp;REQUEST=GetCapabilities&lt;/A&gt;&lt;BR /&gt;has e.g.&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;OnlineResource&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:type&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;simple&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:href&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/ows?SERVICE=WMS&amp;amp;&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;while for the ahocevar service you will see full URLs as in:&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;OnlineResource&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:type&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;simple&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:href&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;&lt;A href="https://ahocevar.com/geoserver/ows?SERVICE=WMS&amp;amp;" target="_blank"&gt;https://ahocevar.com/geoserver/ows?SERVICE=WMS&amp;amp;&lt;/A&gt;&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;The best option would be to get the service fixed.&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 05:53:04 GMT</pubDate>
    <dc:creator>BjornSvensson</dc:creator>
    <dc:date>2021-05-19T05:53:04Z</dc:date>
    <item>
      <title>JSAPI 4 requesting wrong url when loading WMS from third party geoserver</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1058917#M73153</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I tried to load this third party WMS (&lt;A href="https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms" target="_blank"&gt;https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms&lt;/A&gt;) with the following code:&amp;nbsp;(find the full code at bottom of post)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;...
let wmsLayer = new WMSLayer({
  url: "https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms" 
});

map.add(wmsLayer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The layer does not load and requests are answered with 404. In the networks tab I see that the WMS' url is changed, pointing now to&amp;nbsp;&lt;A href="https://developers.arcgis.com/" target="_blank"&gt;https://developers.arcgis.com/&lt;/A&gt;&amp;nbsp;instead of the url where the geoserver is located (The code was ran from the sandbox. It seems it always takes the url of the current site).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LukasWürsch_1-1621339959880.png" style="width: 779px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/13520i22B02D579E9AE030/image-dimensions/779x59?v=v2" width="779" height="59" role="button" title="LukasWürsch_1-1621339959880.png" alt="LukasWürsch_1-1621339959880.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Would I manually replace&amp;nbsp;&lt;A href="https://developers.arcgis.com/" target="_blank"&gt;https://developers.arcgis.com&lt;/A&gt;&amp;nbsp;from this request with the proper url where the geoserver is located (&lt;A href="https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms" target="_blank"&gt;https://data.opendevelopmentmekong.net)&lt;/A&gt;&amp;nbsp;I would get the right response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem occurs only for some WMS, it works for example for &lt;A href="https://ahocevar.com/geoserver/wms" target="_blank"&gt;https://ahocevar.com/geoserver/wms&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LukasWürsch_0-1621339346773.png" style="width: 776px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/13519i7CD5119FBE1B9144/image-dimensions/776x88?v=v2" width="776" height="88" role="button" title="LukasWürsch_0-1621339346773.png" alt="LukasWürsch_0-1621339346773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Is it possible to load the former service with ESRI API 4 so that it points to the correct url? Or is there anything else I could do to fix the issue? I would be very thankful for support or hints.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The code, running from &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/" target="_self"&gt;JSAPI4 Sandbox&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;WMSLayer - 4.19&amp;lt;/title&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.19/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.19/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/WMSLayer",
        "esri/Basemap"
      ], function (Map, MapView, WMSLayer, Basemap) {
        let wmsLayer = new WMSLayer({
          title: "WMS Layer",
          url:
            "https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms"
        });

        var map = new Map({
          basemap: "streets-vector"
        });
        var mapView = new MapView({
          map: map,
          container: "viewDiv"
        });
        map.add(wmsLayer);
      });
    
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 13:09:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1058917#M73153</guid>
      <dc:creator>LukasWürsch</dc:creator>
      <dc:date>2021-05-18T13:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: JSAPI 4 requesting wrong url when loading WMS from third party geoserver</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1059307#M73174</link>
      <description>&lt;P&gt;I think the problem is that Mekong service is not set up properly.&amp;nbsp; The GetCapabilities is not giving a full URL in the resources' &lt;STRONG&gt;xlink:href&lt;/STRONG&gt; .&amp;nbsp;&lt;BR /&gt;&lt;A href="https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms?SERVICE=WMS&amp;amp;REQUEST=GetCapabilities" target="_blank"&gt;https://data.opendevelopmentmekong.net/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/wms?SERVICE=WMS&amp;amp;REQUEST=GetCapabilities&lt;/A&gt;&lt;BR /&gt;has e.g.&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;OnlineResource&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:type&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;simple&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:href&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;/geoserver/ODMekong/lao_admbnda_adm1_ngd_20191112/ows?SERVICE=WMS&amp;amp;&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;while for the ahocevar service you will see full URLs as in:&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;OnlineResource&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:type&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;simple&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class="html-attribute"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="html-attribute-name"&gt;xlink:href&lt;/SPAN&gt;="&lt;SPAN class="html-attribute-value"&gt;&lt;A href="https://ahocevar.com/geoserver/ows?SERVICE=WMS&amp;amp;" target="_blank"&gt;https://ahocevar.com/geoserver/ows?SERVICE=WMS&amp;amp;&lt;/A&gt;&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;The best option would be to get the service fixed.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 05:53:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1059307#M73174</guid>
      <dc:creator>BjornSvensson</dc:creator>
      <dc:date>2021-05-19T05:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: JSAPI 4 requesting wrong url when loading WMS from third party geoserver</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1059331#M73176</link>
      <description>&lt;P&gt;Hi Bjorn,&lt;/P&gt;&lt;P&gt;Thank you for having a look at the service, I see now what the problem is. As I do not have access to the geoserver, I created the following workaround using &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#RequestInterceptor" target="_self"&gt;RequestInterceptor&lt;/A&gt; :&lt;/P&gt;&lt;P&gt;This changes the request url pointing to the incorrect geoserver url to a correct url before sending the request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/WMSLayer",
        "esri/Basemap",
        "esri/config"
      ], function (Map, MapView, WMSLayer, Basemap, esriConfig) {
...

var host = "https://developers.arcgis.com/"; // in case tested in the sandbox. 
var incorrectGeoserverUrl = "https://developers.arcgis.com/geoserver"; 
var correctGeoserverUrl = "https://data.opendevelopmentmekong.net/geoserver";

esriConfig.request.interceptors.push({
  urls: host,
  // change request before it is sent
  before: function(params) {
    if (params.url.includes(incorrectGeoserverUrl)) {
      params.url = params.url.replace(incorrectGeoserverUrl, correctGeoserverUrl); 
    }
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 08:29:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-requesting-wrong-url-when-loading-wms-from/m-p/1059331#M73176</guid>
      <dc:creator>LukasWürsch</dc:creator>
      <dc:date>2021-05-19T08:29:08Z</dc:date>
    </item>
  </channel>
</rss>

