From 25d68c8900c2cc791f03ea3db173955ca237fd55 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Fri, 12 Jul 2019 15:40:05 +0200 Subject: Allow App To Choose Between MsgResponse Sinks - MZS Schema Change: Add "MsgResponseSinks" element to mzs:DeliveryRequest/Config that allows sender to configure how MsgResponses should be archived. - ConfigUtil: Interpret MsgResponseSink parameters from Spring Environment and merge with ConfigType. - MsgResponseBackend: Send responses to sinks according to MsgResponseSinks in Config - application.yaml: Add MsgResponseSinks parameter to configuration. - Uncouple Sink implementations from java.util.function.Function, because the sink interfaces are going to differ and there is no need to unite them under one interface. - Add and test LogResponseSink, which logs responses to it's logger. - MsgResponse: Add JAXB getter for response. Reason: Can be passed to marshaller. --- .../at/gv/egiz/moazs/preprocess/ConfigUtil.java | 62 ++++++++++++++++++---- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/preprocess') 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 68f833e..9cdc07a 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java @@ -1,10 +1,7 @@ package at.gv.egiz.moazs.preprocess; import at.gv.egiz.moazs.util.StringUtils; -import at.gv.zustellung.app2mzs.xsd.ClientType; -import at.gv.zustellung.app2mzs.xsd.ConfigType; -import at.gv.zustellung.app2mzs.xsd.KeyStoreType; -import at.gv.zustellung.app2mzs.xsd.SSLType; +import at.gv.zustellung.app2mzs.xsd.*; import org.springframework.stereotype.Component; import java.math.BigInteger; @@ -13,6 +10,7 @@ import java.util.Map; import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder; 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 java.util.stream.Collectors.toMap; @@ -33,7 +31,9 @@ public class ConfigUtil { public static final String PASSWORD_KEY = "password"; public static final String RECEIVE_TIMEOUT = "receive-timeout"; public static final String CONNECTION_TIMEOUT_KEY = "connection-timeout"; - + 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"; /** * Convert a map into a Config object. @@ -53,10 +53,15 @@ public class ConfigUtil { ClientType tnvzClient = tnvzClientParams.isEmpty() ? null : buildClient(tnvzClientParams); + var msgResponseSinksParams = filterMapByPrefix(values, MSG_RESPONSE_SINKS_KEY); + MsgResponseSinksType sinks = msgResponseSinksParams.isEmpty() + ? null : buildMsgResponseSinks(msgResponseSinksParams); + return ConfigType.configTypeBuilder() .withPerformQueryPersonRequest(performQueryPersonRequest) .withMSGClient(msgClient) .withTNVZClient(tnvzClient) + .withMsgResponseSinks(sinks) .build(); } @@ -102,11 +107,8 @@ public class ConfigUtil { KeyStoreType trustStore = trustStoreParams.isEmpty() ? null : buildKeyStore(trustStoreParams); - var trustAll = sslParams.get(TRUST_ALL_KEY) == null - ? null : Boolean.getBoolean(sslParams.get(TRUST_ALL_KEY)); - - var laxHostNameVerification = sslParams.get(LAX_HOSTNAME_VERIFICATION_KEY) == null - ? null : Boolean.getBoolean(sslParams.get(LAX_HOSTNAME_VERIFICATION_KEY)); + var trustAll = booleanOrNull(sslParams.get(TRUST_ALL_KEY)); + var laxHostNameVerification = booleanOrNull(sslParams.get(LAX_HOSTNAME_VERIFICATION_KEY)); return SSLTypeBuilder() .withKeyStore(keyStore) @@ -126,6 +128,22 @@ public class ConfigUtil { .build(); } + private MsgResponseSinksType buildMsgResponseSinks(Map params) { + + var logResponse = booleanOrNull(params.get(LOG_RESPONSE_KEY)); + var saveResponse = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_KEY)); + + return msgResponseSinksTypeBuilder() + .withLogResponse(logResponse) + .withLogResponse(saveResponse) + .build(); + } + + private Boolean booleanOrNull(String value) { + return value == null ? null : Boolean.getBoolean(value); + } + + /** * Combine properties of two Configs; {@code primary} overrides {@code fallback}. * @@ -149,6 +167,10 @@ public class ConfigUtil { builder.withMSGClient(merge(primary.getTNVZClient(), fallback.getTNVZClient())); } + if (primary.getMsgResponseSinks() != null) { + builder.withMsgResponseSinks(merge(primary.getMsgResponseSinks(), fallback.getMsgResponseSinks())); + } + return builder.build(); } @@ -214,4 +236,24 @@ public class ConfigUtil { } + private MsgResponseSinksType merge(MsgResponseSinksType primary, MsgResponseSinksType fallback) { + + if (fallback == null) { + return primary; + } + + var builder = msgResponseSinksTypeBuilder(fallback); + + if (primary.isLogResponse() != null) { + builder.withLogResponse(primary.isLogResponse()); + } + + if (primary.isSafeResponseToFile() != null) { + builder.withLogResponse(primary.isSafeResponseToFile()); + } + + return builder.build(); + } + + } -- cgit v1.2.3