aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-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
-rw-r--r--src/main/resources/application.yaml6
-rw-r--r--src/main/resources/mzs/app2mzs.xsd9
-rw-r--r--src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java4
6 files changed, 61 insertions, 20 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();
+
+ }
}
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index a04a903..2d0bed3 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -30,9 +30,11 @@ delivery-request-configuration-profiles:
# 0 means indefinitely.
receive-timeout: 0
- # Specifies how MoaZS should
+ # Specifies how MoaZS should a synchronous responses from msg.
msg-response-sinks:
- save-response-to-file: false
+ save-response-to-file:
+ active: false
+ path: /msg-responses/
log-response: true
ssl-profile:
diff --git a/src/main/resources/mzs/app2mzs.xsd b/src/main/resources/mzs/app2mzs.xsd
index ba99eab..5733a00 100644
--- a/src/main/resources/mzs/app2mzs.xsd
+++ b/src/main/resources/mzs/app2mzs.xsd
@@ -132,10 +132,17 @@
<xs:element name="MsgResponseSinks" type="MsgResponseSinksType"/>
<xs:complexType name="MsgResponseSinksType">
<xs:sequence>
- <xs:element name="SafeResponseToFile" type="xs:boolean" minOccurs="0" />
+ <xs:element ref="SaveResponseToFile" minOccurs="0" />
<xs:element name="LogResponse" type="xs:boolean" minOccurs="0" />
</xs:sequence>
</xs:complexType>
+ <xs:element name="SaveResponseToFile" type="SaveResponseToFileType" />
+ <xs:complexType name="SaveResponseToFileType">
+ <xs:sequence>
+ <xs:element name="Active" type="xs:boolean" minOccurs="0"/>
+ <xs:element name="Path" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:element name="DeliveryResponse" type="DeliveryResponseType"/>
<xs:complexType name="DeliveryResponseType">
<xs:choice>
diff --git a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
index 58efe6a..1fa3997 100644
--- a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
@@ -44,7 +44,7 @@ public class SaveResponseToFileSinkTest {
@Before
public void setup() {
- sink = new SaveResponseToFileSink(marshaller, repository, root);
+ sink = new SaveResponseToFileSink(marshaller, repository);
deleteRoot();
}
@@ -63,7 +63,7 @@ public class SaveResponseToFileSinkTest {
var fileContent = "<xml>some content</xml>";
var status = setupMocks(fileContent);
- sink.save(status)
+ sink.save(status, root)
.thenRun(() -> assertFilesCreatedAndContentMatches(fileContent));
}