Skip to content

Commit

Permalink
avniproject/avni-webapp#1337 | Resolve issues with Remote Metabase AP…
Browse files Browse the repository at this point in the history
…I invocations with cookie
  • Loading branch information
himeshr committed Dec 4, 2024
1 parent 6751c2f commit 6f8597b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.http.MediaType;
import org.springframework.stereotype.Repository;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Repository
Expand All @@ -22,7 +23,7 @@ public class MetabaseConnector {
protected String apiKey;

public MetabaseConnector(RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = restTemplateBuilder.build();
this.restTemplate = restTemplateBuilder.additionalCustomizers(new RestTemplateStandardCookieCustomizer()).build();
}

protected HttpHeaders getHeaders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.avni.server.dao.metabase;

import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClients;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateStandardCookieCustomizer implements RestTemplateCustomizer {

@Override
public void customize(final RestTemplate restTemplate) {
final HttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
.build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
}

0 comments on commit 6f8597b

Please sign in to comment.