private void loadFeatureLayerWithStoredCredentials(String publicUrl) { ArcGISMap map = new ArcGISMap(Basemap.Type.STREETS, xCenter, yCenter, zoomLevel); ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(publicUrl); serviceFeatureTable.addDoneLoadingListener(() -> serviceFeatureTableProcess(serviceFeatureTable)); FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable); map.getOperationalLayers().add(featureLayer); mapView.setMap(map); }
Attending customer requirements about security and limitations of access, I have to add Limit Usage to the Feature Layer:
And I have to change the code to add Referer Header to the request:
private void loadFeatureLayerWithStoredCredentials(String urlPublico, String referer) { ArcGISMap map = new ArcGISMap(Basemap.Type.STREETS, xCenter, yCenter, zoomLevel); ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(urlPublico); serviceFeatureTable.addDoneLoadingListener(() -> serviceFeatureTableProcess(serviceFeatureTable)); RequestConfiguration request = new RequestConfiguration(); request.getHeaders().put("Referer", referer); serviceFeatureTable.setRequestConfiguration(request); FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable); map.getOperationalLayers().add(featureLayer); mapView.setMap(map); }
Since then I began to get this error:
Error: com.esri.arcgisruntime.io.JsonEmbeddedException: You do not have permissions
to access this resource or perform this operation.
Can somebody help me?
Solved! Go to Solution.
The answer is very simple but strange, in this line:
request.getHeaders().put("Referer", referer);
The key must be in lowercase, I mean: "referer" that's all. >(
The answer is very simple but strange, in this line:
request.getHeaders().put("Referer", referer);
The key must be in lowercase, I mean: "referer" that's all. >(