1515import java .util .logging .Level ;
1616import java .util .logging .Logger ;
1717
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 ;
18+ import javax .net .ssl .*;
19+ import javax .ws .rs .client .*;
20+ import javax .ws .rs .core .*;
3421
3522import org .gitlab4j .api .Constants .TokenType ;
3623import org .gitlab4j .api .GitLabApi .ApiVersion ;
4128import org .glassfish .jersey .client .ClientProperties ;
4229import org .glassfish .jersey .client .JerseyClientBuilder ;
4330import 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 ;
31+ import org .glassfish .jersey .media .multipart .*;
5032import org .glassfish .jersey .media .multipart .file .FileDataBodyPart ;
5133import org .glassfish .jersey .media .multipart .file .StreamDataBodyPart ;
5234
@@ -72,9 +54,6 @@ public class GitLabApiClient implements AutoCloseable {
7254 private SSLContext openSslContext ;
7355 private HostnameVerifier openHostnameVerifier ;
7456 private Long sudoAsId ;
75- private Integer connectTimeout ;
76- private Integer readTimeout ;
77-
7857 /**
7958 * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
8059 * server URL, private token, and secret token.
@@ -259,6 +238,7 @@ public GitLabApiClient(
259238 // to use the features and services explicitly configured by gitlab4j
260239 clientConfig .property (ClientProperties .FEATURE_AUTO_DISCOVERY_DISABLE , true );
261240 clientConfig .property (ClientProperties .METAINF_SERVICES_LOOKUP_DISABLE , true );
241+ clientConfig .property (ClientProperties .FOLLOW_REDIRECTS , true );
262242
263243 clientConfig .register (JacksonJson .class );
264244 clientConfig .register (JacksonFeature .class );
@@ -304,8 +284,13 @@ void enableRequestResponseLogging(Logger logger, Level level, int maxEntityLengt
304284 * @param readTimeout the per request read timeout in milliseconds, can be null to use default
305285 */
306286 void setRequestTimeout (Integer connectTimeout , Integer readTimeout ) {
307- this .connectTimeout = connectTimeout ;
308- this .readTimeout = readTimeout ;
287+ clientConfig .property (ClientProperties .CONNECT_TIMEOUT , connectTimeout );
288+ clientConfig .property (ClientProperties .READ_TIMEOUT , readTimeout );
289+
290+ // Recreate the Client instance if already created.
291+ if (apiClient != null ) {
292+ createApiClient ();
293+ }
309294 }
310295
311296 /**
@@ -855,7 +840,7 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
855840 createApiClient ();
856841 }
857842
858- WebTarget target = apiClient .target (url .toExternalForm ()). property ( ClientProperties . FOLLOW_REDIRECTS , true ) ;
843+ WebTarget target = apiClient .target (url .toExternalForm ());
859844 if (queryParams != null ) {
860845 for (Map .Entry <String , List <String >> param : queryParams .entrySet ()) {
861846 target = target .queryParam (param .getKey (), param .getValue ().toArray ());
@@ -874,16 +859,6 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
874859 // If sudo as ID is set add the Sudo header
875860 if (sudoAsId != null && sudoAsId .intValue () > 0 ) builder = builder .header (SUDO_HEADER , sudoAsId );
876861
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-
887862 return (builder );
888863 }
889864
0 commit comments