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 ;
18+ import javax .net .ssl .*;
2419
2520import jakarta .ws .rs .client .Client ;
2621import jakarta .ws .rs .client .ClientBuilder ;
4237import org .glassfish .jersey .client .ClientProperties ;
4338import org .glassfish .jersey .client .JerseyClientBuilder ;
4439import org .glassfish .jersey .jackson .JacksonFeature ;
45- import org .glassfish .jersey .media .multipart .BodyPart ;
46- import org .glassfish .jersey .media .multipart .Boundary ;
47- import org .glassfish .jersey .media .multipart .FormDataBodyPart ;
48- import org .glassfish .jersey .media .multipart .FormDataMultiPart ;
49- import org .glassfish .jersey .media .multipart .MultiPart ;
50- import org .glassfish .jersey .media .multipart .MultiPartFeature ;
40+ import org .glassfish .jersey .media .multipart .*;
5141import org .glassfish .jersey .media .multipart .file .FileDataBodyPart ;
5242import org .glassfish .jersey .media .multipart .file .StreamDataBodyPart ;
5343
@@ -73,8 +63,6 @@ public class GitLabApiClient implements AutoCloseable {
7363 private SSLContext openSslContext ;
7464 private HostnameVerifier openHostnameVerifier ;
7565 private Long sudoAsId ;
76- private Integer connectTimeout ;
77- private Integer readTimeout ;
7866 private String userAgentHeader ;
7967
8068 /**
@@ -261,6 +249,7 @@ public GitLabApiClient(
261249 // to use the features and services explicitly configured by gitlab4j
262250 clientConfig .property (ClientProperties .FEATURE_AUTO_DISCOVERY_DISABLE , true );
263251 clientConfig .property (ClientProperties .METAINF_SERVICES_LOOKUP_DISABLE , true );
252+ clientConfig .property (ClientProperties .FOLLOW_REDIRECTS , true );
264253
265254 clientConfig .register (JacksonJson .class );
266255 clientConfig .register (JacksonFeature .class );
@@ -306,8 +295,13 @@ void enableRequestResponseLogging(Logger logger, Level level, int maxEntityLengt
306295 * @param readTimeout the per request read timeout in milliseconds, can be null to use default
307296 */
308297 void setRequestTimeout (Integer connectTimeout , Integer readTimeout ) {
309- this .connectTimeout = connectTimeout ;
310- this .readTimeout = readTimeout ;
298+ clientConfig .property (ClientProperties .CONNECT_TIMEOUT , connectTimeout );
299+ clientConfig .property (ClientProperties .READ_TIMEOUT , readTimeout );
300+
301+ // Recreate the Client instance if already created.
302+ if (apiClient != null ) {
303+ createApiClient ();
304+ }
311305 }
312306
313307 /**
@@ -857,7 +851,7 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
857851 createApiClient ();
858852 }
859853
860- WebTarget target = apiClient .target (url .toExternalForm ()). property ( ClientProperties . FOLLOW_REDIRECTS , true ) ;
854+ WebTarget target = apiClient .target (url .toExternalForm ());
861855 if (queryParams != null ) {
862856 for (Map .Entry <String , List <String >> param : queryParams .entrySet ()) {
863857 target = target .queryParam (param .getKey (), param .getValue ().toArray ());
@@ -879,16 +873,6 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
879873 // If sudo as ID is set add the Sudo header
880874 if (sudoAsId != null && sudoAsId .intValue () > 0 ) builder = builder .header (SUDO_HEADER , sudoAsId );
881875
882- // Set the per request connect timeout
883- if (connectTimeout != null ) {
884- builder .property (ClientProperties .CONNECT_TIMEOUT , connectTimeout );
885- }
886-
887- // Set the per request read timeout
888- if (readTimeout != null ) {
889- builder .property (ClientProperties .READ_TIMEOUT , readTimeout );
890- }
891-
892876 return (builder );
893877 }
894878
0 commit comments