-
Notifications
You must be signed in to change notification settings - Fork 1.3k
WMS Authorization header #13835
Comments
With 7.0.0, we refactored how OnMapReady invocation and style loading is performed. You need to update your code to match this paradigm. Here is a simple example, you can provide a callback to that method so you have access to
This is not a feature directly exposed by the SDK but you can add this integration by using an own HttpClient. You can do this by using: Closing as answered. |
Ok Thanks Tobrun will give it a try so you mean some of the code on examples might not work on new SDK version can you please clarify here i only have 1 week working with mapBox |
Here is a migration guide @Nxele: https://github.com/mapbox/mapbox-gl-native/wiki/Android-6.x-to-7.x-migration-guide
The Android SDK in this repository uses OkHttp as HttpClient (which is the default for Android development). That library exposes a configuration for you to intercept http requests and change things to them, eg add a header. THe SDK in this repository exposes a way for you to define your own OkHttpClient and thus allow for using these interceptors. https://stackoverflow.com/questions/32196424/how-to-add-headers-to-okhttp-request-interceptor |
Hi Tobrun Just for clarity I've locked at these classes just wanna make sure if this is exactly what you are talking about I've tried this extending HttpRequest and made these changes Request.Builder builder = new Request.Builder().addHeader("Authorization",Airbus_key); but on the main call it's declared as final link to the classes https://github.com/mapbox/mapbox-gl-native/pull/12449/files#diff-70a86c6769ec7890977716965f5734b7 |
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(chain -> {
Request original = chain.request();
Request request = original.newBuilder()
.header("Header-Name", "Your-Value")
.method(original.method(), original.body())
.build();
return chain.proceed(request);
};
HttpRequestUtil.setOkHttpClient(httpClient.build());
setContentView(R.layout.activity_map_simple);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
));
} |
Thanks tobrun i was struggling with making this call HttpRequestUtil.setOkHttpClient(httpClient.build()); i was using one of the code you gave me OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
is there a huge difference but i like the one you've sent just now less code ? I'm getting this error now 2019-01-31 16:17:34.682 14787-14831/com.maps.airbusmapbox V/Mbgl-HttpRequest: [HTTP] Request was successful (code = 200). This is how i'm callling the WMS image
|
To me it look like the request went through but now it's failing to load the images |
Thanks a lot Tobrun you are a Code Hero your help was highly appreciated everything works like charm ever since you gave me that code. |
Greeting
we have a satellite image service provider called Airbus. we want to make a call to their WMS restful API using mapBox Android SDK. the issue is Airbus requires us to pass a Authorization header with the key (token) when making the call for security seasons. and on mapBox SDK you can only pass the url source as a string and not the header.
please not we can make calls to other WMS services that doesn't require Authorization header
Steps to reproduce
Expected behavior
When passing the url_source and the Authorization header with the key or token the mapBox SDK should render the image on the device.
Actual behavior
I don't get the Satellite image i get the error below
/Mbgl: {GLThread 1090}[Style]: Failed to load tile 9/296/293=>9 for source web-map-source: HTTP status code 401 (401 Authorization error code)
Configuration
Android versions: 8.1
Device models:Emulator Nexus 4
Mapbox SDK versions:6.8.1
Please note I'm using Mapbox SDK version 6.8.1 because 7.0.1 wouldn't allow me to use these methods addSource() and addLayerBelow(). but worked on 6.8.1
The text was updated successfully, but these errors were encountered: