Skip to content

Commit 733a86d

Browse files
committed
Fix Olog HttpClient timeout and URL encoding
1 parent 4e257ca commit 733a86d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogHttpClient.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,19 @@ public static Builder builder() {
126126
* Disallow instantiation.
127127
*/
128128
private OlogHttpClient(String userName, String password) {
129-
httpClient = HttpClient.newBuilder()
130-
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
131-
.followRedirects(HttpClient.Redirect.ALWAYS)
132-
// HttpClient rejects Duration.ZERO for the connect timeout value.
133-
// To support infinite timeout (preference value == 0), use Long.MAX_VALUE
134-
.connectTimeout(Duration.ofMillis(Preferences.connectTimeout <= 0 ? Long.MAX_VALUE : Preferences.connectTimeout))
135-
.build();
129+
if(Preferences.connectTimeout > 0){
130+
httpClient = HttpClient.newBuilder()
131+
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
132+
.followRedirects(HttpClient.Redirect.ALWAYS)
133+
.connectTimeout(Duration.ofMillis(Preferences.connectTimeout))
134+
.build();
135+
}
136+
else{
137+
httpClient = HttpClient.newBuilder()
138+
.cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL))
139+
.followRedirects(HttpClient.Redirect.ALWAYS)
140+
.build();
141+
}
136142

137143
if (userName != null && password != null) {
138144
this.basicAuthenticationHeader = "Basic " + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes());
@@ -456,7 +462,8 @@ public Collection<Property> listProperties() {
456462
public InputStream getAttachment(Long logId, String attachmentName) {
457463
try {
458464
HttpRequest request = HttpRequest.newBuilder()
459-
.uri(URI.create(Preferences.olog_url + "/logs/attachments/" + logId + "/" + URLEncoder.encode(attachmentName, StandardCharsets.UTF_8)))
465+
.uri(URI.create(Preferences.olog_url + "/logs/attachments/" + logId + "/" +
466+
URLEncoder.encode(attachmentName, StandardCharsets.UTF_8).replace("+", "%20"))) // + char does not work in path element!
460467
.GET()
461468
.build();
462469
HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTable.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,21 @@ public LogEntryTable(final LogEntryTableApp app) {
5757
loader.setResources(resourceBundle);
5858
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));
5959

60+
LogClient logClient = app.getClient();
61+
6062
loader.setControllerFactory(clazz -> {
6163
try {
62-
if (app.getClient() != null) {
64+
if (logClient != null) {
6365
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
64-
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class).newInstance(app.getClient(), ologQueryManager, searchParameters);
66+
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class)
67+
.newInstance(logClient, ologQueryManager, searchParameters);
6568
logEntryTableViewController.setGoBackAndGoForwardActions(goBackAndGoForwardActions);
6669
logEntryTableViewController.setDecorations(decorations);
6770
return logEntryTableViewController;
6871
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
69-
return clazz.getConstructor(LogClient.class, SearchParameters.class).newInstance(app.getClient(), searchParameters);
72+
return clazz.getConstructor(LogClient.class, SearchParameters.class).newInstance(logClient, searchParameters);
7073
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
71-
SingleLogEntryDisplayController singleLogEntryDisplayController = (SingleLogEntryDisplayController) clazz.getConstructor(LogClient.class).newInstance(app.getClient());
74+
SingleLogEntryDisplayController singleLogEntryDisplayController = (SingleLogEntryDisplayController) clazz.getConstructor(LogClient.class).newInstance(logClient);
7275
singleLogEntryDisplayController.setSelectLogEntryInUI(id -> goBackAndGoForwardActions.loadLogEntryWithID(id));
7376
return singleLogEntryDisplayController;
7477
} else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
@@ -80,7 +83,7 @@ public LogEntryTable(final LogEntryTableApp app) {
8083
} else if (clazz.isAssignableFrom(AttachmentsEditorController.class)) {
8184
return clazz.getConstructor().newInstance();
8285
} else if (clazz.isAssignableFrom(MergedLogEntryDisplayController.class)) {
83-
return clazz.getConstructor(LogClient.class).newInstance(app.getClient());
86+
return clazz.getConstructor(LogClient.class).newInstance(logClient);
8487
}
8588
} else {
8689
// no logbook client available

0 commit comments

Comments
 (0)