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
fbbe0dbf
Commit
fbbe0dbf
authored
Mar 02, 2014
by
Greg Messner
Browse files
Refactored to move all message model classes to models package.
parent
56afbdf1
Changes
30
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/GitLabApiClient.java
View file @
fbbe0dbf
...
...
@@ -12,6 +12,7 @@ import javax.net.ssl.HostnameVerifier;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.SSLSocketFactory
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
javax.ws.rs.core.MediaType
;
...
...
@@ -31,7 +32,7 @@ import com.sun.jersey.client.urlconnection.HTTPSProperties;
/**
* This class utilizes the Jersey client package to communicate with a GitLab API endpoint.
*
* @author
g
messner
* @author
Greg Messner <greg@
messner
s.com>
*/
public
class
GitLabApiClient
{
...
...
@@ -42,7 +43,18 @@ public class GitLabApiClient {
private
Client
apiClient
;
private
String
hostUrl
;
private
String
privateToken
;
private
static
boolean
ignoreCertificateErrors
;
private
static
SSLSocketFactory
defaultSocketFactory
;
private
static
HTTPSProperties
defaultHttpsProperties
;
/**
* Construct an instance to communicate with a GitLab API server using the specified
* server URL and private token.
*
* @param hostUrl the URL to the GitLab API server
* @param privateToken the private token to authenticate with
*/
public
GitLabApiClient
(
String
hostUrl
,
String
privateToken
)
{
// Remove the trailing "/" from the hostUrl if present
...
...
@@ -56,7 +68,56 @@ public class GitLabApiClient {
}
protected
boolean
ignoreCertificateErrors
()
{
/**
* Returns true if the API is setup to ignore SSL certificate errors, otherwise returns false.
*
* @return true if the API is setup to ignore SSL certificate errors, otherwise returns false
*/
protected
boolean
getIgnoreCertificateErrors
()
{
return
(
GitLabApiClient
.
ignoreCertificateErrors
);
}
/**
* Sets up the Jersey system ignore SSL certificate errors or not.
*
* <p><strong>WARNING: Setting this to true will affect ALL uses of HttpsURLConnection and Jersey.<strong><p>
*
* @param ignoreCertificateErrors
*/
protected
void
setIgnoreCerificateErrors
(
boolean
ignoreCertificateErrors
)
{
if
(
GitLabApiClient
.
ignoreCertificateErrors
==
ignoreCertificateErrors
)
{
return
;
}
if
(
ignoreCertificateErrors
==
false
)
{
GitLabApiClient
.
ignoreCertificateErrors
=
false
;
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
GitLabApiClient
.
defaultSocketFactory
);
clientConfig
.
getProperties
().
put
(
HTTPSProperties
.
PROPERTY_HTTPS_PROPERTIES
,
GitLabApiClient
.
defaultHttpsProperties
);
return
;
}
SSLSocketFactory
defaultSocketFactory
=
HttpsURLConnection
.
getDefaultSSLSocketFactory
();
HTTPSProperties
defaultHttpsProperties
=
(
HTTPSProperties
)
clientConfig
.
getProperties
().
get
(
HTTPSProperties
.
PROPERTY_HTTPS_PROPERTIES
);
if
(
ignoreCertificateErrors
()
==
true
)
{
GitLabApiClient
.
ignoreCertificateErrors
=
true
;
GitLabApiClient
.
defaultSocketFactory
=
defaultSocketFactory
;
GitLabApiClient
.
defaultHttpsProperties
=
defaultHttpsProperties
;
}
else
{
throw
new
RuntimeException
(
"Unable to ignore certificate errors."
);
}
}
/**
* Sets up Jersey client to ignore certificate errors.
*
* @return true if successful at setting up to ignore certificate errors, otherwise returns false.
*/
private
boolean
ignoreCertificateErrors
()
{
// Create a TrustManager that trusts all certificates
TrustManager
[
]
certs
=
new
TrustManager
[
]
{
...
...
@@ -77,16 +138,19 @@ public class GitLabApiClient {
};
// Now set the default SSLSocketFactory to use the just created TrustManager
SSLSocketFactory
defaultSocketFactory
=
HttpsURLConnection
.
getDefaultSSLSocketFactory
();
SSLContext
sslContext
=
null
;
try
{
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
sslContext
.
init
(
null
,
certs
,
new
SecureRandom
());
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sslContext
.
getSocketFactory
());
HttpsURLConnection
.
getDefaultSSLSocketFactory
();
}
catch
(
GeneralSecurityException
ex
)
{
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
defaultSocketFactory
);
return
(
false
);
}
// Set up a HostnameVerifier for Jersey to verify all hostnames
// Set up a HostnameVerifier for Jersey to verify all hostnames
as valid
try
{
clientConfig
.
getProperties
().
put
(
HTTPSProperties
.
PROPERTY_HTTPS_PROPERTIES
,
new
HTTPSProperties
(
...
...
@@ -99,6 +163,7 @@ public class GitLabApiClient {
));
}
catch
(
NoSuchAlgorithmException
e
)
{
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
defaultSocketFactory
);
return
(
false
);
}
...
...
@@ -106,7 +171,13 @@ public class GitLabApiClient {
}
/**
* Construct a REST URL with the specified path arguments.
*
* @param pathArgs
* @return a REST URL with the specified path arguments
* @throws IOException
*/
protected
URL
getApiUrl
(
Object
...
pathArgs
)
throws
IOException
{
StringBuilder
url
=
new
StringBuilder
();
...
...
@@ -118,15 +189,36 @@ public class GitLabApiClient {
return
(
new
URL
(
url
.
toString
()));
}
/**
* Perform an HTTP GET call with the specified query parameters and path objects, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param queryParams
* @param pathArgs
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
* @throws IOException
*/
protected
ClientResponse
get
(
MultivaluedMap
<
String
,
String
>
queryParams
,
Object
...
pathArgs
)
throws
UniformInterfaceException
,
ClientHandlerException
,
IOException
{
URL
url
=
getApiUrl
(
pathArgs
);
return
(
get
(
queryParams
,
url
));
}
/**
* Perform an HTTP GET call with the specified query parameters and URL, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param queryParams
* @param url
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
*/
protected
ClientResponse
get
(
MultivaluedMap
<
String
,
String
>
queryParams
,
URL
url
)
throws
UniformInterfaceException
,
ClientHandlerException
{
...
...
@@ -145,13 +237,34 @@ public class GitLabApiClient {
}
/**
* Perform an HTTP POST call with the specified form data and path objects, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param formData
* @param pathArgs
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
* @throws IOException
*/
protected
ClientResponse
post
(
Form
formData
,
Object
...
pathArgs
)
throws
UniformInterfaceException
,
ClientHandlerException
,
IOException
{
URL
url
=
getApiUrl
(
pathArgs
);
return
(
post
(
formData
,
url
));
}
/**
* Perform an HTTP POST call with the specified form data and URL, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param formData
* @param url
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
*/
protected
ClientResponse
post
(
Form
formData
,
URL
url
)
throws
UniformInterfaceException
,
ClientHandlerException
{
if
(
apiClient
==
null
)
{
...
...
@@ -166,13 +279,34 @@ public class GitLabApiClient {
}
/**
* Perform an HTTP DELETE call with the specified form data and path objects, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param queryParams
* @param pathArgs
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
* @throws IOException
*/
protected
ClientResponse
delete
(
MultivaluedMap
<
String
,
String
>
queryParams
,
Object
...
pathArgs
)
throws
UniformInterfaceException
,
ClientHandlerException
,
IOException
{
URL
url
=
getApiUrl
(
pathArgs
);
return
(
delete
(
queryParams
,
url
));
}
/**
* Perform an HTTP DELETE call with the specified form data and URL, returning
* a ClientResponse instance with the data returned from the endpoint.
*
* @param queryParams
* @param url
* @return a ClientResponse instance with the data returned from the endpoint
* @throws UniformInterfaceException
* @throws ClientHandlerException
*/
protected
ClientResponse
delete
(
MultivaluedMap
<
String
,
String
>
queryParams
,
URL
url
)
throws
UniformInterfaceException
,
ClientHandlerException
{
...
...
src/main/java/com/messners/gitlab/api/AbstractUser.java
→
src/main/java/com/messners/gitlab/api/
models/
AbstractUser.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
src/main/java/com/messners/gitlab/api/Assignee.java
→
src/main/java/com/messners/gitlab/api/
models/
Assignee.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlRootElement
;
...
...
src/main/java/com/messners/gitlab/api/Author.java
→
src/main/java/com/messners/gitlab/api/
models/
Author.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlRootElement
;
...
...
src/main/java/com/messners/gitlab/api/Branch.java
→
src/main/java/com/messners/gitlab/api/
models/
Branch.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/Commit.java
→
src/main/java/com/messners/gitlab/api/
models/
Commit.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
import
java.util.List
;
...
...
src/main/java/com/messners/gitlab/api/Committer.java
→
src/main/java/com/messners/gitlab/api/
models/
Committer.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlRootElement
;
...
...
src/main/java/com/messners/gitlab/api/Diff.java
→
src/main/java/com/messners/gitlab/api/
models/
Diff.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/ErrorMessage.java
→
src/main/java/com/messners/gitlab/api/
models/
ErrorMessage.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
...
...
src/main/java/com/messners/gitlab/api/Event.java
→
src/main/java/com/messners/gitlab/api/
models/
Event.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/EventData.java
→
src/main/java/com/messners/gitlab/api/
models/
EventData.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.List
;
...
...
src/main/java/com/messners/gitlab/api/Group.java
→
src/main/java/com/messners/gitlab/api/
models/
Group.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/Issue.java
→
src/main/java/com/messners/gitlab/api/
models/
Issue.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
import
java.util.List
;
...
...
src/main/java/com/messners/gitlab/api/Key.java
→
src/main/java/com/messners/gitlab/api/
models/
Key.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
src/main/java/com/messners/gitlab/api/Member.java
→
src/main/java/com/messners/gitlab/api/
models/
Member.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
src/main/java/com/messners/gitlab/api/MergeRequest.java
→
src/main/java/com/messners/gitlab/api/
models/
MergeRequest.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/MergeRequestComment.java
→
src/main/java/com/messners/gitlab/api/
models/
MergeRequestComment.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
src/main/java/com/messners/gitlab/api/Milestone.java
→
src/main/java/com/messners/gitlab/api/
models/
Milestone.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
src/main/java/com/messners/gitlab/api/Namespace.java
→
src/main/java/com/messners/gitlab/api/
models/
Namespace.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
src/main/java/com/messners/gitlab/api/Note.java
→
src/main/java/com/messners/gitlab/api/
models/
Note.java
View file @
fbbe0dbf
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
.models
;
import
java.util.Date
;
...
...
Prev
1
2
Next
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