aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv
diff options
context:
space:
mode:
authorFlorian Reimair <florian.reimair@iaik.tugraz.at>2014-02-26 13:54:44 +0100
committerFlorian Reimair <florian.reimair@iaik.tugraz.at>2014-02-26 15:07:58 +0100
commit5dd5959e9ddd730452d0007fbf2c091d2c2506e1 (patch)
tree802b7c58325a551d6ee3074f880cc44780c0fde4 /id/server/idserverlib/src/main/java/at/gv
parent001161aec7e42825c21fc969cac45f77da31fb86 (diff)
downloadmoa-id-spss-5dd5959e9ddd730452d0007fbf2c091d2c2506e1.tar.gz
moa-id-spss-5dd5959e9ddd730452d0007fbf2c091d2c2506e1.tar.bz2
moa-id-spss-5dd5959e9ddd730452d0007fbf2c091d2c2506e1.zip
parse the SOAP response
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java143
1 files changed, 117 insertions, 26 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java
index 42652464b..fdf0806b8 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java
@@ -1,10 +1,13 @@
package at.gv.egovernment.moa.id.protocols.stork2;
+import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
@@ -14,6 +17,12 @@ import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -58,13 +67,13 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider {
SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection();
// assemble SOAP request
- MessageFactory messageFactory = MessageFactory.newInstance();
- SOAPMessage requestMessage = messageFactory.createMessage();
- SOAPPart requestPart = requestMessage.getSOAPPart();
-
- // (soap 1.1 relevant part. could not find a solution to use soap 1.2 in time.
- requestMessage.getMimeHeaders().setHeader("SOAPAction", "http://gesundheit.gv.at/BAGDAD/DataAccessService/IsHealthcareProfessional");
-
+ MessageFactory messageFactory = MessageFactory.newInstance();
+ SOAPMessage requestMessage = messageFactory.createMessage();
+ SOAPPart requestPart = requestMessage.getSOAPPart();
+
+ // (soap 1.1 relevant part. could not find a solution to use soap 1.2 in time.
+ requestMessage.getMimeHeaders().setHeader("SOAPAction", "http://gesundheit.gv.at/BAGDAD/DataAccessService/IsHealthcareProfessional");
+
/*
Construct SOAP Request Message:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
@@ -74,34 +83,116 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider {
</IsHealthcareProfessional>
</soap:Body>
</soap:Envelope>
-
+
see https://stork.ehealth.gv.at/GDAService.asmx?op=IsHealthcareProfessional
*/
- // SOAP Envelope
- SOAPEnvelope envelope = requestPart.getEnvelope();
+ // SOAP Envelope
+ SOAPEnvelope envelope = requestPart.getEnvelope();
+
+ // SOAP Body
+ SOAPBody requestBody = envelope.getBody();
+ SOAPElement requestBodyElem = requestBody.addChildElement("IsHealthcareProfessional");
+ SOAPElement requestBodyElem1 = requestBodyElem.addChildElement("bPK");
+ // TODO fetch bpk_gh from somewhere
+ requestBodyElem1.addTextNode("bpk_gh");
- // SOAP Body
- SOAPBody requestBody = envelope.getBody();
- SOAPElement requestBodyElem = requestBody.addChildElement("IsHealthcareProfessional");
- SOAPElement requestBodyElem1 = requestBodyElem.addChildElement("bPK");
- // TODO fetch bpk_gh from somewhere
- requestBodyElem1.addTextNode("bpk_gh");
+ requestMessage.saveChanges();
- requestMessage.saveChanges();
-
// perform SOAP call
- SOAPMessage responseMessage = soapConnection.call(requestMessage, destination);
-
+ SOAPMessage responseMessage = soapConnection.call(requestMessage, destination);
+
// parse SOAP response
-
- // assemble attribute
- PersonalAttribute acquiredAttribute = new PersonalAttribute();
-
+
+ /*
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <IsHealthcareProfessionalResponse xmlns="http://gesundheit.gv.at/BAGDAD/DataAccessService">
+ <IsHealthcareProfessionalResult>
+ <RequestOK>boolean</RequestOK>
+ <Message>string</Message>
+ <IsHealthcareProfessional>boolean</IsHealthcareProfessional>
+ <NameOfOrganisation>string</NameOfOrganisation>
+ <Type>string</Type>
+ <Specialization>string</Specialization>
+ </IsHealthcareProfessionalResult>
+ </IsHealthcareProfessionalResponse>
+ </soap:Body>
+ </soap:Envelope>
+
+ see https://stork.ehealth.gv.at/GDAService.asmx?op=IsHealthcareProfessional
+ */
+ SOAPBody responseBody = responseMessage.getSOAPBody();
+
+ // iterate through tree
+ SOAPElement responseElement = (SOAPElement) responseBody.getChildElements().next();
+ SOAPElement resultElement = (SOAPElement) responseElement.getChildElements().next();
+ SOAPElement tmp;
+
+ // collect all info in a map
+ Iterator it = resultElement.getChildElements();
+ Map<String, String> collection = new HashMap<String, String>();
+ while (it.hasNext()) {
+ SOAPElement current = (SOAPElement) it.next();
+
+ collection.put(current.getNodeName(), current.getTextContent());
+
+ }
+
+ // check if there is anything valid in the map
+ if (collection.isEmpty() || collection.size() != 6) {
+ // TODO report error
+ }
+
+ // - fetch request validity
+ if (collection.get("RequestOK").equals("false")) {
+ // TODO report error
+ }
+
+ PersonalAttribute acquiredAttribute = null;
+
+ if (collection.get("IsHealthcareProfessional").equals("false")) {
+ // the citizen is no HCP
+ acquiredAttribute = new PersonalAttribute("isHCP", false, new ArrayList<String>(), "NotAvailable");
+ } else {
+ // go on and parse the data
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+
+ Element orgname = doc.createElement("nameOfOrganisation");
+ orgname.appendChild(doc.createTextNode(collection.get("NameOfOrganization")));
+ doc.appendChild(orgname);
+
+ Element type = doc.createElement("HCP");
+ // TODO fix value mapping
+ if (collection.get("Type").equals("Medical Doctors"))
+ type.appendChild(doc.createTextNode("D"));
+ doc.appendChild(type);
+
+ Element specialization = doc.createElement("specialisation");
+ // TODO fix value mapping
+ specialization.appendChild(doc.createTextNode(collection.get("Specialization").substring(0, 2)));
+ doc.appendChild(specialization);
+
+ // get string from dom tree
+ Source source = new DOMSource(doc);
+ StringWriter out = new StringWriter();
+ Result result = new StreamResult(out);
+
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer();
+ transformer.transform(source, result);
+
+ ArrayList<String> value = new ArrayList<String>();
+ value.add(out.toString());
+
+ acquiredAttribute = new PersonalAttribute("isHCP", false, value, "Available");
+ }
+
// pack and return the result
PersonalAttributeList result = new PersonalAttributeList();
result.add(acquiredAttribute);
-
+
return result;
} catch (Exception e) {
// TODO in case of an error, we might want to inform someone somehow different than by just saying nothing