Skip to content

Commit 69bdcc3

Browse files
committed
Add debugging flag
1 parent f7441c7 commit 69bdcc3

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map<String, Object>
430430
this(ApiVersion.V4, hostUrl, TokenType.PRIVATE, personalAccessToken, null, clientConfigProperties);
431431
}
432432

433+
/**
434+
* Constructs a GitLabApi instance set up to interact with the GitLab server specified by GitLab API version.
435+
*
436+
* @param apiVersion the ApiVersion specifying which version of the API to use
437+
* @param hostUrl the URL of the GitLab server
438+
* @param tokenType the type of auth the token is for, PRIVATE or ACCESS
439+
* @param authToken to token to use for access to the API
440+
* @param secretToken use this token to validate received payloads
441+
* @param clientConfigProperties Map instance with additional properties for the Jersey client connection
442+
*/
443+
public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> clientConfigProperties) {
444+
this(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, false);
445+
}
446+
433447
/**
434448
* Constructs a GitLabApi instance set up to interact with the GitLab server specified by GitLab API version.
435449
*
@@ -439,12 +453,13 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map<String, Object>
439453
* @param authToken to token to use for access to the API
440454
* @param secretToken use this token to validate received payloads
441455
* @param clientConfigProperties Map instance with additional properties for the Jersey client connection
456+
* @param debugging log http requests and responses
442457
*/
443-
public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> clientConfigProperties) {
458+
public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> clientConfigProperties, boolean debugging) {
444459
this.apiVersion = apiVersion;
445460
this.gitLabServerUrl = hostUrl;
446461
this.clientConfigProperties = clientConfigProperties;
447-
apiClient = new GitLabApiClient(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties);
462+
apiClient = new GitLabApiClient(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, debugging);
448463
}
449464

450465
/**

src/main/java/org/gitlab4j/api/GitLabApiClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.function.Supplier;
1515
import java.util.logging.Level;
1616
import java.util.logging.Logger;
17+
1718
import javax.net.ssl.HostnameVerifier;
1819
import javax.net.ssl.SSLContext;
1920
import javax.net.ssl.SSLEngine;
@@ -30,6 +31,7 @@
3031
import javax.ws.rs.core.MultivaluedMap;
3132
import javax.ws.rs.core.Response;
3233
import javax.ws.rs.core.StreamingOutput;
34+
3335
import org.gitlab4j.api.Constants.TokenType;
3436
import org.gitlab4j.api.GitLabApi.ApiVersion;
3537
import org.gitlab4j.api.utils.JacksonJson;
@@ -39,6 +41,7 @@
3941
import org.glassfish.jersey.client.ClientProperties;
4042
import org.glassfish.jersey.client.JerseyClientBuilder;
4143
import org.glassfish.jersey.jackson.JacksonFeature;
44+
import org.glassfish.jersey.logging.LoggingFeature;
4245
import org.glassfish.jersey.media.multipart.BodyPart;
4346
import org.glassfish.jersey.media.multipart.Boundary;
4447
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
@@ -212,6 +215,22 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, String privateToke
212215
* @param clientConfigProperties the properties given to Jersey's clientconfig
213216
*/
214217
public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> clientConfigProperties) {
218+
this(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, false);
219+
}
220+
221+
/**
222+
* Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
223+
* server URL and private token.
224+
*
225+
* @param apiVersion the ApiVersion specifying which version of the API to use
226+
* @param hostUrl the URL to the GitLab API server
227+
* @param tokenType the type of auth the token is for, PRIVATE or ACCESS
228+
* @param authToken the private token to authenticate with
229+
* @param secretToken use this token to validate received payloads
230+
* @param clientConfigProperties the properties given to Jersey's clientconfig
231+
* @param debugging log http requests and responses
232+
*/
233+
public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> clientConfigProperties, boolean debugging) {
215234

216235
// Remove the trailing "/" from the hostUrl if present
217236
this.hostUrl = (hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl);
@@ -240,6 +259,11 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp
240259
}
241260
}
242261

262+
if (debugging) {
263+
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024 * 50 /* Log payloads up to 50K */));
264+
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
265+
}
266+
243267
// Disable auto-discovery of feature and services lookup, this will force Jersey
244268
// to use the features and services explicitly configured by gitlab4j
245269
clientConfig.property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);

0 commit comments

Comments
 (0)