aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/scheme
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/scheme
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/scheme')
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/MoaZSPrefixMapper.java36
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java17
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java44
3 files changed, 68 insertions, 29 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/MoaZSPrefixMapper.java b/src/main/java/at/gv/egiz/moazs/scheme/MoaZSPrefixMapper.java
index faee8a5..d725ce6 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/MoaZSPrefixMapper.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/MoaZSPrefixMapper.java
@@ -12,43 +12,21 @@ public class MoaZSPrefixMapper extends NamespacePrefixMapper {
private final Map<String, String> map = new HashMap<>();
public MoaZSPrefixMapper() {
- map.put(getMsgNamespaceUri(), "msg");
- map.put(getMsgPNamespaceUri(), "msgp");
- map.put(getMzsNamespaceUri(), "mzs");
- map.put(getMzsPNamespaceUri(), "mzsp");
- map.put(getDsigNamespaceUri(), "dsig");
+ map.put(NameSpace.MSG, "msg");
+ map.put(NameSpace.MSGP, "msgp");
+ map.put(NameSpace.MZS, "mzs");
+ map.put(NameSpace.MZSP, "mzsp");
+ map.put(NameSpace.DSIG, "dsig");
}
public MoaZSPrefixMapper(boolean isMzs) {
this();
- map.put((isMzs) ? getMzsPNamespaceUri() : getMsgPNamespaceUri(), "p");
- map.put((isMzs) ? getMzsNamespaceUri() : getMsgNamespaceUri(), "");
+ map.put((isMzs) ? NameSpace.MZSP : NameSpace.MSGP, "p");
+ map.put((isMzs) ? NameSpace.MZS : NameSpace.MSG , "");
}
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return map.getOrDefault(namespaceUri, suggestion);
}
-
- private String getMsgNamespaceUri() {
- return new at.gv.zustellung.msg.xsd.ObjectFactory().createDeliveryRequest(null).getName().getNamespaceURI();
- }
-
- private String getMsgPNamespaceUri() {
- return new at.gv.zustellung.msg.xsd.persondata.ObjectFactory().createPerson(null).getName().getNamespaceURI();
- }
-
- private String getMzsNamespaceUri() {
- return new at.gv.zustellung.app2mzs.xsd.ObjectFactory().createDeliveryRequest(null).getName().getNamespaceURI();
- }
-
- private String getMzsPNamespaceUri() {
- return new at.gv.zustellung.app2mzs.xsd.persondata.ObjectFactory().createAbstractPersonData(null).getName().getNamespaceURI();
- }
-
- private String getDsigNamespaceUri() {
- return new org.w3._2000._09.xmldsig_.ObjectFactory().createCanonicalizationMethod(null).getName().getNamespaceURI();
- }
-
-
}
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java b/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java
new file mode 100644
index 0000000..63276cb
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java
@@ -0,0 +1,17 @@
+package at.gv.egiz.moazs.scheme;
+
+public class NameSpace {
+
+ private NameSpace() {}
+
+ public static final String MSG = new at.gv.zustellung.msg.xsd.ObjectFactory().createDeliveryRequest(null).getName().getNamespaceURI();
+
+ public static final String MSGP = new at.gv.zustellung.msg.xsd.persondata.ObjectFactory().createPerson(null).getName().getNamespaceURI();
+
+ public static final String MZS = new at.gv.zustellung.app2mzs.xsd.ObjectFactory().createDeliveryRequest(null).getName().getNamespaceURI();
+
+ public static final String MZSP = new at.gv.zustellung.app2mzs.xsd.persondata.ObjectFactory().createAbstractPersonData(null).getName().getNamespaceURI();
+
+ public static final String DSIG = new org.w3._2000._09.xmldsig_.ObjectFactory().createCanonicalizationMethod(null).getName().getNamespaceURI();
+
+}
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java b/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java
new file mode 100644
index 0000000..2d4df4b
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java
@@ -0,0 +1,44 @@
+package at.gv.egiz.moazs.scheme;
+
+import at.gv.egiz.moazs.MoaZSException;
+import at.gv.util.DOMUtils;
+import org.apache.cxf.binding.soap.Soap11;
+import org.springframework.stereotype.Component;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+@Component
+public class SOAPUtils {
+
+ public Element toDOM(byte[] bytes) throws IOException, SAXException, ParserConfigurationException {
+ var stream = new ByteArrayInputStream(bytes);
+ return DOMUtils.parseXmlNonValidating(stream);
+ }
+
+ public byte[] unwrapSoapEnvelope(Element document) {
+ try {
+ var body = document.getElementsByTagNameNS(Soap11.SOAP_NAMESPACE, "Body");
+ var item = body.item(0).getFirstChild();
+
+ return DOMUtils.serializeNode(item, true)
+ .getBytes(StandardCharsets.UTF_8);
+
+ } catch (IOException | TransformerException e) {
+ throw new MoaZSException("Error while parsing message. ", e);
+ }
+ }
+
+ public String getAppDeliveryIDFrom(Element document) {
+ var elements = document.getElementsByTagNameNS(NameSpace.MSG, "AppDeliveryID");
+
+ var appDeliveryIdElement = elements.item(0).getFirstChild();
+
+ return appDeliveryIdElement.getNodeValue();
+ }
+}