Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
874 B
0
Indexable
Never
public class TFERestClientGenerator {
    // ...

    public <S> S createService(Class<S> serviceClass) {
        SrvPise srvPise = new SrvPise(); // Initialiser SrvPise ici
        String piseAccessToken = srvPise.getAccessTokenFromPISE(); // Appeler la méthode sur srvPise
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(chain -> {
            Request original = chain.request();
            Request.Builder requestBuilder = original.newBuilder()
                    .header("Authorization", "Bearer " + piseAccessToken)
                    .method(original.method(), original.body());

            Request request = requestBuilder.build();
            return chain.proceed(request);
        });

        builder.client(httpClient.build());
        return builder.build().create(serviceClass);
    }

    // ...
}