Skip to content

Commit

Permalink
Merge remote-tracking branch 'jmini/patch-15' into 6.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/gitlab4j/api/GitLabApiClient.java
  • Loading branch information
jmini committed Dec 19, 2023
2 parents 982f4b6 + 69bdcc3 commit 1ee2b02
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/gitlab4j/api/GitLabApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,20 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map<String, Object>
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<String, Object> 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.
*
Expand All @@ -439,12 +453,13 @@ public GitLabApi(String hostUrl, String personalAccessToken, Map<String, Object>
* @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<String, Object> clientConfigProperties) {
public GitLabApi(ApiVersion apiVersion, String hostUrl, TokenType tokenType, String authToken, String secretToken, Map<String, Object> 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);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/gitlab4j/api/GitLabApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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<String, Object> clientConfigProperties, boolean debugging) {

// Remove the trailing "/" from the hostUrl if present
this.hostUrl = (hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1ee2b02

Please sign in to comment.