diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index 377a5a008..4d9a193ef 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -430,6 +430,20 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map this(ApiVersion.V4, hostUrl, TokenType.PRIVATE, personalAccessToken, null, clientConfigProperties); } + /** + * Constructs a GitLabApi instance set up to interact with the GitLab server specified by GitLab API version. + * + * @param apiVersion the ApiVersion specifying which version of the API to use + * @param hostUrl the URL of the GitLab server + * @param tokenType the type of auth the token is for, PRIVATE or ACCESS + * @param authToken to token to use for access to the API + * @param secretToken use this token to validate received payloads + * @param clientConfigProperties Map instance with additional properties for the Jersey client connection + */ + public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map clientConfigProperties) { + this(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, false); + } + /** * Constructs a GitLabApi instance set up to interact with the GitLab server specified by GitLab API version. * @@ -439,12 +453,13 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map * @param authToken to token to use for access to the API * @param secretToken use this token to validate received payloads * @param clientConfigProperties Map instance with additional properties for the Jersey client connection + * @param debugging log http requests and responses */ - public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map clientConfigProperties) { + public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map clientConfigProperties, boolean debugging) { this.apiVersion = apiVersion; this.gitLabServerUrl = hostUrl; this.clientConfigProperties = clientConfigProperties; - apiClient = new GitLabApiClient(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties); + apiClient = new GitLabApiClient(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, debugging); } /** diff --git a/src/main/java/org/gitlab4j/api/GitLabApiClient.java b/src/main/java/org/gitlab4j/api/GitLabApiClient.java index a21756b93..77ded4bb8 100755 --- a/src/main/java/org/gitlab4j/api/GitLabApiClient.java +++ b/src/main/java/org/gitlab4j/api/GitLabApiClient.java @@ -14,6 +14,7 @@ import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; @@ -39,6 +40,7 @@ import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.JerseyClientBuilder; import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.logging.LoggingFeature; import org.glassfish.jersey.media.multipart.BodyPart; import org.glassfish.jersey.media.multipart.Boundary; import org.glassfish.jersey.media.multipart.FormDataBodyPart; @@ -212,6 +214,22 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, String privateToke * @param clientConfigProperties the properties given to Jersey's clientconfig */ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map clientConfigProperties) { + this(apiVersion, hostUrl, tokenType, authToken, secretToken, clientConfigProperties, false); + } + + /** + * Construct an instance to communicate with a GitLab API server using the specified GitLab API version, + * server URL and private token. + * + * @param apiVersion the ApiVersion specifying which version of the API to use + * @param hostUrl the URL to the GitLab API server + * @param tokenType the type of auth the token is for, PRIVATE or ACCESS + * @param authToken the private token to authenticate with + * @param secretToken use this token to validate received payloads + * @param clientConfigProperties the properties given to Jersey's clientconfig + * @param debugging log http requests and responses + */ + public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map clientConfigProperties, boolean debugging) { // Remove the trailing "/" from the hostUrl if present this.hostUrl = (hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl); @@ -240,6 +258,11 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp } } + if (debugging) { + 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 */)); + clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); + } + // Disable auto-discovery of feature and services lookup, this will force Jersey // to use the features and services explicitly configured by gitlab4j clientConfig.property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);