Attivato di default l'http interceptor
This commit is contained in:
parent
6c6daa4809
commit
f8b92901fd
@ -3,6 +3,7 @@ package it.integry.integrywmsnative.core.rest;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||||
|
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
@ -17,15 +18,19 @@ public class HttpInterceptor implements Interceptor {
|
|||||||
@Override
|
@Override
|
||||||
public Response intercept(Chain chain) throws IOException {
|
public Response intercept(Chain chain) throws IOException {
|
||||||
|
|
||||||
final String PROFILE_DB = SettingsManager.i().getUserSession() == null ? null : SettingsManager.i().getUserSession().getProfileDB();
|
final String PROFILE_DB = SettingsManager.i().getUserSession() == null ? null : SettingsManager.i().getUserSession().getProfileDB();
|
||||||
final String APP_TOKEN = "fa3a21af-606b-4129-a22b-aedc2a52c7b6";
|
final String APP_TOKEN = "fa3a21af-606b-4129-a22b-aedc2a52c7b6";
|
||||||
|
|
||||||
final Request request = chain.request();
|
HttpUrl.Builder urlBuilder = chain.request().url().newBuilder();
|
||||||
final HttpUrl url = request.url().newBuilder()
|
|
||||||
.addQueryParameter("profileDb", PROFILE_DB)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Request.Builder builder = chain.request().newBuilder()
|
if (!UtilityString.isNullOrEmpty(PROFILE_DB))
|
||||||
|
urlBuilder
|
||||||
|
.addQueryParameter("profileDb", PROFILE_DB);
|
||||||
|
|
||||||
|
HttpUrl url = urlBuilder.build();
|
||||||
|
|
||||||
|
final Request.Builder requestBuilder = chain.request().newBuilder();
|
||||||
|
Request.Builder builder = requestBuilder
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.addHeader("Accept", "*/*")
|
.addHeader("Accept", "*/*")
|
||||||
.addHeader("x-app-token", APP_TOKEN);
|
.addHeader("x-app-token", APP_TOKEN);
|
||||||
|
|||||||
@ -37,19 +37,19 @@ public class RESTBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getService(final Class<T> service, int timeout) {
|
public <T> T getService(final Class<T> service, int timeout) {
|
||||||
return getService(service, SettingsManager.i().getServer().getProtocol(), SettingsManager.i().getServer().getHost(), SettingsManager.i().getServer().getPort(), true, true, timeout);
|
return getService(service, SettingsManager.i().getServer().getProtocol(), SettingsManager.i().getServer().getHost(), SettingsManager.i().getServer().getPort(), true, timeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getService(final Class<T> service, String protocol, String host, int port, boolean addInterceptors) {
|
public <T> T getService(final Class<T> service, String protocol, String host, int port) {
|
||||||
return getService(service, protocol, host, port, addInterceptors, true, 60);
|
return getService(service, protocol, host, port, true, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getService(final Class<T> service, String protocol, String host, int port, boolean addInterceptors, boolean addEmsApi) {
|
public <T> T getService(final Class<T> service, String protocol, String host, int port, boolean addEmsApi) {
|
||||||
return getService(service, protocol, host, port, addInterceptors, addEmsApi, 60);
|
return getService(service, protocol, host, port, addEmsApi, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getService(final Class<T> service, String protocol, String host, int port, boolean addInterceptors, boolean addEmsApi, int timeout) {
|
public <T> T getService(final Class<T> service, String protocol, String host, int port, boolean addEmsApi, int timeout) {
|
||||||
OkHttpClient.Builder clientBuilder = getDefaultHttpClient();
|
OkHttpClient.Builder clientBuilder = getDefaultHttpClient();
|
||||||
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
@ -62,7 +62,7 @@ public class RESTBuilder {
|
|||||||
clientBuilder.retryOnConnectionFailure(true);
|
clientBuilder.retryOnConnectionFailure(true);
|
||||||
|
|
||||||
clientBuilder.addInterceptor(authInterceptor);
|
clientBuilder.addInterceptor(authInterceptor);
|
||||||
if (addInterceptors) clientBuilder.addInterceptor(new HttpInterceptor());
|
clientBuilder.addInterceptor(new HttpInterceptor());
|
||||||
if (ADD_LOGGER_INTERCEPTOR) clientBuilder.addInterceptor(new HttpLoggerInterceptor());
|
if (ADD_LOGGER_INTERCEPTOR) clientBuilder.addInterceptor(new HttpLoggerInterceptor());
|
||||||
|
|
||||||
OkHttpClient client = clientBuilder.build();
|
OkHttpClient client = clientBuilder.build();
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class AuthenticationRESTConsumer extends _BaseRESTConsumer {
|
|||||||
String host = CommonConst.Login.Azienda.host;
|
String host = CommonConst.Login.Azienda.host;
|
||||||
int port = CommonConst.Login.Azienda.port;
|
int port = CommonConst.Login.Azienda.port;
|
||||||
|
|
||||||
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, false, true);
|
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, true);
|
||||||
service.loginAzienda(codAzienda).enqueue(new ManagedErrorCallback<>() {
|
service.loginAzienda(codAzienda).enqueue(new ManagedErrorCallback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<ServiceRESTResponse<LoginAziendaDTO>> call, Response<ServiceRESTResponse<LoginAziendaDTO>> response) {
|
public void onResponse(Call<ServiceRESTResponse<LoginAziendaDTO>> call, Response<ServiceRESTResponse<LoginAziendaDTO>> response) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user