From 544b94c919155a3a49ca3ce5dfb7c2cbca2e8a57 Mon Sep 17 00:00:00 2001 From: liningrui Date: Fri, 27 Apr 2018 15:02:25 +0800 Subject: [PATCH] HugeGraph-1257: Let jersey client use preemptive credentials Change-Id: Ica97e912e905c0c7ee1353e603651794408564d1 --- .../com/baidu/hugegraph/rest/RestClient.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/baidu/hugegraph/rest/RestClient.java b/src/main/java/com/baidu/hugegraph/rest/RestClient.java index b5a8a8904..6d30c5571 100644 --- a/src/main/java/com/baidu/hugegraph/rest/RestClient.java +++ b/src/main/java/com/baidu/hugegraph/rest/RestClient.java @@ -209,13 +209,16 @@ public abstract class RestClient { String password, int timeout) { ClientConfig config = buildConfig(timeout); - - config.register(HttpAuthenticationFeature - .basicBuilder() - .nonPreemptive() - .credentials(username, password) - .build()); - + /* + * NOTE: don't use non-preemptive mode + * In non-preemptive mode the authentication information is added + * only when server refuses the request with 401 status code and + * then the request is repeated. + * Non-preemptive has negative impact on the performance. The advantage + * is that it does not send credentials when they are not needed. + * https://jersey.github.io/documentation/latest/client.html#d0e5461 + */ + config.register(HttpAuthenticationFeature.basic(username, password)); return config; }