Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-gitlab-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
java-gitlab-api
Commits
81ade3b6
Commit
81ade3b6
authored
Dec 18, 2015
by
Apanasevich Dmitrii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds request timeout support. Now big commit diffs can be handled with SocketTimeoutException.
parent
d82e68ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+10
-0
GitlabHTTPRequestor.java
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
+9
-4
No files found.
src/main/java/org/gitlab/api/GitlabAPI.java
View file @
81ade3b6
...
@@ -38,6 +38,7 @@ public class GitlabAPI {
...
@@ -38,6 +38,7 @@ public class GitlabAPI {
private
final
TokenType
tokenType
;
private
final
TokenType
tokenType
;
private
AuthMethod
authMethod
;
private
AuthMethod
authMethod
;
private
boolean
ignoreCertificateErrors
=
false
;
private
boolean
ignoreCertificateErrors
=
false
;
private
int
requestTimeout
=
0
;
private
GitlabAPI
(
String
hostUrl
,
String
apiToken
,
TokenType
tokenType
,
AuthMethod
method
)
{
private
GitlabAPI
(
String
hostUrl
,
String
apiToken
,
TokenType
tokenType
,
AuthMethod
method
)
{
this
.
hostUrl
=
hostUrl
.
endsWith
(
"/"
)
?
hostUrl
.
replaceAll
(
"/$"
,
""
)
:
hostUrl
;
this
.
hostUrl
=
hostUrl
.
endsWith
(
"/"
)
?
hostUrl
.
replaceAll
(
"/$"
,
""
)
:
hostUrl
;
...
@@ -70,6 +71,15 @@ public class GitlabAPI {
...
@@ -70,6 +71,15 @@ public class GitlabAPI {
return
this
;
return
this
;
}
}
public
int
getRequestTimeout
()
{
return
requestTimeout
;
}
public
GitlabAPI
setRequestTimeout
(
int
requestTimeout
)
{
this
.
requestTimeout
=
requestTimeout
;
return
this
;
}
public
GitlabHTTPRequestor
retrieve
()
{
public
GitlabHTTPRequestor
retrieve
()
{
return
new
GitlabHTTPRequestor
(
this
).
authenticate
(
apiToken
,
tokenType
,
authMethod
);
return
new
GitlabHTTPRequestor
(
this
).
authenticate
(
apiToken
,
tokenType
,
authMethod
);
}
}
...
...
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
View file @
81ade3b6
...
@@ -13,10 +13,7 @@ import java.io.IOException;
...
@@ -13,10 +13,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.net.HttpURLConnection
;
import
java.net.*
;
import
java.net.MalformedURLException
;
import
java.net.ProtocolException
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -296,6 +293,11 @@ public class GitlabHTTPRequestor {
...
@@ -296,6 +293,11 @@ public class GitlabHTTPRequestor {
connection
.
setRequestProperty
(
tokenType
.
getTokenHeaderName
(),
String
.
format
(
tokenType
.
getTokenHeaderFormat
(),
apiToken
));
connection
.
setRequestProperty
(
tokenType
.
getTokenHeaderName
(),
String
.
format
(
tokenType
.
getTokenHeaderFormat
(),
apiToken
));
}
}
final
int
requestTimeout
=
root
.
getRequestTimeout
();
if
(
requestTimeout
>
0
)
{
connection
.
setReadTimeout
(
requestTimeout
);
}
try
{
try
{
connection
.
setRequestMethod
(
method
);
connection
.
setRequestMethod
(
method
);
}
catch
(
ProtocolException
e
)
{
}
catch
(
ProtocolException
e
)
{
...
@@ -351,6 +353,9 @@ public class GitlabHTTPRequestor {
...
@@ -351,6 +353,9 @@ public class GitlabHTTPRequestor {
if
(
e
instanceof
FileNotFoundException
)
{
if
(
e
instanceof
FileNotFoundException
)
{
throw
e
;
// pass through 404 Not Found to allow the caller to handle it intelligently
throw
e
;
// pass through 404 Not Found to allow the caller to handle it intelligently
}
}
if
(
e
instanceof
SocketTimeoutException
&&
root
.
getRequestTimeout
()
>
0
)
{
throw
e
;
}
InputStream
es
=
wrapStream
(
connection
,
connection
.
getErrorStream
());
InputStream
es
=
wrapStream
(
connection
,
connection
.
getErrorStream
());
try
{
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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