Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Olog HttpClient timeout and URL encoding #3238

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ public static Builder builder() {
* Disallow instantiation.
*/
private OlogHttpClient(String userName, String password) {
httpClient = HttpClient.newBuilder()
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
.followRedirects(HttpClient.Redirect.ALWAYS)
// HttpClient rejects Duration.ZERO for the connect timeout value.
// To support infinite timeout (preference value == 0), use Long.MAX_VALUE
.connectTimeout(Duration.ofMillis(Preferences.connectTimeout <= 0 ? Long.MAX_VALUE : Preferences.connectTimeout))
.build();
if(Preferences.connectTimeout > 0){
httpClient = HttpClient.newBuilder()
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
.followRedirects(HttpClient.Redirect.ALWAYS)
.connectTimeout(Duration.ofMillis(Preferences.connectTimeout))
.build();
}
else{
httpClient = HttpClient.newBuilder()
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
.followRedirects(HttpClient.Redirect.ALWAYS)
.build();
}

if (userName != null && password != null) {
this.basicAuthenticationHeader = "Basic " + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes());
Expand Down Expand Up @@ -456,7 +462,8 @@ public Collection<Property> listProperties() {
public InputStream getAttachment(Long logId, String attachmentName) {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(Preferences.olog_url + "/logs/attachments/" + logId + "/" + URLEncoder.encode(attachmentName, StandardCharsets.UTF_8)))
.uri(URI.create(Preferences.olog_url + "/logs/attachments/" + logId + "/" +
URLEncoder.encode(attachmentName, StandardCharsets.UTF_8).replace("+", "%20"))) // + char does not work in path element!
.GET()
.build();
HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@ public LogEntryTable(final LogEntryTableApp app) {
loader.setResources(resourceBundle);
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));

LogClient logClient = app.getClient();

loader.setControllerFactory(clazz -> {
try {
if (app.getClient() != null) {
if (logClient != null) {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class).newInstance(app.getClient(), ologQueryManager, searchParameters);
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class)
.newInstance(logClient, ologQueryManager, searchParameters);
logEntryTableViewController.setGoBackAndGoForwardActions(goBackAndGoForwardActions);
logEntryTableViewController.setDecorations(decorations);
return logEntryTableViewController;
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class, SearchParameters.class).newInstance(app.getClient(), searchParameters);
return clazz.getConstructor(LogClient.class, SearchParameters.class).newInstance(logClient, searchParameters);
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
SingleLogEntryDisplayController singleLogEntryDisplayController = (SingleLogEntryDisplayController) clazz.getConstructor(LogClient.class).newInstance(app.getClient());
SingleLogEntryDisplayController singleLogEntryDisplayController = (SingleLogEntryDisplayController) clazz.getConstructor(LogClient.class).newInstance(logClient);
singleLogEntryDisplayController.setSelectLogEntryInUI(id -> goBackAndGoForwardActions.loadLogEntryWithID(id));
return singleLogEntryDisplayController;
} else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
Expand All @@ -80,7 +83,7 @@ public LogEntryTable(final LogEntryTableApp app) {
} else if (clazz.isAssignableFrom(AttachmentsEditorController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(MergedLogEntryDisplayController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(app.getClient());
return clazz.getConstructor(LogClient.class).newInstance(logClient);
}
} else {
// no logbook client available
Expand Down
Loading