Load a FeatureLayer with Stored Credentials and Limit Usage to a Map

1014
1
Jump to solution
07-23-2019 05:36 PM
marceloctorres
Esri Contributor
I'm trying to load a FeatureLayer with Stored Credentials from ArcGIS Online to a Map using ArcGIS SDK Runtime for Android. This is the code:
    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?

Marcelo César Torres
0 Kudos
1 Solution

Accepted Solutions
marceloctorres
Esri Contributor

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. >(

Marcelo César Torres

View solution in original post

0 Kudos
1 Reply
marceloctorres
Esri Contributor

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. >(

Marcelo César Torres
0 Kudos