Skip to content

Commit

Permalink
Misc Swagger and timeout fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Sep 26, 2023
1 parent c73d2d9 commit 85de9eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ext {
springBootVersion = '2.6.6'
springVersion = '6.0.6'
springOauth2Version = "2.5.1.RELEASE"
springDocVersion = '1.6.14'
springDocVersion = '2.2.0'
lombokVersion = '1.18.26'
junit5Version = '5.9.2'
radarSpringAuthVersion = '1.2.0'
Expand Down Expand Up @@ -68,7 +68,7 @@ dependencies {
runtimeOnly("org.hibernate.validator:hibernate-validator:$hibernateValidatorVersion")

// Open API spec
implementation(group: 'org.springdoc', name: 'springdoc-openapi-ui', version: springDocVersion)
implementation(group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: springDocVersion)


//runtimeOnly('org.springframework.boot:spring-boot-devtools')
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/org/radarbase/appserver/service/GithubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class GithubClient {
private static final String GITHUB_API_URI = "api.github.com";
private static final String GITHUB_API_ACCEPT_HEADER = "application/vnd.github.v3+json";
private final transient HttpClient client;

@Nonnull
private final transient String authorizationHeader;

private transient final Duration httpTimeout;
private transient final Executor executor;

@Value("${security.github.client.maxContentLength:1000000}")
private transient int maxContentLength;
Expand All @@ -64,11 +68,11 @@ public GithubClient(
@Value("${security.github.client.token:}") String githubToken) {
this.authorizationHeader = githubToken != null ? "Bearer " + githubToken.trim() : "";
this.httpTimeout = Duration.ofSeconds(httpTimeout);
this.client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(this.httpTimeout)
.build();
this.executor = new ThreadPoolExecutor(0,
8,
30,
TimeUnit.SECONDS,
new SynchronousQueue<>());
}

public String getGithubContent(String url) throws IOException, InterruptedException {
Expand All @@ -94,6 +98,12 @@ public String getGithubContent(String url) throws IOException, InterruptedExcept
}

private HttpResponse<InputStream> makeRequest(URI uri) throws InterruptedException {
HttpClient client = HttpClient.newBuilder()
.executor(executor)
.version(HttpClient.Version.HTTP_1_1)
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(this.httpTimeout)
.build();
try {
return client.send(getRequest(uri), HttpResponse.BodyHandlers.ofInputStream());
} catch (IOException ex) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ security.radar.managementportal.url=http://localhost:8081
#security.oauth2.client.userAuthorizationUri=
# Github Authentication
security.github.client.token=
security.github.client.timeout=PT10s
security.github.client.timeout=10
# max content size 1 MB
security.github.client.maxContentLength=1000000
security.github.cache.size=10000
Expand Down

0 comments on commit 85de9eb

Please sign in to comment.