aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-27 09:46:36 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-27 10:28:56 +0200
commit695ab1f836160d40c4352a2c3127f4f687912817 (patch)
treecd23bf0e2f6430bd2f5caf40825705e3fe644f98 /src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java
parent0a316ada10bb88720dd15958168409fcb9fcf800 (diff)
downloadmoa-zs-695ab1f836160d40c4352a2c3127f4f687912817.tar.gz
moa-zs-695ab1f836160d40c4352a2c3127f4f687912817.tar.bz2
moa-zs-695ab1f836160d40c4352a2c3127f4f687912817.zip
Intercept Incoming DeliveryRequestStatus and Store as byte[]
- Add egovutils dependency (Reason: Need DomUtils to serialize / unserialize Soap Message via DOMParser) - Add Incerceptor to MsgClient / -Factory that stores the message content byte-by-byte in the DeliveryRepository. The format is required for successfully validating a DeliveryRequestStatus. - Add SoapUtils, which interacts with byte[] Soap message. - Add CXFMessageUtils, which interacts with CXF Messages from interceptor chains. - Refactor xsd namespaces: Move them out from the PrefixMapper and into a dedicated class.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java b/src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java
new file mode 100644
index 0000000..4e023ac
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/msg/StoreSOAPBodyBinaryInRepositoryInterceptor.java
@@ -0,0 +1,55 @@
+package at.gv.egiz.moazs.msg;
+
+import at.gv.egiz.moazs.MoaZSException;
+import at.gv.egiz.moazs.repository.DeliveryRepository;
+import at.gv.egiz.moazs.scheme.SOAPUtils;
+import at.gv.egiz.moazs.util.CXFMessageUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+
+@Component
+public class StoreSOAPBodyBinaryInRepositoryInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ private static final Logger log = LoggerFactory.getLogger(StoreSOAPBodyBinaryInRepositoryInterceptor.class);
+
+ private final CXFMessageUtils messageUtils;
+ private final SOAPUtils soapUtils;
+ private final DeliveryRepository repository;
+
+ @Autowired
+ public StoreSOAPBodyBinaryInRepositoryInterceptor(CXFMessageUtils extractor, SOAPUtils soapUtils,
+ DeliveryRepository repository) {
+ super(Phase.RECEIVE);
+ this.messageUtils = extractor;
+ this.soapUtils = soapUtils;
+ this.repository = repository;
+ }
+
+ public void handleMessage(Message message) {
+
+ try {
+ byte[] content = messageUtils.copyContent(message);
+
+ if(content.length > 0) {
+ Element document = soapUtils.toDOM(content);
+ byte[] status = soapUtils.unwrapSoapEnvelope(document);
+ String appDeliveryId = soapUtils.getAppDeliveryIDFrom(document);
+ repository.addSignedDeliveryRequestStatus(status, appDeliveryId);
+ log.info("Store binary DeliveryRequestStatus with AppDeliveryId={}", appDeliveryId);
+ }
+ } catch (ParserConfigurationException | SAXException | IOException | NullPointerException e) {
+ throw new MoaZSException("Could not extract signed data from message.", e);
+ }
+ }
+
+}