From defceef8afef538555c13d33e344a89a828a3d97 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 20 Dec 2013 12:35:28 +0100 Subject: inital --- .../at/gv/util/client/mis/simple/MISMandate.java | 23 ++ .../at/gv/util/client/mis/simple/MISSessionId.java | 23 ++ .../gv/util/client/mis/simple/MISSimpleClient.java | 233 +++++++++++++++++++++ .../mis/simple/MISSimpleClientException.java | 22 ++ 4 files changed, 301 insertions(+) create mode 100644 src/main/java/at/gv/util/client/mis/simple/MISMandate.java create mode 100644 src/main/java/at/gv/util/client/mis/simple/MISSessionId.java create mode 100644 src/main/java/at/gv/util/client/mis/simple/MISSimpleClient.java create mode 100644 src/main/java/at/gv/util/client/mis/simple/MISSimpleClientException.java (limited to 'src/main/java/at/gv/util/client/mis/simple') diff --git a/src/main/java/at/gv/util/client/mis/simple/MISMandate.java b/src/main/java/at/gv/util/client/mis/simple/MISMandate.java new file mode 100644 index 0000000..fe4159a --- /dev/null +++ b/src/main/java/at/gv/util/client/mis/simple/MISMandate.java @@ -0,0 +1,23 @@ +package at.gv.util.client.mis.simple; + +public class MISMandate { + + private boolean isProfRep = false; + private byte[] mandate = null; + + public boolean isProfRep() { + return isProfRep; + } + public void setProfRep(boolean isProfRep) { + this.isProfRep = isProfRep; + } + public byte[] getMandate() { + return mandate; + } + public void setMandate(byte[] mandate) { + this.mandate = mandate; + } + + + +} diff --git a/src/main/java/at/gv/util/client/mis/simple/MISSessionId.java b/src/main/java/at/gv/util/client/mis/simple/MISSessionId.java new file mode 100644 index 0000000..c9adc66 --- /dev/null +++ b/src/main/java/at/gv/util/client/mis/simple/MISSessionId.java @@ -0,0 +1,23 @@ +package at.gv.util.client.mis.simple; + +public class MISSessionId { + + private String sessiondId = null; + private String redirectURL = null; + + public String getSessiondId() { + return sessiondId; + } + public void setSessiondId(String sessiondId) { + this.sessiondId = sessiondId; + } + public String getRedirectURL() { + return redirectURL; + } + public void setRedirectURL(String redirectURL) { + this.redirectURL = redirectURL; + } + + + +} diff --git a/src/main/java/at/gv/util/client/mis/simple/MISSimpleClient.java b/src/main/java/at/gv/util/client/mis/simple/MISSimpleClient.java new file mode 100644 index 0000000..34ba951 --- /dev/null +++ b/src/main/java/at/gv/util/client/mis/simple/MISSimpleClient.java @@ -0,0 +1,233 @@ +package at.gv.util.client.mis.simple; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.xpath.XPathAPI; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import at.gv.util.DOMUtils; + +public class MISSimpleClient { + + private final static String SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/"; + private final static String MIS_NS = "http://reference.e-government.gv.at/namespace/mandates/mis/1.0/xsd"; + + private static Element NS_NODE = null; + + private static Logger log = LoggerFactory.getLogger(MISSimpleClient.class); + + static { + try { + NS_NODE = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument().createElement("test"); + NS_NODE.setAttribute("xmlns:soap", SOAP_NS); + NS_NODE.setAttribute("xmlns:mis", MIS_NS); + } catch (Exception e) { + log.warn("Error initializing namespace node.", e); + } + } + + public static List sendGetMandatesRequest(String webServiceURL, String sessionId) throws MISSimpleClientException { + if (webServiceURL == null) { + throw new NullPointerException("Argument webServiceURL must not be null."); + } + if (sessionId == null) { + throw new NullPointerException("Argument sessionId must not be null."); + } + try { + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Element mirElement = doc.createElementNS(MIS_NS, "MandateIssueRequest"); + Element sessionIdElement = doc.createElementNS(MIS_NS, "SessionID"); + sessionIdElement.appendChild(doc.createTextNode(sessionId)); + mirElement.appendChild(sessionIdElement); + // send soap request + Element mandateIssueResponseElement = sendSOAPRequest(webServiceURL, mirElement); + + // check for error + checkForError(mandateIssueResponseElement); + + // check for session id + NodeList mandateElements = XPathAPI.selectNodeList(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:Mandates/mis:Mandate", NS_NODE); + + if (mandateElements == null || mandateElements.getLength() == 0) { + throw new MISSimpleClientException("No mandates found in response."); + } + + ArrayList foundMandates = new ArrayList(); + for (int i=0; i 0) { + Element certElement = doc.createElementNS(MIS_NS, "X509SignatureCertificate"); + certElement.appendChild(doc.createTextNode(Base64.encodeBase64String(cert))); + mirElement.appendChild(certElement); + } + Element redirectElement = doc.createElementNS(MIS_NS, "RedirectURL"); + redirectElement.appendChild(doc.createTextNode(redirectURL)); + mirElement.appendChild(redirectElement); + Element refValElement = doc.createElementNS(MIS_NS, "ReferenceValue"); + refValElement.appendChild(doc.createTextNode(refValue)); + mirElement.appendChild(refValElement); + if (mandateIdentifier != null && mandateIdentifier.length > 0) { + Element filtersElement = doc.createElementNS(MIS_NS, "Filters"); + Element mandateIdentifiersElement = doc.createElementNS(MIS_NS, "MandateIdentifiers"); + for (int i=0; i