11package org .gitlab4j .api ;
22
3+ import org .gitlab4j .api .Constants .TokenType ;
4+ import org .gitlab4j .api .GitLabApi .ApiVersion ;
5+ import org .gitlab4j .api .utils .JacksonJson ;
6+ import org .gitlab4j .api .utils .MaskingLoggingFilter ;
7+ import org .glassfish .jersey .apache .connector .ApacheConnectorProvider ;
8+ import org .glassfish .jersey .client .ClientConfig ;
9+ import org .glassfish .jersey .client .ClientProperties ;
10+ import org .glassfish .jersey .client .JerseyClientBuilder ;
11+ import org .glassfish .jersey .jackson .JacksonFeature ;
12+ import org .glassfish .jersey .media .multipart .*;
13+ import org .glassfish .jersey .media .multipart .file .FileDataBodyPart ;
14+ import org .glassfish .jersey .media .multipart .file .StreamDataBodyPart ;
15+
16+ import javax .net .ssl .*;
17+ import javax .ws .rs .client .*;
18+ import javax .ws .rs .core .*;
319import java .io .File ;
420import java .io .IOException ;
521import java .io .InputStream ;
1531import java .util .logging .Level ;
1632import java .util .logging .Logger ;
1733
18- import javax .net .ssl .HostnameVerifier ;
19- import javax .net .ssl .SSLContext ;
20- import javax .net .ssl .SSLEngine ;
21- import javax .net .ssl .SSLSession ;
22- import javax .net .ssl .TrustManager ;
23- import javax .net .ssl .X509ExtendedTrustManager ;
24- import javax .ws .rs .client .Client ;
25- import javax .ws .rs .client .ClientBuilder ;
26- import javax .ws .rs .client .Entity ;
27- import javax .ws .rs .client .Invocation ;
28- import javax .ws .rs .client .WebTarget ;
29- import javax .ws .rs .core .Form ;
30- import javax .ws .rs .core .MediaType ;
31- import javax .ws .rs .core .MultivaluedMap ;
32- import javax .ws .rs .core .Response ;
33- import javax .ws .rs .core .StreamingOutput ;
34-
35- import org .gitlab4j .api .Constants .TokenType ;
36- import org .gitlab4j .api .GitLabApi .ApiVersion ;
37- import org .gitlab4j .api .utils .JacksonJson ;
38- import org .gitlab4j .api .utils .MaskingLoggingFilter ;
39- import org .glassfish .jersey .apache .connector .ApacheConnectorProvider ;
40- import org .glassfish .jersey .client .ClientConfig ;
41- import org .glassfish .jersey .client .ClientProperties ;
42- import org .glassfish .jersey .client .JerseyClientBuilder ;
43- import org .glassfish .jersey .jackson .JacksonFeature ;
44- import org .glassfish .jersey .media .multipart .BodyPart ;
45- import org .glassfish .jersey .media .multipart .Boundary ;
46- import org .glassfish .jersey .media .multipart .FormDataBodyPart ;
47- import org .glassfish .jersey .media .multipart .FormDataMultiPart ;
48- import org .glassfish .jersey .media .multipart .MultiPart ;
49- import org .glassfish .jersey .media .multipart .MultiPartFeature ;
50- import org .glassfish .jersey .media .multipart .file .FileDataBodyPart ;
51- import org .glassfish .jersey .media .multipart .file .StreamDataBodyPart ;
52-
5334/**
5435 * This class utilizes the Jersey client package to communicate with a GitLab API endpoint.
5536 */
@@ -72,9 +53,6 @@ public class GitLabApiClient implements AutoCloseable {
7253 private SSLContext openSslContext ;
7354 private HostnameVerifier openHostnameVerifier ;
7455 private Long sudoAsId ;
75- private Integer connectTimeout ;
76- private Integer readTimeout ;
77-
7856 /**
7957 * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
8058 * server URL, private token, and secret token.
@@ -259,6 +237,7 @@ public GitLabApiClient(
259237 // to use the features and services explicitly configured by gitlab4j
260238 clientConfig .property (ClientProperties .FEATURE_AUTO_DISCOVERY_DISABLE , true );
261239 clientConfig .property (ClientProperties .METAINF_SERVICES_LOOKUP_DISABLE , true );
240+ clientConfig .property (ClientProperties .FOLLOW_REDIRECTS , true );
262241
263242 clientConfig .register (JacksonJson .class );
264243 clientConfig .register (JacksonFeature .class );
@@ -304,8 +283,13 @@ void enableRequestResponseLogging(Logger logger, Level level, int maxEntityLengt
304283 * @param readTimeout the per request read timeout in milliseconds, can be null to use default
305284 */
306285 void setRequestTimeout (Integer connectTimeout , Integer readTimeout ) {
307- this .connectTimeout = connectTimeout ;
308- this .readTimeout = readTimeout ;
286+ clientConfig .property (ClientProperties .CONNECT_TIMEOUT , connectTimeout );
287+ clientConfig .property (ClientProperties .READ_TIMEOUT , readTimeout );
288+
289+ // Recreate the Client instance if already created.
290+ if (apiClient != null ) {
291+ createApiClient ();
292+ }
309293 }
310294
311295 /**
@@ -855,7 +839,7 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
855839 createApiClient ();
856840 }
857841
858- WebTarget target = apiClient .target (url .toExternalForm ()). property ( ClientProperties . FOLLOW_REDIRECTS , true ) ;
842+ WebTarget target = apiClient .target (url .toExternalForm ());
859843 if (queryParams != null ) {
860844 for (Map .Entry <String , List <String >> param : queryParams .entrySet ()) {
861845 target = target .queryParam (param .getKey (), param .getValue ().toArray ());
@@ -874,16 +858,6 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
874858 // If sudo as ID is set add the Sudo header
875859 if (sudoAsId != null && sudoAsId .intValue () > 0 ) builder = builder .header (SUDO_HEADER , sudoAsId );
876860
877- // Set the per request connect timeout
878- if (connectTimeout != null ) {
879- builder .property (ClientProperties .CONNECT_TIMEOUT , connectTimeout );
880- }
881-
882- // Set the per request read timeout
883- if (readTimeout != null ) {
884- builder .property (ClientProperties .READ_TIMEOUT , readTimeout );
885- }
886-
887861 return (builder );
888862 }
889863
0 commit comments