aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-15 12:04:26 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-15 12:09:28 +0200
commitd9e5864f48d261c06de1f1d34000ff6156155569 (patch)
treed66524e395f403d57f27d25cfdcab5dcd25511e4 /src/main/java
parent25d68c8900c2cc791f03ea3db173955ca237fd55 (diff)
downloadmoa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.tar.gz
moa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.tar.bz2
moa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.zip
Save Response To File Sink: Add Path to Configuration + Fix
- Fix in ConfigUtil: SaveResponseToFile boolean would override LogResponse configuration (Copy Paste Error).
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java4
-rw-r--r--src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java14
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java44
3 files changed, 47 insertions, 15 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
index 1b17f34..59db396 100644
--- a/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
+++ b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
@@ -84,8 +84,8 @@ public class MsgResponseBackend implements Consumer<String> {
var sinkParams = getSinkParams(msgResponse);
- if (sinkParams.isSafeResponseToFile()) {
- supplyAsync(() -> saveResponseToFileSink.save(msgResponse));
+ if (sinkParams.getSafeResponseToFile().isActive()) {
+ supplyAsync(() -> saveResponseToFileSink.save(msgResponse, sinkParams.getSafeResponseToFile().getPath()));
}
if (sinkParams.isLogResponse()) {
diff --git a/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java b/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java
index 7da76ef..2468ca9 100644
--- a/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java
+++ b/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java
@@ -31,13 +31,11 @@ public class SaveResponseToFileSink {
private final SimpleDateFormat isoFormatter;
private final Marshaller msgMarshaller;
private final DeliveryRepository repository;
- private final String root;
@Autowired
- public SaveResponseToFileSink(Marshaller msgMarshaller, DeliveryRepository repository, String root) {
+ public SaveResponseToFileSink(Marshaller msgMarshaller, DeliveryRepository repository) {
this.msgMarshaller = msgMarshaller;
this.repository = repository;
- this.root = root;
this.isoFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
}
@@ -47,17 +45,17 @@ public class SaveResponseToFileSink {
* @param response
* @return Future that completes when both responses have been written to the file system.
*/
- public CompletableFuture<Void> save(MsgResponse response) {
+ public CompletableFuture<Void> save(MsgResponse response, String rootPath) {
var responseID = response.getResponseID();
- var responsePath = generatePath(responseID, "xml");
+ var responsePath = generatePath(rootPath, responseID, "xml");
var storeResponseToFileSystemFuture = supplyAsync(() -> msgMarshaller.marshallXml(response.getResponse()))
.thenApply(responseString -> responseString.getBytes(StandardCharsets.UTF_8))
.thenAccept(responseByteArray -> storeToFile(responsePath, responseByteArray))
.exceptionally(ex -> logException(ex, responseID));
- var binaryResponsePath = generatePath(responseID, "binary.xml");
+ var binaryResponsePath = generatePath(rootPath, responseID, "binary.xml");
var storeBinaryResponseToFileSystemFuture = supplyAsync(() -> repository.retrieveBinaryResponse(responseID).get())
.thenAccept(binaryResponseByteArray -> storeToFile(binaryResponsePath, binaryResponseByteArray))
.exceptionally(ex -> logException(ex, responseID));
@@ -66,10 +64,10 @@ public class SaveResponseToFileSink {
}
- private String generatePath(String id, String suffix) {
+ private String generatePath(String rootPath, String id, String suffix) {
var folder = sanitizeFileString(id);
var nowInIso8601 = isoFormatter.format(new Date());
- return format("%s/%s/%s.%s", root, folder, nowInIso8601, suffix);
+ return format("%s/%s/%s.%s", rootPath, folder, nowInIso8601, suffix);
}
private String sanitizeFileString(String fileString) {
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
index 9cdc07a..b69b828 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
@@ -12,6 +12,7 @@ import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.KeyStoreType.keyStoreTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.MsgResponseSinksType.msgResponseSinksTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.SSLType.SSLTypeBuilder;
+import static at.gv.zustellung.app2mzs.xsd.SaveResponseToFileType.saveResponseToFileTypeBuilder;
import static java.util.stream.Collectors.toMap;
@Component
@@ -34,11 +35,14 @@ public class ConfigUtil {
public static final String MSG_RESPONSE_SINKS_KEY = "msg-response-sinks";
public static final String LOG_RESPONSE_KEY = "log-response";
public static final String SAVE_RESPONSE_TO_FILE_KEY = "save-response-to-file";
+ public static final String SAVE_RESPONSE_TO_FILE_ACTIVE_KEY = "active";
+ public static final String SAVE_RESPONSE_TO_FILE_PATH_KEY = "path";
+
/**
* Convert a map into a Config object.
*
- * @param map with well-defined indexes and values
+ * @param values: Map with well-defined indexes and values
* @return Config
*/
public ConfigType convert(Map<String, String> values) {
@@ -131,11 +135,24 @@ public class ConfigUtil {
private MsgResponseSinksType buildMsgResponseSinks(Map<String, String> params) {
var logResponse = booleanOrNull(params.get(LOG_RESPONSE_KEY));
- var saveResponse = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_KEY));
+
+ var saveResponseParams = filterMapByPrefix(params, SAVE_RESPONSE_TO_FILE_KEY);
+ var saveResponse = buildSaveResponse(saveResponseParams);
return msgResponseSinksTypeBuilder()
.withLogResponse(logResponse)
- .withLogResponse(saveResponse)
+ .withSaveResponseToFile(saveResponse)
+ .build();
+ }
+
+ private SaveResponseToFileType buildSaveResponse(Map<String, String> params) {
+
+ var isActive = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_ACTIVE_KEY));
+ var path = params.get(SAVE_RESPONSE_TO_FILE_PATH_KEY);
+
+ return saveResponseToFileTypeBuilder()
+ .withActive(isActive)
+ .withPath(path)
.build();
}
@@ -248,12 +265,29 @@ public class ConfigUtil {
builder.withLogResponse(primary.isLogResponse());
}
- if (primary.isSafeResponseToFile() != null) {
- builder.withLogResponse(primary.isSafeResponseToFile());
+ if (primary.getSaveResponseToFile() != null) {
+ builder.withSaveResponseToFile(merge(primary.getSaveResponseToFile(), fallback.getSaveResponseToFile()));
}
return builder.build();
}
+ private SaveResponseToFileType merge(SaveResponseToFileType primary, SaveResponseToFileType fallback) {
+
+ if (fallback == null) return primary;
+
+ var builder = saveResponseToFileTypeBuilder(fallback);
+
+ if (primary.isActive() != null) {
+ builder.withActive(primary.isActive());
+ }
+
+ if (primary.getPath() != null) {
+ builder.withPath(primary.getPath());
+ }
+
+ return builder.build();
+
+ }
}