Skip to content

Commit 4a2e83f

Browse files
author
Robin Duda
committed
Avoid overwriting context keys on reroute.
1 parent 4115e58 commit 4a2e83f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/main/java/com/codingchili/excelastic/controller/Website.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.FileNotFoundException;
1616
import java.util.Iterator;
1717
import java.util.concurrent.atomic.AtomicReference;
18+
import java.util.function.BiConsumer;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021

@@ -57,14 +58,20 @@ public void start(Future<Void> start) {
5758

5859
// adds values used in the template to all routes.
5960
router.route("/*").handler(context -> {
61+
BiConsumer<String, String> applyIfUnset = (key, value) -> {
62+
if (context.get(key) == null) {
63+
context.put(key, value);
64+
}
65+
};
6066
context.put("version", VERSION);
6167
context.put("esVersion", getElasticVersion());
6268
context.put("esURL", Configuration.getElasticURL());
6369
context.put("connected", ElasticWriter.isConnected());
6470
context.put("tls", Configuration.isElasticTLS());
65-
context.put("index", Configuration.getDefaultIndex());
6671
context.put("indexLocked", Configuration.isIndexLocked());
6772
context.put("supportedFiles", String.join(", ", ParserFactory.getSupportedExtensions()));
73+
applyIfUnset.accept("index", Configuration.getDefaultIndex());
74+
6875
context.next();
6976
});
7077

@@ -155,7 +162,6 @@ private Future<Integer> onComplete(RoutingContext context, String fileName) {
155162
return Future.<Integer>future().setHandler(result -> {
156163
if (result.succeeded()) {
157164
String index = getIndexFromRequest(context.request());
158-
159165
logger.info(String.format("Imported file '%s' successfully into '%s'.", fileName, index));
160166

161167
context.put(INDEX, index);

src/main/resources/templates/done.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ html(lang='en')
77
.jumbotron
88
h1 Success!
99
p
10-
| Imported #{context.imported} rows from '#{context.file}' into #{context.index} successfully.
10+
| Imported #{context.imported} rows from '#{context.file}' into '#{context.index}' successfully.
1111
button.btn.btn-success.btn-block#start-page ANOTHER FILE
1212
include scripts

0 commit comments

Comments
 (0)