Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
7af51b86
Commit
7af51b86
authored
Feb 10, 2018
by
Greg Messner
Browse files
Mods to support using a proxy server (#141).
parent
cff589a9
Changes
4
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
7af51b86
...
@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
...
@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
```
java
```
java
dependencies
{
dependencies
{
...
...
compile
group:
'
org
.
gitlab4j
'
,
name:
'
gitlab4j
-
api
'
,
version:
'
4.8
.
1
'
compile
group:
'
org
.
gitlab4j
'
,
name:
'
gitlab4j
-
api
'
,
version:
'
4.8
.
2
'
}
}
```
```
...
@@ -20,7 +20,7 @@ dependencies {
...
@@ -20,7 +20,7 @@ dependencies {
<dependency>
<dependency>
<groupId>
org.gitlab4j
</groupId>
<groupId>
org.gitlab4j
</groupId>
<artifactId>
gitlab4j-api
</artifactId>
<artifactId>
gitlab4j-api
</artifactId>
<version>
4.8.
1
</version>
<version>
4.8.
2
</version>
</dependency>
</dependency>
```
```
...
@@ -68,7 +68,20 @@ gitLabApi.sudo("johndoe")
...
@@ -68,7 +68,20 @@ gitLabApi.sudo("johndoe")
// To turn off sudo mode
// To turn off sudo mode
gitLabApi
.
unsudo
();
gitLabApi
.
unsudo
();
```
```
---
## Connecting Through a Proxy Server
As of GitLab4J-API 4.8.2 support has been added for connecting to the GitLab server using an HTTP proxy server
:
```
java
// Log in to the GitLab server using a proxy server (with basic auth on proxy)
Map<String, Object> proxyConfiguration = ProxyClientConfig.createProxyClientConfig("http://your-proxy-server", "proxy-username", "proxy-password");
GitLabApi gitLabApi = new GitLabApi("http://your.gitlab.server.com", "YOUR_PRIVATE_TOKEN",
null
, proxyConfiguration);
```
```
java
// Log in to the GitLab server using a proxy server (no auth on proxy)
Map<String, Object> proxyConfiguration = ProxyClientConfig.createProxyClientConfig("http://your-proxy-server");
GitLabApi gitLabApi = new GitLabApi("http://your.gitlab.server.com", "YOUR_PRIVATE_TOKEN",
null
, proxyConfiguration);
```
*NOTE
:
See the Javadoc on the GitLabApi class for a complete list of methods accepting the proxy configuration (clientConfiguration parameter)*
---
---
## GitLab API V3 and V4 Support
## GitLab API V3 and V4 Support
As of GitLab4J-API 4.2.0 support has been added for GitLab API V4. If your application requires GitLab API V3,
As of GitLab4J-API 4.2.0 support has been added for GitLab API V4. If your application requires GitLab API V3,
...
...
pom.xml
View file @
7af51b86
...
@@ -222,6 +222,11 @@
...
@@ -222,6 +222,11 @@
<artifactId>
jersey-client
</artifactId>
<artifactId>
jersey-client
</artifactId>
<version>
${jersey.version}
</version>
<version>
${jersey.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.glassfish.jersey.connectors
</groupId>
<artifactId>
jersey-apache-connector
</artifactId>
<version>
${jersey.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<artifactId>
javax.servlet-api
</artifactId>
...
...
src/main/java/org/gitlab4j/api/GitLabApiClient.java
View file @
7af51b86
...
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response;
...
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response;
import
org.gitlab4j.api.Constants.TokenType
;
import
org.gitlab4j.api.Constants.TokenType
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.glassfish.jersey.apache.connector.ApacheConnectorProvider
;
import
org.glassfish.jersey.client.ClientConfig
;
import
org.glassfish.jersey.client.ClientConfig
;
import
org.glassfish.jersey.client.ClientProperties
;
import
org.glassfish.jersey.client.ClientProperties
;
...
@@ -211,6 +212,11 @@ public class GitLabApiClient {
...
@@ -211,6 +212,11 @@ public class GitLabApiClient {
clientConfig
=
new
ClientConfig
();
clientConfig
=
new
ClientConfig
();
if
(
clientConfigProperties
!=
null
)
{
if
(
clientConfigProperties
!=
null
)
{
if
(
clientConfigProperties
.
containsKey
(
ClientProperties
.
PROXY_URI
))
{
clientConfig
.
connectorProvider
(
new
ApacheConnectorProvider
());
}
for
(
Map
.
Entry
<
String
,
Object
>
propertyEntry
:
clientConfigProperties
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Object
>
propertyEntry
:
clientConfigProperties
.
entrySet
())
{
clientConfig
.
property
(
propertyEntry
.
getKey
(),
propertyEntry
.
getValue
());
clientConfig
.
property
(
propertyEntry
.
getKey
(),
propertyEntry
.
getValue
());
}
}
...
...
src/test/java/org/gitlab4j/api/TestGitLabApi.java
View file @
7af51b86
...
@@ -3,7 +3,8 @@ package org.gitlab4j.api;
...
@@ -3,7 +3,8 @@ package org.gitlab4j.api;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
java.util.Map
;
import
org.gitlab4j.api.models.Version
;
import
org.gitlab4j.api.models.Version
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
...
@@ -23,9 +24,15 @@ public class TestGitLabApi {
...
@@ -23,9 +24,15 @@ public class TestGitLabApi {
// The following needs to be set to your test repository
// The following needs to be set to your test repository
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
private
static
final
String
TEST_PROXY_URI
;
private
static
final
String
TEST_PROXY_USERNAME
;
private
static
final
String
TEST_PROXY_PASSWORD
;
static
{
static
{
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
TEST_PROXY_URI
=
TestUtils
.
getProperty
(
"TEST_PROXY_URI"
);
TEST_PROXY_USERNAME
=
TestUtils
.
getProperty
(
"TEST_PROXY_USERNAME"
);
TEST_PROXY_PASSWORD
=
TestUtils
.
getProperty
(
"TEST_PROXY_PASSWORD"
);
}
}
private
static
GitLabApi
gitLabApi
;
private
static
GitLabApi
gitLabApi
;
...
@@ -47,7 +54,7 @@ public class TestGitLabApi {
...
@@ -47,7 +54,7 @@ public class TestGitLabApi {
}
}
if
(
problems
.
isEmpty
())
{
if
(
problems
.
isEmpty
())
{
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
gitLabApi
=
new
GitLabApi
(
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
}
else
{
}
else
{
System
.
err
.
print
(
problems
);
System
.
err
.
print
(
problems
);
}
}
...
@@ -66,4 +73,19 @@ public class TestGitLabApi {
...
@@ -66,4 +73,19 @@ public class TestGitLabApi {
assertNotNull
(
version
.
getVersion
());
assertNotNull
(
version
.
getVersion
());
assertNotNull
(
version
.
getRevision
());
assertNotNull
(
version
.
getRevision
());
}
}
@Test
public
void
testProxyConnection
()
throws
GitLabApiException
{
assumeTrue
(
TEST_PROXY_URI
!=
null
&&
TEST_PROXY_USERNAME
!=
null
&&
TEST_PROXY_PASSWORD
!=
null
);
// Setup a GitLabApi instance to use a proxy
Map
<
String
,
Object
>
clientConfig
=
ProxyClientConfig
.
createProxyClientConfig
(
TEST_PROXY_URI
,
TEST_PROXY_USERNAME
,
TEST_PROXY_PASSWORD
);
GitLabApi
gitLabApi
=
new
GitLabApi
(
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
,
null
,
clientConfig
);
Version
version
=
gitLabApi
.
getVersion
();
assertNotNull
(
version
);
System
.
out
.
format
(
"version=%s, revision=%s%n"
,
version
.
getVersion
(),
version
.
getRevision
());
assertNotNull
(
version
.
getVersion
());
assertNotNull
(
version
.
getRevision
());
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment