diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-08 18:02:37 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-08 18:02:37 +0200 |
commit | c1a1a5130a4ecf755da72941ad3525beb919447f (patch) | |
tree | ecaca5da80571e10f25186402ee73d8e062d4544 /src/main/java/at/gv/egiz/moazs/util | |
parent | 78f0715d86a055aed11138df5f66b0794e72326a (diff) | |
download | moa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.tar.gz moa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.tar.bz2 moa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.zip |
Implement Zuse2App Services
- Add zuse2app.wsdl contract.
- Add MsgResponse as an type-agnostic view for DeliveryRequestStatus
and DeliveryNotification messages. Reason: Both DeliveryNotification
and DeliveryRequestStatus messages have similar fields and need to
be treated similarly (e.g.: receive from msg service, store to
repository, verify signature, store to file...). In order to prevent
duplicated code, the wrapper interface provides a type-agnostic view
onto these messages for depending components to operate on.
- Add MsgResponseHandler interface; decides how to process
MsgResponse. Also implement this handler with a multi-threaded
single-node implementation.
- Add MsgResponseSink interface; decides how to archive MsgResponse.
- Implement and test SafeResponseToFileSink.
Change Identifier for MsgResponses:
- Before, DeliveryRequestStatus and DeliveryNotifications had their
own repositories. Now, both types are stored in the same repository
(the MsgResponse repository) to streamline the handling of
MsgResponses. We need to change the identification of MsgReponses,
otherwise the identifiers (AppDeliveryID) clash.
- MsgResponses are not identified by:
<AppDeliveryId>+<typeSpecificSuffix>
- Rewrite StoreSOAPInterceptor to accommodate fact that, both
DeliveryRequestStatus and DeliveryNotification messages have
different IDs upon storage / retrieval.
Restructure packages and components as follows:
- client: All components that are involved when consuming a web service.
- process: "fabric" of MoaZS; contains business logic that
orchestrates back-end tasks of MoaZS's operational services, e.g.:
by processing a delivery request.
- service: Implementation of MoaZS's front-end services.
Refactoring:
- MoaZSException: Remove unused fields. Before: Store mzsrequest,
tnvzresult, msgrequest and msgresult as members. Now: Only keep the
fields that are needed later, e.g for generating a
msg:DeliveryRequestStatus element. Add copy constructor to Builder.
- Put storage of byte[] into a dedicated "BinaryRepository". Reason:
This was useful in a former design. Now it's not really needed
anymore.
- Put "create Endpoint" code into EndpointFactory. Reason: Eliminate
duplicated code when configuring a service.
Testing:
- Activate Stacktraces in surefire.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/util')
4 files changed, 71 insertions, 14 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java b/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java index e7761fe..d0a445b 100644 --- a/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java +++ b/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java @@ -1,5 +1,7 @@ -package at.gv.egiz.moazs.util; +package at.gv.egiz.moazs.client; +import at.gv.egiz.moazs.util.FileUtils; +import at.gv.egiz.moazs.util.StoreSOAPBodyBinaryInRepositoryInterceptor; import at.gv.zustellung.app2mzs.xsd.ClientType; import at.gv.zustellung.app2mzs.xsd.KeyStoreType; import at.gv.zustellung.app2mzs.xsd.SSLType; diff --git a/src/main/java/at/gv/egiz/moazs/util/EndpointFactory.java b/src/main/java/at/gv/egiz/moazs/util/EndpointFactory.java new file mode 100644 index 0000000..24321e1 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/util/EndpointFactory.java @@ -0,0 +1,41 @@ +package at.gv.egiz.moazs.util; + +import org.apache.cxf.Bus; +import org.apache.cxf.interceptor.Interceptor; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.message.Message; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import javax.xml.ws.Endpoint; + +import javax.xml.ws.Service; + +@Component +public class EndpointFactory { + + private final Bus bus; + + @Autowired + public EndpointFactory(Bus bus) { + this.bus = bus; + } + + public Endpoint create(Object implementor, Service service) { + return create(implementor, service, null); + } + + public Endpoint create(Object implementor, Service service, Interceptor<Message> interceptor) { + EndpointImpl endpoint = new EndpointImpl(bus, implementor); + endpoint.setAddress("/"); + endpoint.setServiceName(service.getServiceName()); + endpoint.setWsdlLocation(service.getWSDLDocumentLocation().toString()); + endpoint.publish(); + + if (interceptor != null) { + endpoint.getInInterceptors().add(interceptor); + } + + return endpoint; + } + +} diff --git a/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java b/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java index 302bbf0..8fb5d80 100644 --- a/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java +++ b/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java @@ -1,4 +1,4 @@ -package at.gv.egiz.moazs.util; +package at.gv.egiz.moazs.client; import at.gv.egiz.eaaf.core.impl.utils.KeyStoreUtils; import at.gv.zustellung.app2mzs.xsd.KeyStoreType; diff --git a/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java b/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java index 2db81ab..d70c8bd 100644 --- a/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java +++ b/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java @@ -1,6 +1,6 @@ package at.gv.egiz.moazs.util; -import at.gv.egiz.moazs.repository.DeliveryRepository; +import at.gv.egiz.moazs.repository.BinaryRepository; import at.gv.egiz.moazs.scheme.SOAPUtils; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; @@ -15,6 +15,7 @@ import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Map; import static at.gv.egiz.moazs.MoaZSException.moaZSException; @@ -25,14 +26,16 @@ public class StoreSOAPBodyBinaryInRepositoryInterceptor extends AbstractPhaseInt private final CXFMessageUtils messageUtils; private final SOAPUtils soapUtils; - private final DeliveryRepository repository; + private final Map<String, String> idSuffixes; + private final BinaryRepository repository; @Autowired public StoreSOAPBodyBinaryInRepositoryInterceptor(CXFMessageUtils extractor, SOAPUtils soapUtils, - DeliveryRepository repository) { + Map<String, String> idSuffixes, BinaryRepository repository) { super(Phase.RECEIVE); this.messageUtils = extractor; this.soapUtils = soapUtils; + this.idSuffixes = idSuffixes; this.repository = repository; } @@ -45,17 +48,28 @@ public class StoreSOAPBodyBinaryInRepositoryInterceptor extends AbstractPhaseInt log.trace("Interceptor received this SOAP message: {}. ", new String(content, StandardCharsets.UTF_8)); } - if(content.length > 0) { - Element document = soapUtils.toDOM(content); - byte[] status = soapUtils.unwrapSoapEnvelope(document); - String appDeliveryID = soapUtils.getAppDeliveryIDFrom(document); - repository.addSignedDeliveryRequestStatus(status, appDeliveryID); + if (content.length <= 0) { + return; + } + + Element document = soapUtils.toDOM(content); + byte[] response = soapUtils.unwrapSoapEnvelope(document); + String appDeliveryID = soapUtils.getAppDeliveryIDFrom(document); + String rootTag = document.getTagName(); - if(log.isTraceEnabled()) { - log.trace("DeliveryRequestStatus with AppDeliveryID={} unwrapped and stored: {}. ", - appDeliveryID, new String(status, StandardCharsets.UTF_8)); - } + if (!idSuffixes.containsKey(rootTag)) { + log.trace("Will not add message of type {}. ", rootTag); + return; } + + var id = appDeliveryID + idSuffixes.get(rootTag); + repository.add(id, response); + + if(log.isTraceEnabled()) { + log.trace("Msg Response with AppDeliveryID={} unwrapped and stored: {}. ", + appDeliveryID, new String(response, StandardCharsets.UTF_8)); + } + } catch (ParserConfigurationException | SAXException | IOException | NullPointerException e) { throw moaZSException("Could not extract signed data from message.", e); } |