AnsweredAssumed Answered

CORS Javascript API problem

Question asked by bmnds on Nov 19, 2015
Latest reply on Nov 25, 2015 by bmnds

I've implemented an example of FeatureLayer filtering using a Buffer geometry running from local disk and it worked like a charm out-of-the-box, here is a snippet of it:

 

function filterSegVia(geometry) {
  var query = new esri.tasks.Query();
  query.geometry = geometry;
  segViaLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
}

 

When I tried to load the map inside a JSP from a Java application running on JBoss server, I got this error message:

esri.config.defaults.io.proxyUrl não está configurado. Se fizer um pedido para um servidor CORS habilitado, mande o domínio para esri.config.defaults.io.corsEnabledServers

 

I tried to add the server domain and IP to 'corsEnabledServer' config as stated above but the same error occurred:

esri.config.defaults.io.corsEnabledServers.push("services-gis.prodam.am.gov.br");
esri.config.defaults.io.corsEnabledServers.push("10.20.1.245");

 

I did another test hosting my app in Mongoose, a very lightweight web server, and it worked. Here is the captured request from the API, header and data:

  1. POST /arcgis/rest/services/Dynamic/IdentificacaoSISP/FeatureServer/12/query HTTP/1.1 Host: services-gis.prodam.am.gov.br Connection: keep-alive Content-Length: 3294 Origin: http://localhost User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36 Content-Type: application/x-www-form-urlencoded Accept: */* Referer: http://localhost/featureLayerFiltering.html Accept-Encoding: gzip, deflate Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
  2. f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry=%7B%22rings%22%3A%5B%5B%5B-59.99709160681768%2C-3.000937507636297%5D%2C%5B-59.9970989883816%2C-3.00079665900631%5D%2C%5B-59.997121052199375%2C-3.000657353543388%5D%2C%5B-59.99715755653522%2C-3.000521117507333%5D%2C%5B-59.99720810143998%2C-3.000389443528667%5D%2C%5B-59.9972721331331%2C-3.0002637742550538%5D%2C%5B-59.99734895006996%2C-3.000145486545353%5D%2C%5B-59.99743771062813%2C-3.000035876384466%5D%2C%5B-59.997537442328344%2C-2.9999361446842525%5D%2C%5B-59.99764705248923%2C-2.99984738412609%5D%2C%5B-59.99776534019893%2C-2.9997705671892283%5D%2C%5B-59.99789100947254%2C-2.999706535496103%5D%2C%5B-59.99802268345121%2C-2.999655990591343%5D%2C%5B-59.99815891948726%2C-2.999619486255502%5D%2C%5B-59.99829822495018%2C-2.999597422437723%5D%2C%5B-59.99843907358017%2C-2.9995900408738105%5D%2C%5B-59.99857992221016%2C-2.999597422437723%5D%2C%5B-59.998719227673085%2C-2.999619486255502%5D%2C%5B-59.998855463709134%2C-2.999655990591343%5D%2C%5B-59.998987137687806%2C-2.999706535496103%5D%2C%5B-59.99911280696141%2C-2.9997705671892283%5D%2C%5B-59.99923109467112%2C-2.99984738412609%5D%2C%5B-59.999340704832%2C-2.9999361446842525%5D%2C%5B-59.99944043653222%2C-3.000035876384466%5D%2C%5B-59.99952919709038%2C-3.000145486545353%5D%2C%5B-59.99960601402724%2C-3.0002637742550538%5D%2C%5B-59.999670045720364%2C-3.000389443528667%5D%2C%5B-59.999720590625124%2C-3.000521117507333%5D%2C%5B-59.99975709496097%2C-3.000657353543388%5D%2C%5B-59.99977915877874%2C-3.00079665900631%5D%2C%5B-59.99978654034266%2C-3.000937507636297%5D%2C%5B-59.99977915877874%2C-3.0010783562662837%5D%2C%5B-59.99975709496097%2C-3.001217661729206%5D%2C%5B-59.999720590625124%2C-3.0013538977652607%5D%2C%5B-59.999670045720364%2C-3.001485571743927%5D%2C%5B-59.99960601402724%2C-3.00161124101754%5D%2C%5B-59.99952919709038%2C-3.0017295287272407%5D%2C%5B-59.99944043653222%2C-3.001839138888128%5D%2C%5B-59.999340704832%2C-3.0019388705883414%5D%2C%5B-59.99923109467112%2C-3.002027631146504%5D%2C%5B-59.99911280696141%2C-3.0021044480833656%5D%2C%5B-59.998987137687806%2C-3.0021684797764907%5D%2C%5B-59.998855463709134%2C-3.002219024681251%5D%2C%5B-59.998719227673085%2C-3.002255529017092%5D%2C%5B-59.99857992221016%2C-3.002277592834871%5D%2C%5B-59.99843907358017%2C-3.0022849743987834%5D%2C%5B-59.99829822495018%2C-3.002277592834871%5D%2C%5B-59.99815891948726%2C-3.002255529017092%5D%2C%5B-59.99802268345121%2C-3.002219024681251%5D%2C%5B-59.99789100947254%2C-3.0021684797764907%5D%2C%5B-59.99776534019893%2C-3.0021044480833656%5D%2C%5B-59.99764705248923%2C-3.002027631146504%5D%2C%5B-59.997537442328344%2C-3.0019388705883414%5D%2C%5B-59.99743771062813%2C-3.001839138888128%5D%2C%5B-59.99734895006996%2C-3.0017295287272407%5D%2C%5B-59.9972721331331%2C-3.00161124101754%5D%2C%5B-59.99720810143998%2C-3.001485571743927%5D%2C%5B-59.99715755653522%2C-3.0013538977652607%5D%2C%5B-59.997121052199375%2C-3.001217661729206%5D%2C%5B-59.9970989883816%2C-3.0010783562662837%5D%2C%5B-59.99709160681768%2C-3.000937507636297%5D%2C%5B-59.99709160681768%2C-3.000937507636297%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%2C%22latestWkid%22%3A4326%7D%7D&geometryType=esriGeometryPolygon&inSR=4326&outFields=OBJECTID%2CANNOT_ANTERIOR%2CANNOT_ATUAL%2CANNOT_POPULAR&outSR=4326

 

