diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-12 15:40:05 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-12 15:40:05 +0200 |
commit | 25d68c8900c2cc791f03ea3db173955ca237fd55 (patch) | |
tree | f4d28b97845d10a709590dce480195b322ba019b /src/main/java/at/gv/egiz/moazs/preprocess | |
parent | 9dc0e72571a895e34a55c11d015c5d359b485aff (diff) | |
download | moa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.tar.gz moa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.tar.bz2 moa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.zip |
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.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java | 62 |
1 files changed, 52 insertions, 10 deletions
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<String, String> 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(); + } + + } |