diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-17 13:17:21 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-17 13:27:40 +0200 |
commit | f2e1263702901581512131ea587fad7a2ba45baa (patch) | |
tree | b92a38f758fecb039de184963116017921d2e314 /src/main/java/at/gv/egiz/moazs/client | |
parent | 896195cc9b287a3f41008cc85997b9c2209120b8 (diff) | |
download | moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.gz moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.bz2 moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.zip |
Put MoaZSException on Diet & Handle Edge Cases
Reason: MoaZSException (and: its builder) were used to collect
intermediary results while stepping through the delivery request
backend. These results were needed to generate meaningful responses
towards the sender application in case of error. However, the builder
sprawled over too many interfaces (e.g. DeliveryRequestBackend and
TNVZHelper) and it became difficult to understand from where
intermediary results originated.
Solution: Put MoaZSException on diet:
- Remove all DeliveryAnswer fields from MoaZSException and refactor
code base to ensure that the removed fields get sourced by other
means.
- Remove Builder since amount of parameters is manageable.
Refactor DeliveryRequestBackend:
- Instead of passing down the builder and using MoaZSException as the
only source for intermediary results, we collect available results
at the outermost stack frame (DeliveryRequestBackend.accept) and
only retrieve results via exception if those results appear
somewhere down the stack frame (E.g. PredviceNoteSent). We collect
available results with the "fallbackAnswerBuilder" and switch to the
msg client response, once received.
Refactor MsgResponseBackend:
- Handle cases (response missing, binary response missing) properly.
- Integrate changes from MsgResponse.generateError()
Refactor TVNZHelper:
- Remove MoaZSExceptionBuilder from all interfaces.
Refactor MsgResponse.generateError:
- Change interface such that it's more intuitive.
- Implement NotificationResponse.generateError.
- Implement RequestStatusResponse.generateError.
Others:
- Replace all invocations against MoaZSException.Builder.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/client')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java | 5 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java | 35 |
2 files changed, 17 insertions, 23 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java b/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java index 8fb5d80..47a2f1c 100644 --- a/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java +++ b/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java @@ -6,13 +6,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import javax.net.ssl.X509TrustManager; import javax.net.ssl.*; import java.io.IOException; import java.security.*; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static java.lang.String.format; diff --git a/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java b/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java index 884be3e..de22805 100644 --- a/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java +++ b/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java @@ -19,6 +19,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static at.gv.zustellung.tnvz.xsd.PersonQueryType.MetaData.metaDataBuilder; import static at.gv.zustellung.tnvz.xsd.PersonQueryType.personQueryTypeBuilder; import static at.gv.zustellung.tnvz.xsd.QueryPersonRequest.QueryEntryList.queryEntryListBuilder; @@ -52,21 +53,19 @@ public class TnvzHelper { * {@code tvnzPort}, validates the tnvz's response and extracts the {@code Identification} Element. * @param mzsRequest Data source for the QueryPersonRequest * @param tvnzPort Client for communicating with the tnvz service - * @param exceptionBuilder Utility to collect information and build a meaningful exception in case of errors. * @throws MoaZSException in case of an error. * @return */ public IdentificationType performQueryPersonRequest(DeliveryRequestType mzsRequest, - TNVZServicePort tvnzPort, - MoaZSException.Builder exceptionBuilder) { + TNVZServicePort tvnzPort) { var tvnzQuery = buildQuery(mzsRequest); var tvnzResponse = tvnzPort.queryPerson(tvnzQuery); - verifyResponse(tvnzResponse, exceptionBuilder); + verifyResponse(tvnzResponse); var tvnzResult = getResult(tvnzResponse); var typesInRequest = extractListOfMimemtypesIn(mzsRequest); - checkMimetypes(tvnzResult, typesInRequest, exceptionBuilder); + checkMimetypes(tvnzResult, typesInRequest); return tvnzResult.getSuccess().getIdentification(); } @@ -170,30 +169,26 @@ public class TnvzHelper { .collect(toSet()); } - private void verifyResponse(QueryPersonResponse tvnzResponse, MoaZSException.Builder mzsBuilder) { + private void verifyResponse(QueryPersonResponse tvnzResponse) { var error = tvnzResponse.getError(); if (error != null) { - throw mzsBuilder.withErrorCode(error.getCode()) - .withMessage(error.getText()) - .build(); + throw MoaZSException.moaZSException(error.getText(), error.getCode()); } var results = tvnzResponse.getQueryResultList().getQueryResult(); if (results.isEmpty()) { - throw mzsBuilder.withErrorCode(MoaZSException.ERROR_MZS_NO_TNVZ_PERSON_QUERY_RESULTS) - .withMessage(MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG) - .build(); + throw MoaZSException.moaZSException(MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG, + MoaZSException.ERROR_MZS_NO_TNVZ_PERSON_QUERY_RESULTS); } var tnvzResult = results.get(0); - mzsBuilder.withPreAdviceNoteSent(tnvzResult); if (tnvzResult.getError() != null) { var info = tnvzResult.getError().getErrorInfo(); - throw mzsBuilder.withErrorCode(info.getCode()) - .withMessage(RECEIVER_NOT_ADRESSABLE_ERROR_MSG, info.getText()) - .build(); + var message = String.format(RECEIVER_NOT_ADRESSABLE_ERROR_MSG, info.getText()); + var code = info.getCode(); + throw moaZSException(message, code, tnvzResult.getError().getPreAdviceNoteSent()); } } @@ -201,14 +196,14 @@ public class TnvzHelper { return tvnzResponse.getQueryResultList().getQueryResult().get(0); } - private void checkMimetypes(PersonResultType tnvzResult, Set<String> typesInRequest, MoaZSException.Builder mzsBuilder) { + private void checkMimetypes(PersonResultType tnvzResult, Set<String> typesInRequest) { var mismatchedTypes = findMimeTypeMismatches(tnvzResult, typesInRequest); if (!mismatchedTypes.isEmpty()) { var acceptedTypesString = join(",", getAcceptedTypes(tnvzResult)); var mismatchedTypesString = join(",", mismatchedTypes); - throw mzsBuilder.withErrorCode(MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH) - .withMessage(MIMETYPE_MISSMATCH_ERROR_MSG, mismatchedTypesString, acceptedTypesString) - .build(); + var message = String.format(MIMETYPE_MISSMATCH_ERROR_MSG, mismatchedTypesString, acceptedTypesString); + var code = MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH; + throw MoaZSException.moaZSException(message, code); } } |