As a final test, I've created a POST request manually using the following script in order to make the same request from the map loaded from Jboss:

 

var data = new FormData()
data.append('f','json')
data.append('returnGeometry','true')
data.append('spatialRel','esriSpatialRelIntersects')
data.append('geometryType','esriGeometryPolygon')
data.append('inSR','4326')
data.append('outSR','4326')
data.append('outFields','OBJECTID%2CANNOT_ANTERIOR%2CANNOT_ATUAL%2CANNOT_POPULAR')
data.append('geometry','%7B%22rings%22%3A%5B%5B%5B-59.99709160681768%2C-3.000937507636297%5D%2C%5B-59.9970989883816%2C-3.00079665900631%5D%2C%5B-59.997121052199375%2C-3.000657353543388%5D%2C%5B-59.99715755653522%2C-3.000521117507333%5D%2C%5B-59.99720810143998%2C-3.000389443528667%5D%2C%5B-59.9972721331331%2C-3.0002637742550538%5D%2C%5B-59.99734895006996%2C-3.000145486545353%5D%2C%5B-59.99743771062813%2C-3.000035876384466%5D%2C%5B-59.997537442328344%2C-2.9999361446842525%5D%2C%5B-59.99764705248923%2C-2.99984738412609%5D%2C%5B-59.99776534019893%2C-2.997705671892283%5D%2C%5B-59.99789100947254%2C-2.999706535496103%5D%2C%5B-59.99802268345121%2C-2.999655990591343%5D%2C%5B-59.99815891948726%2C-2.999619486255502%5D%2C%5B-59.99829822495018%2C-2.999597422437723%5D%2C%5B-59.99843907358017%2C-2.9995900408738105%5D%2C%5B-59.99857992221016%2C-2.999597422437723%5D%2C%5B-59.998719227673085%2C-2.999619486255502%5D%2C%5B-59.998855463709134%2C-2.999655990591343%5D%2C%5B-59.998987137687806%2C-2.999706535496103%5D%2C%5B-59.99911280696141%2C-2.9997705671892283%5D%2C%5B-59.99923109467112%2C-2.99984738412609%5D%2C%5B-59.999340704832%2C-2.9999361446842525%5D%2C%5B-59.99944043653222%2C-3.000035876384466%5D%2C%5B-59.99952919709038%2C-3.000145486545353%5D%2C%5B-59.99960601402724%2C-3.0002637742550538%5D%2C%5B-59.999670045720364%2C-3.000389443528667%5D%2C%5B-59.999720590625124%2C-3.000521117507333%5D%2C%5B-59.99975709496097%2C-3.000657353543388%5D%2C%5B-59.99977915877874%2C-3.00079665900631%5D%2C%5B-59.99978654034266%2C-3.000937507636297%5D%2C%5B-59.99977915877874%2C-3.0010783562662837%5D%2C%5B-59.99975709496097%2C-3.001217661729206%5D%2C%5B-59.999720590625124%2C-3.0013538977652607%5D%2C%5B-59.999670045720364%2C-3.001485571743927%5D%2C%5B-59.99960601402724%2C-3.00161124101754%5D%2C%5B-59.99952919709038%2C-3.0017295287272407%5D%2C%5B-59.99944043653222%2C-3.001839138888128%5D%2C%5B-59.999340704832%2C-3.0019388705883414%5D%2C%5B-59.99923109467112%2C-3.002027631146504%5D%2C%5B-59.99911280696141%2C-3.0021044480833656%5D%2C%5B-59.998987137687806%2C-3.0021684797764907%5D%2C%5B-59.998855463709134%2C-3.002219024681251%5D%2C%5B-59.998719227673085%2C-3.002255529017092%5D%2C%5B-59.99857992221016%2C-3.002277592834871%5D%2C%5B-59.99843907358017%2C-3.0022849743987834%5D%2C%5B-59.99829822495018%2C-3.002277592834871%5D%2C%5B-59.99815891948726%2C-3.002255529017092%5D%2C%5B-59.99802268345121%2C-3.002219024681251%5D%2C%5B-59.99789100947254%2C-3.0021684797764907%5D%2C%5B-59.99776534019893%2C-3.0021044480833656%5D%2C%5B-59.99764705248923%2C-3.002027631146504%5D%2C%5B-59.997537442328344%2C-3.0019388705883414%5D%2C%5B-59.99743771062813%2C-3.001839138888128%5D%2C%5B-59.99734895006996%2C-3.0017295287272407%5D%2C%5B-59.9972721331331%2C-3.00161124101754%5D%2C%5B-59.99720810143998%2C-3.001485571743927%5D%2C%5B-59.99715755653522%2C-3.0013538977652607%5D%2C%5B-59.997121052199375%2C-3.001217661729206%5D%2C%5B-59.9970989883816%2C-3.0010783562662837%5D%2C%5B-59.99709160681768%2C-3.000937507636297%5D%2C%5B-59.99709160681768%2C-3.000937507636297%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%2C%22latestWkid%22%3A4326%7D%7D')


var request = new XMLHttpRequest()
request.open('POST', 'http://10.20.1.153/arcgis/rest/services/Dynamic/IdentificacaoSISP/FeatureServer/12')
request.onreadystatechange = function () {
  if (this.status == 200 && this.readyState == 4) {
    console.log('response: ' + this.responseText)
  }
}
request.send(data)

 

And it worked. No CORS error.

 

So, how to solve this? Does the fact that the app is running on JBoss interfere with the ArcGIS Javascript API?

Maybe a bug from the API?

Outcomes