summaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/util/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/util/client')
-rw-r--r--src/main/java/at/gv/util/client/ersb/ERsBClient.java103
-rw-r--r--src/main/java/at/gv/util/client/ersb/ERsBClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/mis/MISClient.java93
-rw-r--r--src/main/java/at/gv/util/client/mis/MISClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/mis/simple/MISMandate.java23
-rw-r--r--src/main/java/at/gv/util/client/mis/simple/MISSessionId.java23
-rw-r--r--src/main/java/at/gv/util/client/mis/simple/MISSimpleClient.java233
-rw-r--r--src/main/java/at/gv/util/client/mis/simple/MISSimpleClientException.java22
-rw-r--r--src/main/java/at/gv/util/client/mis/usp/USPClient.java150
-rw-r--r--src/main/java/at/gv/util/client/mis/usp/USPClientException.java33
-rw-r--r--src/main/java/at/gv/util/client/misstork/MISSTORKClient.java98
-rw-r--r--src/main/java/at/gv/util/client/misstork/MISSTORKClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/mms/MMSClient.java93
-rw-r--r--src/main/java/at/gv/util/client/mms/MMSClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/moaid/MOAIDClient.java126
-rw-r--r--src/main/java/at/gv/util/client/moaid/MOAIDClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/moaspss/MOASPSSClient.java326
-rw-r--r--src/main/java/at/gv/util/client/moaspss/MOASPSSClientException.java44
-rw-r--r--src/main/java/at/gv/util/client/mzs/MOAZSClient.java106
-rw-r--r--src/main/java/at/gv/util/client/mzs/MOAZSClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/omsp/OMSPClient.java46
-rw-r--r--src/main/java/at/gv/util/client/omsp/OMSPClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/omsp/OMSPStatus.java14
-rw-r--r--src/main/java/at/gv/util/client/szr/SZRClient.java167
-rw-r--r--src/main/java/at/gv/util/client/szr/SZRClientException.java23
-rw-r--r--src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java117
-rw-r--r--src/main/java/at/gv/util/client/ur/URClient.java307
-rw-r--r--src/main/java/at/gv/util/client/ur/URClientException.java33
-rw-r--r--src/main/java/at/gv/util/client/ur_V2/URClient.java442
-rw-r--r--src/main/java/at/gv/util/client/ur_V2/URClientException.java33
-rw-r--r--src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java140
-rw-r--r--src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java23
32 files changed, 2979 insertions, 0 deletions
diff --git a/src/main/java/at/gv/util/client/ersb/ERsBClient.java b/src/main/java/at/gv/util/client/ersb/ERsBClient.java
new file mode 100644
index 0000000..82198b3
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ersb/ERsBClient.java
@@ -0,0 +1,103 @@
+package at.gv.util.client.ersb;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.szr.SZRSOAPHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.ersb.ErsbService;
+import at.gv.util.wsdl.ersb.ErsbServiceService;
+import at.gv.util.xsd.ersb.ErsbRequest;
+import at.gv.util.xsd.ersb.ErsbResponse;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class ERsBClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(ERsBClient.class);
+
+ public ERsBClient() {}
+
+ public ERsBClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public ErsbResponse sendERsBRequest(ErsbRequest mir, String ersbServiceURL) throws EgovUtilException {
+ MiscUtil.assertNotNull(mir, "mir");
+ MiscUtil.assertNotNull(ersbServiceURL, "ersbServiceURL");
+
+ URL url = ERsBClient.class.getResource("/schema/ERsB/1.1/ErsbService.wsdl");
+ ErsbServiceService service = new ErsbServiceService(url, new QName("http://statistik.at/namespace/ersb/1#", "ErsbServiceService"));
+ ErsbService port = service.getErsbServiceSoap11();
+
+ log.debug("MISSTORK connection URL: " + ersbServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ersbServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getERsBPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (ersbServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MISSTORK client request.");
+ SSLContext sslContext = config.getERsBsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getERsBsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+
+ return port.ersb(mir);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/ersb/ERsBClientException.java b/src/main/java/at/gv/util/client/ersb/ERsBClientException.java
new file mode 100644
index 0000000..a51d1a6
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ersb/ERsBClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.ersb;
+
+public class ERsBClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public ERsBClientException() {
+ super();
+ }
+
+ public ERsBClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ERsBClientException(String message) {
+ super(message);
+ }
+
+ public ERsBClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mis/MISClient.java b/src/main/java/at/gv/util/client/mis/MISClient.java
new file mode 100644
index 0000000..88afc8b
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/MISClient.java
@@ -0,0 +1,93 @@
+package at.gv.util.client.mis;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.moaid.MOAIDClient;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mis.MandateIssuePortType;
+import at.gv.util.wsdl.mis.MandateIssueService;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.xsd.mis.MandateIssueRequestType;
+import at.gv.util.xsd.mis.MandateIssueResponseType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class MISClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(MISClient.class);
+
+ public MISClient() {}
+
+ public MISClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public MandateIssueResponseType sendMandateIssueRequest(MandateIssueRequestType mir, String misServiceURL) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(mir, "mir");
+ MiscUtil.assertNotNull(misServiceURL, "misServiceURL");
+
+ URL url = MOAIDClient.class.getResource("/wsdl/mis/mis-1.0.3.wsdl");
+ MandateIssueService service = new MandateIssueService(url, new QName("http://reference.e-government.gv.at/namespace/mandates/mis/1.0/wsdl", "MandateIssueService"));
+ MandateIssuePortType port = service.getMandateIssuePort();
+
+ log.debug("MIS connection URL: " + misServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, misServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (misServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MIS client request.");
+ SSLContext sslContext = config.getMISsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMISsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ return port.mandateIssueOperation(mir);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mis/MISClientException.java b/src/main/java/at/gv/util/client/mis/MISClientException.java
new file mode 100644
index 0000000..74d3a4a
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/MISClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.mis;
+
+public class MISClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public MISClientException() {
+ super();
+ }
+
+ public MISClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MISClientException(String message) {
+ super(message);
+ }
+
+ public MISClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
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<mandateElements.getLength(); i++) {
+ Element mandate = (Element) mandateElements.item(i);
+ MISMandate misMandate = new MISMandate();
+ if ("true".equalsIgnoreCase(mandate.getAttribute("ProfessionalRepresentative"))) {
+ misMandate.setProfRep(true);
+ }
+ misMandate.setMandate(Base64.decodeBase64(DOMUtils.getText(mandate)));
+ foundMandates.add(misMandate);
+ }
+ return foundMandates;
+ } catch (ParserConfigurationException e) {
+ throw new MISSimpleClientException(e);
+ } catch (DOMException e) {
+ throw new MISSimpleClientException(e);
+ } catch (TransformerException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+ public static MISSessionId sendSessionIdRequest(String webServiceURL, byte[] idl, byte[] cert, String redirectURL, String refValue, String mandateIdentifier[]) throws MISSimpleClientException {
+ if (webServiceURL == null) {
+ throw new NullPointerException("Argument webServiceURL must not be null.");
+ }
+ if (idl == null) {
+ throw new NullPointerException("Argument idl must not be null.");
+ }
+ if (redirectURL == null) {
+ throw new NullPointerException("Argument redirectURL must not be null.");
+ }
+ if (refValue == null) {
+ throw new NullPointerException("Argument refValue must not be null.");
+ }
+ try {
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element mirElement = doc.createElementNS(MIS_NS, "MandateIssueRequest");
+ Element idlElement = doc.createElementNS(MIS_NS, "IdentityLink");
+ idlElement.appendChild(doc.createTextNode(Base64.encodeBase64String(idl)));
+ mirElement.appendChild(idlElement);
+ if (cert != null && cert.length > 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<mandateIdentifier.length; i++) {
+ Element mandateIdentifierElement = doc.createElementNS(MIS_NS, "MandateIdentifier");
+ mandateIdentifierElement.appendChild(doc.createTextNode(mandateIdentifier[i]));
+ mandateIdentifiersElement.appendChild(mandateIdentifierElement);
+ }
+ filtersElement.appendChild(mandateIdentifiersElement);
+ mirElement.appendChild(filtersElement);
+ }
+ // send soap request
+ Element mandateIssueResponseElement = sendSOAPRequest(webServiceURL, mirElement);
+
+ // check for error
+ checkForError(mandateIssueResponseElement);
+
+ // check for session id
+ Node sessionIdNode = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:SessionID/text()", NS_NODE));
+ if (sessionIdNode == null) {
+ throw new MISSimpleClientException("SessionId not found in response.");
+ }
+ String sessionId = sessionIdNode.getNodeValue();
+
+ Node guiRedirectURLNode = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:GuiRedirectURL/text()", NS_NODE));
+ if (guiRedirectURLNode == null) {
+ throw new MISSimpleClientException("GuiRedirectURL not found in response.");
+ }
+ String guiRedirectURL = guiRedirectURLNode.getNodeValue();
+
+ // create return object
+ MISSessionId msid = new MISSessionId();
+ msid.setSessiondId(sessionId);
+ msid.setRedirectURL(guiRedirectURL);
+
+ return msid;
+ } catch (ParserConfigurationException e) {
+ throw new MISSimpleClientException(e);
+ } catch (DOMException e) {
+ throw new MISSimpleClientException(e);
+ } catch (TransformerException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+ private static void checkForError(Element mandateIssueResponseElement) throws MISSimpleClientException {
+ if (mandateIssueResponseElement == null) {
+ throw new NullPointerException("Argument mandateIssueResponseElement must not be null.");
+ }
+ try {
+ Element errorElement = (Element) XPathAPI.selectSingleNode(mandateIssueResponseElement, "/mis:MandateIssueResponse/mis:Error", NS_NODE);
+ if (errorElement != null) {
+ String code = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "/mis:MandateIssueResponse/mis:Error/mis:Code/text()", NS_NODE)).getNodeValue();
+ String text = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "/mis:MandateIssueResponse/mis:Error/mis:Text/text()", NS_NODE)).getNodeValue();
+ throw new MISSimpleClientException("Fehler beim Abfragen des Online-Vollmachten Services: " + code + " / " + text);
+ }
+ } catch (TransformerException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+ private static Element sendSOAPRequest(String webServiceURL, Element request) throws MISSimpleClientException {
+ if (webServiceURL == null) {
+ throw new NullPointerException("Argument webServiceURL must not be null.");
+ }
+ if (request == null) {
+ throw new NullPointerException("Argument request must not be null.");
+ }
+ try {
+ HttpClient httpclient = new HttpClient();
+ PostMethod post = new PostMethod(webServiceURL);
+ StringRequestEntity re = new StringRequestEntity(DOMUtils.serializeNode(packIntoSOAP(request)),"text/xml", "UTF-8");
+ post.setRequestEntity(re);
+ int responseCode = httpclient.executeMethod(post);
+ if (responseCode != 200) {
+ throw new MISSimpleClientException("Invalid HTTP response code " + responseCode);
+ }
+ return unpackFromSOAP(DOMUtils.parseXmlNonValidating(post.getResponseBodyAsStream()));
+ } catch(IOException e) {
+ throw new MISSimpleClientException(e);
+ } catch (TransformerException e) {
+ throw new MISSimpleClientException(e);
+ } catch (ParserConfigurationException e) {
+ throw new MISSimpleClientException(e);
+ } catch (SAXException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+ private static Element packIntoSOAP(Element element) throws MISSimpleClientException {
+ try {
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element soapEnvelope = doc.createElement("Envelope");
+ soapEnvelope.setAttribute("xmlns", SOAP_NS);
+ Element soapBody = doc.createElement("Body");
+ soapEnvelope.appendChild(soapBody);
+ soapBody.appendChild(doc.importNode(element, true));
+ return soapEnvelope;
+ } catch(ParserConfigurationException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+ private static Element unpackFromSOAP(Element element) throws MISSimpleClientException {
+ try {
+ return (Element) XPathAPI.selectSingleNode(element, "/soap:Envelope/soap:Body/child::*[position()=1]", NS_NODE);
+ } catch(TransformerException e) {
+ throw new MISSimpleClientException(e);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/at/gv/util/client/mis/simple/MISSimpleClientException.java b/src/main/java/at/gv/util/client/mis/simple/MISSimpleClientException.java
new file mode 100644
index 0000000..91250d2
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/simple/MISSimpleClientException.java
@@ -0,0 +1,22 @@
+package at.gv.util.client.mis.simple;
+
+public class MISSimpleClientException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MISSimpleClientException() {
+ }
+
+ public MISSimpleClientException(String message) {
+ super(message);
+ }
+
+ public MISSimpleClientException(Throwable cause) {
+ super(cause);
+ }
+
+ public MISSimpleClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mis/usp/USPClient.java b/src/main/java/at/gv/util/client/mis/usp/USPClient.java
new file mode 100644
index 0000000..ac8315a
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/usp/USPClient.java
@@ -0,0 +1,150 @@
+package at.gv.util.client.mis.usp;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.szr.SZRSOAPHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mis.usp.GetMandatesPortType;
+import at.gv.util.wsdl.mis.usp.GetMandatesService;
+import at.gv.util.xsd.mis.usp.GetMandatesRequest;
+import at.gv.util.xsd.mis.usp.GetMandatesRequest.MandateFilters;
+import at.gv.util.xsd.mis.usp.GetMandatesResponse;
+import at.gv.util.xsd.mis.usp.IdentificationType;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class USPClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ private Logger log = LoggerFactory.getLogger(USPClient.class);
+ private boolean logEnabled = true;
+ private GetMandatesPortType uspSuche = null;
+
+ public USPClient(EgovUtilConfiguration config, boolean logEnabled) throws EgovUtilException {
+ MiscUtil.assertNotNull(config, "config");
+ this.config = config;
+ this.logEnabled = logEnabled;
+ initialize();
+ }
+
+ public GetMandatesResponse getMandates(String bpkType, String bpkValue, List<String> mandateFilters) {
+
+ // assemble request
+ GetMandatesRequest request = new GetMandatesRequest();
+ String requestId = createUSPRequestId();
+ log.debug("USP request id: " + requestId);
+ request.setRequestId(requestId);
+ Date date = new Date();
+ try {
+ request.setTimestamp(MiscUtil.getXMLGregorianCalendar(date));
+ } catch (DatatypeConfigurationException e) {
+ log.warn("Error initializing USP client.", e);
+ return null;
+ }
+ log.debug("USP time stamp: " + date.toString());
+ request.setApplicationId(config.getUSPApplicationId());
+ log.debug("USP application id: " + config.getUSPApplicationId());
+
+ // set identification
+ IdentificationType idt = new IdentificationType();
+ idt.setType(bpkType);
+ idt.setValue(bpkValue);
+ request.setIdentification(idt);
+
+ // set filters
+ if (mandateFilters != null && mandateFilters.size() > 0) {
+ MandateFilters mf = new MandateFilters();
+ mf.getMandateFilter().addAll(mandateFilters);
+ request.setMandateFilters(mf);
+ }
+
+ return this.uspSuche.getMandatesOperation(request);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void initialize() throws EgovUtilException {
+ URL url = USPClient.class.getResource("/wsdl/mis/usp/mis-usp-1.0.2.wsdl");
+ GetMandatesService uspService = null;
+ String uspURL = null;
+ uspService = new GetMandatesService(url, new QName("http://reference.e-government.gv.at/namespace/mandates/mis/usp/1.0.2/wsdl", "GetMandatesService"));
+ uspSuche = uspService.getGetMandatesPort();
+ if (config.isUSPTestEnvironment()) {
+ log.trace("Initializing USP test configuration.");
+ uspURL = config.getUSPTestEnvironmentURL();
+ } else {
+ log.trace("Initializing USP productive configuration.");
+ uspURL = config.getUSPProductionEnvironmentURL();
+ }
+ log.trace("USP connection URL: " + uspURL);
+ BindingProvider bindingProvider = (BindingProvider) uspSuche;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, uspURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ if (this.logEnabled) {
+ handlerList.add(loggingHandler);
+ }
+ // PV authentication
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getURPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+
+ //set HTTP Client Timeout (Default Timeout 60sec)
+ requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, this.config.getHTTPRequestTimeout());
+
+ // check for ssl
+ if (uspURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for SZR client request.");
+ SSLContext sslContext = this.config.getUSPsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getURsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ }
+
+ private String createUSPRequestId() {
+ return RandomStringUtils.randomAlphanumeric(12);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mis/usp/USPClientException.java b/src/main/java/at/gv/util/client/mis/usp/USPClientException.java
new file mode 100644
index 0000000..3c36ccb
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/usp/USPClientException.java
@@ -0,0 +1,33 @@
+package at.gv.util.client.mis.usp;
+
+public class USPClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ private int code = -1;
+
+ public USPClientException(int code) {
+ super();
+ this.code = code;
+ }
+
+ public USPClientException(String message, int code, Throwable cause) {
+ super(message, cause);
+ this.code = code;
+ }
+
+ public USPClientException(String message, int code) {
+ super(message);
+ this.code = code;
+ }
+
+ public USPClientException(int code, Throwable cause) {
+ super(cause);
+ this.code = code;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/misstork/MISSTORKClient.java b/src/main/java/at/gv/util/client/misstork/MISSTORKClient.java
new file mode 100644
index 0000000..ca4173d
--- /dev/null
+++ b/src/main/java/at/gv/util/client/misstork/MISSTORKClient.java
@@ -0,0 +1,98 @@
+package at.gv.util.client.misstork;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.moaid.MOAIDClient;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mis.MandateIssuePortType;
+import at.gv.util.wsdl.mis.MandateIssueService;
+import at.gv.util.wsdl.misstork.MISSTORKService;
+import at.gv.util.wsdl.misstork.MISSTORKType;
+import at.gv.util.wsdl.misstork.MisStorkError;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.xsd.mis.MandateIssueRequestType;
+import at.gv.util.xsd.mis.MandateIssueResponseType;
+import at.gv.util.xsd.misstork.MisStorkRequest;
+import at.gv.util.xsd.misstork.MisStorkResponse;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class MISSTORKClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(MISSTORKClient.class);
+
+ public MISSTORKClient() {}
+
+ public MISSTORKClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public MisStorkResponse sendMISSTORKRequest(MisStorkRequest mir, String misSTORKServiceURL) throws MisStorkError, EgovUtilException {
+ MiscUtil.assertNotNull(mir, "mir");
+ MiscUtil.assertNotNull(misSTORKServiceURL, "misServiceURL");
+
+ URL url = MOAIDClient.class.getResource("/wsdl/misstork/misstork.wsdl");
+ MISSTORKService service = new MISSTORKService(url, new QName("http://reference.e-government.gv.at/namespace/misstork/20131126/wsdl", "MISSTORKService"));
+ MISSTORKType port = service.getMISSTORKPort();
+
+ log.debug("MISSTORK connection URL: " + misSTORKServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, misSTORKServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (misSTORKServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MISSTORK client request.");
+ SSLContext sslContext = config.getMISSTORKsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMISsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ return port.misstorkOperation(mir);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/misstork/MISSTORKClientException.java b/src/main/java/at/gv/util/client/misstork/MISSTORKClientException.java
new file mode 100644
index 0000000..19b4cb2
--- /dev/null
+++ b/src/main/java/at/gv/util/client/misstork/MISSTORKClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.misstork;
+
+public class MISSTORKClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public MISSTORKClientException() {
+ super();
+ }
+
+ public MISSTORKClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MISSTORKClientException(String message) {
+ super(message);
+ }
+
+ public MISSTORKClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mms/MMSClient.java b/src/main/java/at/gv/util/client/mms/MMSClient.java
new file mode 100644
index 0000000..1195d3d
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mms/MMSClient.java
@@ -0,0 +1,93 @@
+package at.gv.util.client.mms;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.moaid.MOAIDClient;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mms.GetMandatesPortType;
+import at.gv.util.wsdl.mms.GetMandatesService;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.xsd.mms.GetMandatesRequest;
+import at.gv.util.xsd.mms.GetMandatesResponse;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class MMSClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(MMSClient.class);
+
+ public MMSClient() {}
+
+ public MMSClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public GetMandatesResponse sendGetMandatesRequest(GetMandatesRequest request, String mmsServiceURL) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(request, "request");
+ MiscUtil.assertNotNull(mmsServiceURL, "mmsServiceURL");
+
+ URL url = MOAIDClient.class.getResource("/wsdl/mms/mms.wsdl");
+ GetMandatesService service = new GetMandatesService(url, new QName("http://reference.e-government.gv.at/namespace/mandates/mms/1.0/wsdl", "GetMandatesService"));
+ GetMandatesPortType port = service.getGetMandatesPort();
+
+ log.debug("MMS connection URL: " + mmsServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, mmsServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (mmsServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MMS client request.");
+ SSLContext sslContext = config.getMMSsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMMSsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ return port.getMandatesOperation(request);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mms/MMSClientException.java b/src/main/java/at/gv/util/client/mms/MMSClientException.java
new file mode 100644
index 0000000..579b4a2
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mms/MMSClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.mms;
+
+public class MMSClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public MMSClientException() {
+ super();
+ }
+
+ public MMSClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MMSClientException(String message) {
+ super(message);
+ }
+
+ public MMSClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/moaid/MOAIDClient.java b/src/main/java/at/gv/util/client/moaid/MOAIDClient.java
new file mode 100644
index 0000000..09f8a57
--- /dev/null
+++ b/src/main/java/at/gv/util/client/moaid/MOAIDClient.java
@@ -0,0 +1,126 @@
+package at.gv.util.client.moaid;
+
+import java.math.BigInteger;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.GetAuthenticationDataService;
+import at.gv.util.wsdl.IdentificationPortType;
+import at.gv.util.wsdl.MOAFault;
+import at.gv.util.xsd.saml.protocol.RequestType;
+import at.gv.util.xsd.saml.protocol.ResponseType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class MOAIDClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(MOAIDClient.class);
+
+ public MOAIDClient() {}
+
+ public MOAIDClient(EgovUtilConfiguration config) {
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public ResponseType sendGetAuthenticationDataRequest(String getAuthDataServiceURL, String artifact) throws MOAIDClientException {
+
+ // verify that parameters are not null
+ if (getAuthDataServiceURL == null) {
+ throw new NullPointerException("Parameter 'getAuthDataServiceURL' must not be null.");
+ }
+ if (artifact == null) {
+ throw new NullPointerException("Parameter 'artifact' must not be null.");
+ }
+
+ URL url = MOAIDClient.class.getResource("/wsdl/MOA-ID-1.x.wsdl");
+ GetAuthenticationDataService service = new GetAuthenticationDataService(url, new QName("http://reference.e-government.gv.at/namespace/moa/20020822#", "GetAuthenticationDataService"));
+ IdentificationPortType port = service.getIdentificationPort();
+
+ log.trace("Authentication data service request URL: " + getAuthDataServiceURL);
+ try {
+
+ // set endpoint address
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getAuthDataServiceURL);
+
+ // add trace log
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // initialize ssl
+
+
+ if (getAuthDataServiceURL.toLowerCase().startsWith("https")) {
+ if (this.config == null) {
+ throw new MOAIDClientException("SSL requires a valid configuration for MOA-ID client.");
+ }
+ log.trace("Using ssl for MOA-ID get authentication data request.");
+ SSLContext sslContext = config.getMOAIDsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new MOAIDClientException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMOAIDsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+
+ // make simple moa-id request
+ RequestType request = new RequestType();
+ request.setMajorVersion(BigInteger.ONE);
+ request.setMinorVersion(BigInteger.ZERO);
+ request.setIssueInstant(MiscUtil.getXMLGregorianCalendar(new Date()));
+ request.setRequestID(RandomStringUtils.randomAlphanumeric(10));
+
+ request.getAssertionArtifact().add(artifact);
+
+ return port.getAuthenticationData(request);
+
+ } catch (EgovUtilException e) {
+ throw new MOAIDClientException(e);
+ } catch (MOAFault e) {
+ throw new MOAIDClientException(e);
+ } catch (DatatypeConfigurationException e) {
+ throw new MOAIDClientException(e);
+ }
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/moaid/MOAIDClientException.java b/src/main/java/at/gv/util/client/moaid/MOAIDClientException.java
new file mode 100644
index 0000000..e9289e5
--- /dev/null
+++ b/src/main/java/at/gv/util/client/moaid/MOAIDClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.moaid;
+
+public class MOAIDClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public MOAIDClientException() {
+ super();
+ }
+
+ public MOAIDClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MOAIDClientException(String message) {
+ super(message);
+ }
+
+ public MOAIDClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/moaspss/MOASPSSClient.java b/src/main/java/at/gv/util/client/moaspss/MOASPSSClient.java
new file mode 100644
index 0000000..ab8acd8
--- /dev/null
+++ b/src/main/java/at/gv/util/client/moaspss/MOASPSSClient.java
@@ -0,0 +1,326 @@
+/*
+ * Copyright 2011 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.gv.util.client.moaspss;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.SSLContext;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import at.gv.util.DOMUtils;
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.SignatureCreationService;
+import at.gv.util.wsdl.SignatureVerificationService;
+import at.gv.util.xsd.moaspss.CreateXMLSignatureRequest;
+import at.gv.util.xsd.moaspss.CreateXMLSignatureResponseType;
+import at.gv.util.xsd.moaspss.ErrorResponseType;
+import at.gv.util.xsd.moaspss.VerifyXMLSignatureRequestType;
+import at.gv.util.xsd.moaspss.VerifyXMLSignatureResponseType;
+
+import com.sun.org.apache.xpath.internal.XPathAPI;
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+/**
+ * MOA-SS client.
+ *
+ * @author <a href="mailto:Arne.Tauber@egiz.gv.at">Arne Tauber</a>
+ *
+ */
+public class MOASPSSClient {
+
+ private static Logger log = LoggerFactory.getLogger(MOASPSSClient.class);
+
+ private EgovUtilConfiguration config = null;
+
+ public MOASPSSClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Argument 'config' must not be null.");
+ }
+ this.config = config;
+ }
+
+ public MOASPSSClient() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public Element sendSignatureCreationRequest(String serviceURL,
+ InputStream signatureCreationRequest) throws MOASPSSClientException {
+
+ log.debug("Creating XML signature using raw CreateXMLSignatureRequest.");
+ // check for arguments
+ if (serviceURL == null) {
+ throw new NullPointerException("Argument 'serviceURL' must not be null.");
+ }
+ if (signatureCreationRequest == null) {
+ throw new NullPointerException(
+ "Argument 'signatureRequest' must not be null.");
+ }
+
+ try {
+
+ log.trace("MOA-SS signature service URL: " + serviceURL);
+ URL url = MOASPSSClient.class.getResource("/wsdl/MOA-SPSS-1.3.wsdl");
+ SignatureCreationService service = new SignatureCreationService(
+ url,
+ new QName(
+ "http://reference.e-government.gv.at/namespace/moa/20020822#moa.wsdl",
+ "SignatureCreationService"));
+ QName qname = new QName(
+ "http://localhost:8080/moa-spss/services/SignatureCreation",
+ "CreateXMLSignatureRequest");
+ service.addPort(qname, SOAPBinding.SOAP11HTTP_BINDING, serviceURL);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ MiscUtil.copyStream(signatureCreationRequest, bos);
+
+ Source source = new StreamSource(new ByteArrayInputStream(
+ bos.toByteArray()));
+ Dispatch<Source> dispatch = service.createDispatch(qname, Source.class,
+ Service.Mode.PAYLOAD);
+
+ BindingProvider bindingProvider = (BindingProvider) dispatch;
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding()
+ .getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // initialize ssl
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+
+ if (serviceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MOA-SP request.");
+ if (this.config == null) {
+ throw new MOASPSSClientException(
+ "SSL requires client to be configured.");
+ }
+ SSLContext sslContext = this.config.getMOASPSSsslConfiguration()
+ .getSSLContext(false);
+ if (sslContext == null) {
+ throw new MOASPSSClientException(
+ "SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY,
+ sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMOASPSSsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER,
+ new LaxHostNameVerifier());
+ }
+ }
+
+ log.trace("Invoking MOA-SS signature creation service.");
+ Source response = dispatch.invoke(source);
+
+ log.trace("Parsing MOA-SS response.");
+ byte[] moaResponse = MiscUtil.sourceToByteArray(response);
+ JAXBContext ctx = JAXBContext.newInstance(CreateXMLSignatureRequest.class
+ .getPackage().getName());
+ JAXBElement<CreateXMLSignatureResponseType> jaxbElement = (JAXBElement<CreateXMLSignatureResponseType>) ctx
+ .createUnmarshaller()
+ .unmarshal(new ByteArrayInputStream(moaResponse));
+ CreateXMLSignatureResponseType createXMLResponse = jaxbElement.getValue();
+ for (Object obj : createXMLResponse
+ .getSignatureEnvironmentOrErrorResponse()) {
+ if (obj instanceof ErrorResponseType) {
+ ErrorResponseType errorResponse = (ErrorResponseType) obj;
+ log.trace("Could not create signature: "
+ + errorResponse.getErrorCode() + "/" + errorResponse.getInfo());
+ throw new MOASPSSClientException("MOA-SS signature error: "
+ + errorResponse.getErrorCode() + "/" + errorResponse.getInfo());
+ }
+ }
+ log.trace(new String(moaResponse));
+ log.trace("Signature successfully created. Extracting from MOA-SS container.");
+ // ok, we have success
+ Document doc = MiscUtil.parseDocument(new ByteArrayInputStream(
+ moaResponse));
+ String xpathExpression = "/moa:CreateXMLSignatureResponse/moa:SignatureEnvironment/child::*";
+ Element nsNode = doc.createElement("NsNode");
+ nsNode.setAttribute("xmlns:moa", doc.getDocumentElement()
+ .getNamespaceURI());
+ log.trace("Selecting signed doc " + xpathExpression);
+ Element documentNode = (Element) XPathAPI.selectSingleNode(doc,
+ xpathExpression, nsNode);
+ log.trace("Signed document: " + DOMUtils.serializeNode(documentNode));
+
+ return documentNode;
+ } catch (TransformerException e) {
+ throw new MOASPSSClientException(e);
+ } catch (IOException e) {
+ throw new MOASPSSClientException(e);
+ } catch (JAXBException e) {
+ throw new MOASPSSClientException(e);
+ } catch (EgovUtilException e) {
+ throw new MOASPSSClientException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public VerifyXMLSignatureResponseType sendSignatureVerificationRequest(
+ String serviceURL, InputStream signatureVerificationRequest)
+ throws MOASPSSClientException {
+ log.debug("Verifying XML signature using raw VerifyXMLSignatureRequest.");
+
+ // check for arguments
+ if (serviceURL == null) {
+ throw new NullPointerException("Argument 'serviceURL' must not be null.");
+ }
+ if (signatureVerificationRequest == null) {
+ throw new NullPointerException(
+ "Argument 'signatureRequest' must not be null.");
+ }
+
+ try {
+ log.trace("MOA-SP verification service URL: " + serviceURL);
+ URL url = MOASPSSClient.class.getResource("/wsdl/MOA-SPSS-1.3.wsdl");
+ SignatureVerificationService service = new SignatureVerificationService(
+ url,
+ new QName(
+ "http://reference.e-government.gv.at/namespace/moa/20020822#moa.wsdl",
+ "SignatureCreationService"));
+ QName qname = new QName(
+ "http://localhost:8080/moa-spss/services/SignatureVerification",
+ "VerifyXMLSignatureRequest");
+ service.addPort(qname, SOAPBinding.SOAP11HTTP_BINDING, serviceURL);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ MiscUtil.copyStream(signatureVerificationRequest, bos);
+
+ Source source = new StreamSource(new ByteArrayInputStream(
+ bos.toByteArray()));
+ Dispatch<Source> dispatch = service.createDispatch(qname, Source.class,
+ Service.Mode.PAYLOAD);
+
+ BindingProvider bindingProvider = (BindingProvider) dispatch;
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding()
+ .getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // initialize ssl
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+
+ if (serviceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MOA-SP request.");
+ if (this.config == null) {
+ throw new MOASPSSClientException(
+ "SSL requires client to be configured.");
+ }
+ SSLContext sslContext = this.config.getMOASPSSsslConfiguration()
+ .getSSLContext(false);
+ if (sslContext == null) {
+ throw new MOASPSSClientException(
+ "SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY,
+ sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMOASPSSsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER,
+ new LaxHostNameVerifier());
+ }
+ }
+
+ log.trace("Invoking MOA-SP signature verification service.");
+ Source response = dispatch.invoke(source);
+
+ log.trace("Parsing MOA-SP response.");
+ byte[] moaResponse = MiscUtil.sourceToByteArray(response);
+ JAXBContext ctx = JAXBContext
+ .newInstance(VerifyXMLSignatureRequestType.class.getPackage()
+ .getName());
+ JAXBElement<VerifyXMLSignatureResponseType> jaxbElement = (JAXBElement<VerifyXMLSignatureResponseType>) ctx
+ .createUnmarshaller()
+ .unmarshal(new ByteArrayInputStream(moaResponse));
+ VerifyXMLSignatureResponseType verifyXMLResponse = jaxbElement.getValue();
+ log.trace(new String(moaResponse));
+ return verifyXMLResponse;
+ } catch (TransformerException e) {
+ throw new MOASPSSClientException(e);
+ } catch (IOException e) {
+ throw new MOASPSSClientException(e);
+ } catch (JAXBException e) {
+ throw new MOASPSSClientException(e);
+ } catch (EgovUtilException e) {
+ throw new MOASPSSClientException(e);
+ }
+ }
+
+ public static boolean isSuccess(VerifyXMLSignatureResponseType verifyResult) {
+ if (verifyResult == null) {
+ throw new NullPointerException(
+ "Argument 'verifyResult' must not be null.");
+ }
+ log.trace("Checking for signature verification result.");
+
+ int signatureCheckCode = verifyResult.getSignatureCheck().getCode()
+ .intValue();
+ int signtaureManifestCheckCode = verifyResult.getSignatureManifestCheck()
+ .getCode().intValue();
+ int certificateCheckCode = verifyResult.getCertificateCheck().getCode()
+ .intValue();
+
+ log.trace("Signature check code: " + signatureCheckCode);
+ log.trace("Signature manifest check code: " + signtaureManifestCheckCode);
+ log.trace("Certificate check code: " + certificateCheckCode);
+
+ return signatureCheckCode == 0 && signtaureManifestCheckCode == 0
+ && certificateCheckCode == 0;
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/moaspss/MOASPSSClientException.java b/src/main/java/at/gv/util/client/moaspss/MOASPSSClientException.java
new file mode 100644
index 0000000..73f3acc
--- /dev/null
+++ b/src/main/java/at/gv/util/client/moaspss/MOASPSSClientException.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2011 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.gv.util.client.moaspss;
+
+/**
+ * MOA-SS client exception class.
+ *
+ * @author <a href="mailto:Arne.Tauber@egiz.gv.at">Arne Tauber</a>
+ *
+ */
+public class MOASPSSClientException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MOASPSSClientException() {
+ }
+
+ public MOASPSSClientException(String message) {
+ super(message);
+ }
+
+ public MOASPSSClientException(Throwable cause) {
+ super(cause);
+ }
+
+ public MOASPSSClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mzs/MOAZSClient.java b/src/main/java/at/gv/util/client/mzs/MOAZSClient.java
new file mode 100644
index 0000000..dc66a2b
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mzs/MOAZSClient.java
@@ -0,0 +1,106 @@
+package at.gv.util.client.mzs;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mzs.App2Mzs;
+import at.gv.util.wsdl.mzs.App2MzsPortType;
+import at.gv.util.xsd.mzs.DeliveryRequestType;
+import at.gv.util.xsd.mzs.DeliveryResponseType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class MOAZSClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(MOAZSClient.class);
+
+ public MOAZSClient() {}
+
+ public MOAZSClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public DeliveryResponseType sendMOAZSRequest(DeliveryRequestType request, String serviceURL) throws MOAZSClientException {
+
+ // verify that parameters are not null
+ if (request == null) {
+ throw new NullPointerException("Parameter 'request' must not be null.");
+ }
+
+ if (serviceURL == null) {
+ throw new NullPointerException("Parameter 'serviceURL' must not be null.");
+ }
+
+ URL url = MOAZSClient.class.getResource("/wsdl/mzs/app2mzs.wsdl");
+ App2Mzs service = new App2Mzs(url, new QName("http://reference.e-government.gv.at/namespace/app2mzs.wsdl", "app2mzs"));
+ App2MzsPortType port = service.getApp2MzsPort();
+
+ log.trace("MOA-ZS request URL: " + serviceURL);
+ try {
+
+ // set endpoint address
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
+
+ // add trace log
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // initialize ssl
+ if (serviceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for MOA-ZS get authentication data request.");
+ SSLContext sslContext = config.getMOAZSsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new MOAZSClientException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getMOAIDsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+
+ // make simple moa-id request
+
+ return port.app2Mzs(request);
+
+ } catch (EgovUtilException e) {
+ throw new MOAZSClientException(e);
+ }
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mzs/MOAZSClientException.java b/src/main/java/at/gv/util/client/mzs/MOAZSClientException.java
new file mode 100644
index 0000000..cb98f06
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mzs/MOAZSClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.mzs;
+
+public class MOAZSClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public MOAZSClientException() {
+ super();
+ }
+
+ public MOAZSClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MOAZSClientException(String message) {
+ super(message);
+ }
+
+ public MOAZSClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/omsp/OMSPClient.java b/src/main/java/at/gv/util/client/omsp/OMSPClient.java
new file mode 100644
index 0000000..42ef55a
--- /dev/null
+++ b/src/main/java/at/gv/util/client/omsp/OMSPClient.java
@@ -0,0 +1,46 @@
+package at.gv.util.client.omsp;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import at.gv.util.MiscUtil;
+import at.gv.util.xsd.omsp.SignedStatusResponse;
+
+public class OMSPClient {
+
+ public static SignedStatusResponse checkMandateStatus(String serviceURL, String mandateId, Date date) throws OMSPClientException {
+ MiscUtil.assertNotNull(serviceURL, "serviceURL");
+ MiscUtil.assertNotNull(mandateId, "mandateId");
+ HttpClient httpclient = new HttpClient();
+ GetMethod method = new GetMethod(serviceURL);
+ String queryString = mandateId;
+ if (date != null) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ mandateId += "+" + sdf.format(date);
+ }
+ method.setQueryString(queryString);
+ try {
+ int code = httpclient.executeMethod(method);
+ if (code != 200) {
+ throw new OMSPClientException("Response code " + code + " returned. Must be 200.");
+ }
+ JAXBContext ctx = JAXBContext.newInstance(SignedStatusResponse.class.getPackage().getName());
+ return (SignedStatusResponse) ctx.createUnmarshaller().unmarshal(method.getResponseBodyAsStream());
+ } catch (HttpException e) {
+ throw new OMSPClientException(e);
+ } catch (IOException e) {
+ throw new OMSPClientException(e);
+ } catch (JAXBException e) {
+ throw new OMSPClientException(e);
+ }
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/omsp/OMSPClientException.java b/src/main/java/at/gv/util/client/omsp/OMSPClientException.java
new file mode 100644
index 0000000..f3a5713
--- /dev/null
+++ b/src/main/java/at/gv/util/client/omsp/OMSPClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.omsp;
+
+public class OMSPClientException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public OMSPClientException() {
+ super();
+ }
+
+ public OMSPClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public OMSPClientException(String message) {
+ super(message);
+ }
+
+ public OMSPClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/omsp/OMSPStatus.java b/src/main/java/at/gv/util/client/omsp/OMSPStatus.java
new file mode 100644
index 0000000..31ffc73
--- /dev/null
+++ b/src/main/java/at/gv/util/client/omsp/OMSPStatus.java
@@ -0,0 +1,14 @@
+package at.gv.util.client.omsp;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class OMSPStatus {
+
+ public final static String ACTIVE = "active";
+ public final static String UNKNOWN = "unknown";
+ public final static String REVOKED = "revoked";
+
+ public final static List<String> ALLOWED_CODES = Arrays.asList(ACTIVE, REVOKED, UNKNOWN);
+
+}
diff --git a/src/main/java/at/gv/util/client/szr/SZRClient.java b/src/main/java/at/gv/util/client/szr/SZRClient.java
new file mode 100644
index 0000000..cb98210
--- /dev/null
+++ b/src/main/java/at/gv/util/client/szr/SZRClient.java
@@ -0,0 +1,167 @@
+package at.gv.util.client.szr;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Holder;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.szr.SZR;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.wsdl.szr.SZRService;
+import at.gv.util.xsd.szr.FremdBPKRequestType;
+import at.gv.util.xsd.szr.FremdBPKType;
+import at.gv.util.xsd.szr.IdentityLinkType;
+import at.gv.util.xsd.szr.PersonInfoType;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+import at.gv.util.xsd.szr.xmldsig.KeyValueType;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class SZRClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(SZRClient.class);
+
+ private SZR szr = null;
+
+ public SZRClient(EgovUtilConfiguration config) throws EgovUtilException {
+ MiscUtil.assertNotNull(config, "config");
+ this.config = config;
+ initialize();
+ }
+
+ public IdentityLinkType getIdentityLink(PersonInfoType personInfo, List<KeyValueType> keyValue, Boolean insertERnP) throws SZRException {
+ MiscUtil.assertNotNull(personInfo, "personInfo");
+ MiscUtil.assertNotNull(keyValue, "keyValue");
+ return this.szr.getIdentityLink(personInfo, keyValue, insertERnP);
+ }
+
+ public String getStammzahl(PersonInfoType personInfo) throws SZRException {
+ MiscUtil.assertNotNull(personInfo, "personInfo");
+ return this.szr.getStammzahl(personInfo);
+ }
+
+ public String getBPK(PersonInfoType personInfo, String target, String vkz) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(personInfo, "personInfo");
+ MiscUtil.assertNotNull(target, "target");
+ String targetPrefix = "urn:publicid:gv.at:cdid+";
+ String targetString = null;
+ if (target.length() == 2) {
+ targetString = targetPrefix + target;
+ } else if (!target.startsWith(targetPrefix)) {
+ throw new EgovUtilException("Target must start with " + targetPrefix);
+ } else {
+ targetString = target;
+ }
+ Holder<String> returnBPK = new Holder<String>();
+
+ this.szr.getBPK(personInfo, targetString, vkz, null, false, returnBPK, null, null);
+
+ return returnBPK.value;
+ }
+
+ public String transformBPK(PersonInfoType personInfo, String inputBpk, String inputTarget, String target, String vkz) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(personInfo, "personInfo");
+ MiscUtil.assertNotNull(target, "target");
+ String targetPrefix = "urn:publicid:gv.at:cdid+";
+ String targetString = null;
+ if (target.length() == 2) {
+ targetString = targetPrefix + target;
+ } else if (!target.startsWith(targetPrefix)) {
+ throw new EgovUtilException("Target must start with " + targetPrefix);
+ } else {
+ targetString = target;
+ }
+ Holder<String> returnBPK = new Holder<String>();
+ FremdBPKRequestType rt = new FremdBPKRequestType();
+ rt.setBereichsKennung(target);
+ rt.setVKZ(vkz);
+ List<FremdBPKRequestType> list = new ArrayList<FremdBPKRequestType>();
+ list.add(rt);
+ List<FremdBPKType> response = this.szr.transformBPK(personInfo, inputBpk, inputTarget, "kt", list);
+ if (response == null) {
+ return null;
+ }
+ return response.get(0).getFremdBPK();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void initialize() throws EgovUtilException {
+ URL url = SZRClient.class.getResource("/wsdl/szr/SZR_v2.0.wsdl");
+ SZRService szrService = null;
+ if (config.isSZRTestEnvironment()) {
+ log.trace("Initializing SZR test configuration.");
+ //szrService = new SZRService(url, new QName("urn:SZRServices", "SZRTestumgebung"));
+ szrService = new SZRService(url, new QName("urn:SZRServices", "SZRService"));
+ szr = szrService.getSZRTestumgebung();
+ } else {
+ log.trace("Initializing SZR productive configuration.");
+ szrService = new SZRService(url, new QName("urn:SZRServices", "SZRService"));
+ szr = szrService.getSZRProduktionsumgebung();
+ }
+ String szrURL = null;
+ if (config.isSZRTestEnvironment()) {
+ szrURL = config.getSZRTestEnvironmentURL();
+ } else {
+ szrURL = config.getSZRProductionEnvironmentURL();
+ }
+
+ log.trace("SZR connection URL: " + szrURL);
+ BindingProvider bindingProvider = (BindingProvider) szr;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, szrURL);
+
+
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (szrURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for SZR client request.");
+ SSLContext sslContext = this.config.getSZRsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getSZRsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/szr/SZRClientException.java b/src/main/java/at/gv/util/client/szr/SZRClientException.java
new file mode 100644
index 0000000..3b864da
--- /dev/null
+++ b/src/main/java/at/gv/util/client/szr/SZRClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.szr;
+
+public class SZRClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public SZRClientException() {
+ super();
+ }
+
+ public SZRClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SZRClientException(String message) {
+ super(message);
+ }
+
+ public SZRClientException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java b/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java
new file mode 100644
index 0000000..05e5004
--- /dev/null
+++ b/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java
@@ -0,0 +1,117 @@
+package at.gv.util.client.szr;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import at.gv.util.DOMUtils;
+import at.gv.util.MiscUtil;
+import at.gv.util.xsd.szr.pvp.ObjectFactory;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+
+public class SZRSOAPHandler implements SOAPHandler<SOAPMessageContext> {
+
+ private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/04/secext";
+ private static final String AUTH_PREFIX="wss";
+
+ private PvpTokenType pvpTokenType = null;
+
+ private Logger log = LoggerFactory.getLogger(SZRSOAPHandler.class);
+
+
+ public void close(MessageContext arg0) {
+ }
+
+
+ public boolean handleFault(SOAPMessageContext arg0) {
+ return true;
+ }
+
+ public void configure(PvpTokenType pvpToken) {
+ MiscUtil.assertNotNull(pvpToken, "pvpToken");
+ this.pvpTokenType = pvpToken;
+ }
+
+
+ public boolean handleMessage(SOAPMessageContext smc) {
+ log.trace("Initializing SZR SOAP message handler.");
+
+ boolean isOutMessage = ((Boolean) smc.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
+ log.trace("Outbound message: " + isOutMessage);
+ if (pvpTokenType == null) {
+ throw new NullPointerException("Please configure first the PVP token.");
+ }
+
+ if (!isOutMessage) {
+ return true;
+ }
+ try {
+ SOAPMessage message = smc.getMessage();
+ SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
+ SOAPFactory soapFactory = SOAPFactory.newInstance();
+
+ // Creating WS-Security header element
+ SOAPElement wsSecHeaderElm = soapFactory.createElement(
+ "Security",
+ AUTH_PREFIX,
+ AUTH_NS);
+
+ // serialize pvp token
+ JAXBContext ctx = JAXBContext.newInstance(PvpTokenType.class);
+ ObjectFactory of = new ObjectFactory();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ctx.createMarshaller().marshal(of.createPvpToken(pvpTokenType), bos);
+ Element pvpTokenElement = DOMUtils.parseXmlNonValidating(new ByteArrayInputStream(bos.toByteArray()));
+ SOAPElement pvpToken = soapFactory.createElement(pvpTokenElement);
+
+ // adding elements
+ wsSecHeaderElm.addChildElement(pvpToken);
+ SOAPHeader header = envelope.addHeader();
+ header.addChildElement(wsSecHeaderElm);
+
+ return true;
+ } catch(SOAPException e) {
+ log.warn("Cannot add WS-Security header.", e);
+ return false;
+ } catch (JAXBException e) {
+ log.warn("Cannot add WS-Security header.", e);
+ return false;
+ } catch (ParserConfigurationException e) {
+ log.warn("Cannot add WS-Security header.", e);
+ return false;
+ } catch (SAXException e) {
+ log.warn("Cannot add WS-Security header.", e);
+ return false;
+ } catch (IOException e) {
+ log.warn("Cannot add WS-Security header.", e);
+ return false;
+ }
+
+
+ }
+
+ public Set<QName> getHeaders() {
+ return null;
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/ur/URClient.java b/src/main/java/at/gv/util/client/ur/URClient.java
new file mode 100644
index 0000000..4988a0f
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ur/URClient.java
@@ -0,0 +1,307 @@
+package at.gv.util.client.ur;
+
+import java.math.BigInteger;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import at.gv.util.xsd.ur.xmlsw.ResultCriteriaType;
+import at.gv.util.xsd.ur.xmlsw.ResultRecord;
+import at.gv.util.xsd.ur.xmlsw.SearchByExampleType;
+import at.gv.util.xsd.ur.xmlsw.SearchCriteriaType;
+import at.gv.util.xsd.ur.xmlsw.SearchResponseType;
+import at.gv.util.DOMUtils;
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.szr.SZRSOAPHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.ur.URSuche;
+import at.gv.util.wsdl.ur.URSucheService;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+import at.gv.util.xsd.ur.pd.IdentificationType;
+import at.gv.util.xsd.ur.pd.NichtNatuerlichePersonTyp;
+import at.gv.util.xsd.ur.pd.PersonenDatenTyp;
+import at.gv.util.xsd.ur.search.Funktion;
+import at.gv.util.xsd.ur.search.ObjectFactory;
+import at.gv.util.xsd.ur.search.SucheUnternehmenNachBpkRequest;
+import at.gv.util.xsd.ur.search.SucheUnternehmenNachIdsRequest;
+import at.gv.util.xsd.ur.search.SucheUnternehmenRequest;
+import at.gv.util.xsd.ur.search.SucheUnternehmensdaten;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class URClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ private Logger log = LoggerFactory.getLogger(URClient.class);
+ private boolean logEnabled = true;
+ private boolean evbCheck = true;
+
+ private URSuche urSuche = null;
+
+ private final static String version = "V2.0";
+ private List<String> allowedKeys = null;
+
+ private final static String EVB = "einzelvertretungsbefugt";
+
+ public URClient(EgovUtilConfiguration config, List<String> allowedKeys, boolean evbCheck, boolean logEnabled) throws EgovUtilException {
+ MiscUtil.assertNotNull(config, "config");
+ this.config = config;
+ this.allowedKeys = allowedKeys;
+ this.logEnabled = logEnabled;
+ this.evbCheck = evbCheck;
+ initialize();
+ }
+
+ public List<NichtNatuerlichePersonTyp> searchByBpk(String vzbpk) throws URClientException {
+ SucheUnternehmenNachBpkRequest request = new SucheUnternehmenNachBpkRequest();
+ ObjectFactory of = new ObjectFactory();
+ request.setVersion(version);
+ request.setBpkWTUREncoded(vzbpk);
+ List<ResultRecord> results = searchByExample(of.createSucheUnternehmenNachBpkRequest(request), -1);
+ return getNichtNatuerlichePersonen(results);
+ }
+
+ public List<NichtNatuerlichePersonTyp> searchByRegisterNumber(String number, String type, int maxResults) throws URClientException {
+ SucheUnternehmenRequest request = new SucheUnternehmenRequest();
+ ObjectFactory of = new ObjectFactory();
+ request.setVersion(version);
+ SucheUnternehmensdaten sud = new SucheUnternehmensdaten();
+ sud.setId(number);
+ sud.setIdArt(type);
+ request.setUnternehmensdaten(sud);
+ List<ResultRecord> results = searchByExample(of.createSucheUnternehmenRequest(request), maxResults);
+ return getNichtNatuerlichePersonen(results);
+ }
+
+ public List<NichtNatuerlichePersonTyp> searchByName(String name, String plz, int maxResults) throws URClientException {
+ SucheUnternehmenRequest request = new SucheUnternehmenRequest();
+ ObjectFactory of = new ObjectFactory();
+ request.setVersion(version);
+ SucheUnternehmensdaten sud = new SucheUnternehmensdaten();
+ sud.setUntName(name);
+ if (MiscUtil.isNotEmpty(plz)) {
+ sud.setPlz(plz);
+ }
+ request.setUnternehmensdaten(sud);
+ List<ResultRecord> results = searchByExample(of.createSucheUnternehmenRequest(request), maxResults);
+ return getNichtNatuerlichePersonen(results);
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<NichtNatuerlichePersonTyp> getNichtNatuerlichePersonen(List<ResultRecord> records) throws URClientException {
+
+ if (records == null || records.size() == 0) {
+ return new ArrayList<NichtNatuerlichePersonTyp>();
+ }
+ List<String> kurs = new ArrayList<String>();
+ for (ResultRecord rr : records) {
+ PersonenDatenTyp pdt = ((JAXBElement<PersonenDatenTyp>) rr.getAny().get(0)).getValue();
+ NichtNatuerlichePersonTyp nnpt = ((JAXBElement<NichtNatuerlichePersonTyp>) pdt.getPerson()).getValue();
+ for (IdentificationType idt : nnpt.getIdentification()) {
+ if ("KUR".equals(idt.getType())) {
+
+ // check evb
+ if (this.evbCheck) {
+ if (isEVB(pdt)) {
+ kurs.add(idt.getValue().getValue());
+ log.debug("EVB found for " + nnpt.getVollerName());
+ } else {
+ log.debug("Not EVB for " + nnpt.getVollerName());
+ }
+ } else {
+ kurs.add(idt.getValue().getValue());
+ }
+ }
+ }
+ }
+ return getNichtNatuerlichePerson(kurs);
+ }
+
+ // check if person is einzelvertretungsbefugt
+ public static boolean isEVB(PersonenDatenTyp pdt) {
+ boolean isEVB = false;
+ for (Object content : pdt.getZusatzdaten().getContent()) {
+ if (content instanceof JAXBElement) {
+ JAXBElement jxb = (JAXBElement) content;
+ if (jxb.getDeclaredType().equals(PersonenDatenTyp.class)) {
+ PersonenDatenTyp pd = (PersonenDatenTyp) jxb.getValue();
+ if (pd.getZusatzdaten() != null) {
+ for (Object c2 : pd.getZusatzdaten().getContent()) {
+
+ if (c2 instanceof Element) {
+ Element fktElement = (Element) c2;
+ if ("Funktion".equals(fktElement.getLocalName())) {
+ NodeList nl = fktElement.getElementsByTagNameNS("http://statistik.at/namespace/ur/stammdaten/1#", "Vertretungsbefugnis");
+ if (nl.getLength() > 0) {
+ String vbt = DOMUtils.getText(nl.item(0));
+ if (EVB.equals(vbt)) {
+ return true;
+ }
+ }
+ }
+ } else if (c2 instanceof JAXBElement) {
+ JAXBElement jxb2= (JAXBElement) c2;
+ if (jxb2.getDeclaredType().equals(Funktion.class)) {
+ Funktion fkt = (Funktion) jxb2.getValue();
+ if (EVB.equals(fkt.getVertretungsbefugnis())) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // get list of legal persons
+ @SuppressWarnings("unchecked")
+ public List<NichtNatuerlichePersonTyp> getNichtNatuerlichePerson(List<String> ids) throws URClientException {
+ SucheUnternehmenNachIdsRequest request = new SucheUnternehmenNachIdsRequest();
+ ObjectFactory of = new ObjectFactory();
+ request.getKur().addAll(ids);
+ List<ResultRecord> results = searchByExample(of.createSucheUnternehmenNachIdsRequest(request), -1);
+ if (results.size() == 0) {
+ return new ArrayList<NichtNatuerlichePersonTyp>();
+ }
+ List<NichtNatuerlichePersonTyp> result = new ArrayList<NichtNatuerlichePersonTyp>();
+ for (ResultRecord rr : results) {
+ PersonenDatenTyp pdt = ((JAXBElement<PersonenDatenTyp>)rr.getAny().get(0)).getValue();
+
+ NichtNatuerlichePersonTyp nnpt = ((JAXBElement<NichtNatuerlichePersonTyp>) pdt.getPerson()).getValue();
+
+ // check if we have to filter out
+ if (this.allowedKeys == null || this.allowedKeys.size() == 0) {
+ result.add(nnpt);
+ } else {
+ boolean hasKey = false;
+ for (IdentificationType idt : nnpt.getIdentification()) {
+ if (this.allowedKeys.contains(idt.getType())) {
+ hasKey = true;
+ }
+ }
+ if (hasKey) {
+ result.add(nnpt);
+ }
+ }
+
+ }
+ return result;
+ }
+
+ // search by example
+ public List<ResultRecord> searchByExample(Object request, int maxResults) throws URClientException {
+ SearchByExampleType body = new SearchByExampleType();
+ body.setSearchRequestId(createURSearchId());
+ ResultCriteriaType rc = new ResultCriteriaType();
+ // set only value of max results if > 0
+ if (maxResults > 0) {
+ rc.setMaxRecords(BigInteger.valueOf(maxResults));
+ }
+ body.setResultCriteria(rc);
+ SearchCriteriaType sct = new SearchCriteriaType();
+ sct.getAny().add(request);
+ body.setSearchCriteria(sct);
+ SearchResponseType srt = this.urSuche.searchByExample(body);
+
+ // check number of records found
+// int numFound = 0;
+// if (srt.getResultInfo() != null) {
+// numFound = srt.getResultInfo().getReturnedRecords().intValue();
+// }
+ // check whether we have an error message
+ if (srt.getMessage() != null) {
+ if (srt.getMessage().getCode().intValue() != 2040) { // 2040 = no records found
+ throw new URClientException(srt.getMessage().getReason().get(0), srt.getMessage().getCode().intValue());
+ }
+ }
+ if (srt.getResultRecords() == null || srt.getResultRecords().getResultRecord() == null) {
+ return new ArrayList<ResultRecord>();
+ }
+ return srt.getResultRecords().getResultRecord();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void initialize() throws EgovUtilException {
+ URL url = URClient.class.getResource("/wsdl/ur/URSucheService.wsdl");
+ URSucheService urService = null;
+ String urURL = null;
+ urService = new URSucheService(url, new QName("urn:at:statistik:udb:ws", "URSucheService"));
+ urSuche = urService.getURSucheService();
+ if (config.isURTestEnvironment()) {
+ log.trace("Initializing UR test configuration.");
+ urURL = config.getURTestEnvironmentURL();
+ } else {
+ log.trace("Initializing UR productive configuration.");
+ urURL = config.getURProductionEnvironmentURL();
+ }
+
+ log.trace("UR connection URL: " + urURL);
+ BindingProvider bindingProvider = (BindingProvider) urSuche;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ if (this.logEnabled) {
+ handlerList.add(loggingHandler);
+ }
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getURPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (urURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for SZR client request.");
+ SSLContext sslContext = this.config.getURsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getURsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ }
+
+ private String createURSearchId() {
+ return RandomStringUtils.randomAlphanumeric(8) + "-" +
+ RandomStringUtils.randomAlphanumeric(4) + "-" + RandomStringUtils.randomAlphanumeric(4) + "-" +
+ RandomStringUtils.randomAlphanumeric(12);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/ur/URClientException.java b/src/main/java/at/gv/util/client/ur/URClientException.java
new file mode 100644
index 0000000..80b4cd6
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ur/URClientException.java
@@ -0,0 +1,33 @@
+package at.gv.util.client.ur;
+
+public class URClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ private int code = -1;
+
+ public URClientException(int code) {
+ super();
+ this.code = code;
+ }
+
+ public URClientException(String message, int code, Throwable cause) {
+ super(message, cause);
+ this.code = code;
+ }
+
+ public URClientException(String message, int code) {
+ super(message);
+ this.code = code;
+ }
+
+ public URClientException(int code, Throwable cause) {
+ super(cause);
+ this.code = code;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/ur_V2/URClient.java b/src/main/java/at/gv/util/client/ur_V2/URClient.java
new file mode 100644
index 0000000..e7766e0
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ur_V2/URClient.java
@@ -0,0 +1,442 @@
+package at.gv.util.client.ur_V2;
+
+import java.math.BigInteger;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.xsd.ur_V2.xmlsw.ExtraResultCriteria;
+import at.gv.util.xsd.ur_V2.xmlsw.ResultCriteriaType;
+import at.gv.util.xsd.ur_V2.xmlsw.ResultRecord;
+import at.gv.util.xsd.ur_V2.xmlsw.SearchByExampleType;
+import at.gv.util.xsd.ur_V2.xmlsw.SearchCriteriaType;
+import at.gv.util.xsd.ur_V2.xmlsw.SearchResponseType;
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.szr.SZRSOAPHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.ur_V2.URSuche;
+import at.gv.util.wsdl.ur_V2.URSucheService;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+import at.gv.util.xsd.ur_V2.pd.IdentificationType;
+import at.gv.util.xsd.ur_V2.pd.NichtNatuerlichePersonTyp;
+import at.gv.util.xsd.ur_V2.pd.PersonenDatenTyp;
+import at.gv.util.xsd.ur_V2.pd.PersonenDatenTyp.Zusatzdaten;
+import at.gv.util.xsd.ur_V2.pd.PersonenDatenZusatzdatenTyp;
+import at.gv.util.xsd.ur_V2.pd.ZusatzdatenPersonenTyp;
+import at.gv.util.xsd.ur_V2.search.BestandszeitraumVollzug;
+import at.gv.util.xsd.ur_V2.search.FunktionVollzug;
+import at.gv.util.xsd.ur_V2.search.SucheUnternehmenNachBpkRequest;
+import at.gv.util.xsd.ur_V2.search.SucheUnternehmenRequest;
+import at.gv.util.xsd.ur_V2.search.SucheUnternehmensdaten;
+import at.gv.util.xsd.ur_V2.simpletypes.EvbStatusTyp;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class URClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ private Logger log = LoggerFactory.getLogger(URClient.class);
+ private boolean logEnabled = true;
+ private boolean evbCheck = true;
+ private URSuche urSuche = null;
+
+ private final static String version = "V2.0";
+ private List<String> allowedKeys = null;
+ private HashSet<String> allowedERsBKeys = null;
+
+ public URClient(EgovUtilConfiguration config, List<String> allowedKeys, HashSet<String> ersbkeys, boolean evbCheck, boolean logEnabled) throws EgovUtilException {
+ MiscUtil.assertNotNull(config, "config");
+ this.config = config;
+ this.allowedKeys = allowedKeys;
+ this.logEnabled = logEnabled;
+ this.evbCheck = evbCheck;
+ this.allowedERsBKeys = ersbkeys;
+
+ initialize();
+ }
+
+ public List<URSearchResult> searchByBpk(String vzbpk) throws URClientException {
+ SucheUnternehmenNachBpkRequest request = new SucheUnternehmenNachBpkRequest();
+ request.setVersion(version);
+ request.setBpkWTUREncoded(vzbpk);
+
+ request.setNurAktive(true);
+
+ SearchCriteriaType sct = new SearchCriteriaType();
+ sct.setSucheUnternehmenNachBpkRequest(request);
+
+ List<ResultRecord> results = searchByExample(sct, -1);
+ return getURSearchResult(results);
+ }
+
+ public List<NichtNatuerlichePersonTyp> searchByRegisterNumber(String number, String type, int maxResults) throws URClientException {
+ SucheUnternehmenRequest request = new SucheUnternehmenRequest();
+ request.setVersion(version);
+ SucheUnternehmensdaten sud = new SucheUnternehmensdaten();
+ sud.setId(number);
+ sud.setIdArt(type);
+ request.setUnternehmensdaten(sud);
+
+ SearchCriteriaType sct = new SearchCriteriaType();
+ sct.setSucheUnternehmenRequest(request);
+
+ List<ResultRecord> results = searchByExample(sct, maxResults);
+ return getNichtNatuerlichePersonen(results);
+ }
+
+ public List<NichtNatuerlichePersonTyp> searchByName(String name, String plz, int maxResults) throws URClientException {
+ SucheUnternehmenRequest request = new SucheUnternehmenRequest();
+ request.setVersion(version);
+ SucheUnternehmensdaten sud = new SucheUnternehmensdaten();
+ sud.setUntName(name);
+ if (MiscUtil.isNotEmpty(plz)) {
+ sud.setPlz(plz);
+ }
+ request.setUnternehmensdaten(sud);
+
+ SearchCriteriaType sct = new SearchCriteriaType();
+ sct.setSucheUnternehmenRequest(request);
+
+ List<ResultRecord> results = searchByExample(sct, maxResults);
+ return getNichtNatuerlichePersonen(results);
+ }
+
+ private List<URSearchResult> getURSearchResult(List<ResultRecord> records) throws URClientException {
+
+ if (records == null || records.size() == 0) {
+ return new ArrayList<URSearchResult>();
+ }
+
+ List<URSearchResult> result = new ArrayList<URSearchResult>();
+
+ log.debug("UR SOAP response with " + records.size() + "records");
+
+ for (ResultRecord rr : records) {
+ PersonenDatenTyp pdt = rr.getPersonenDaten();
+ NichtNatuerlichePersonTyp nnpt = pdt.getNichtNatuerlichePerson();
+ Zusatzdaten zsd = pdt.getZusatzdaten();
+
+ //check validity era
+ boolean check_valera = isInValidityEra(zsd);
+
+ //check allowed keys
+ boolean check_allowedkeys = hasAllowedKeys(nnpt.getIdentification());
+
+ //ERsB function codes
+ List<String> ersbcode = hasAllowedEVBCode(zsd);
+
+ //check EVB
+ boolean check_EVB = isEVB(zsd);
+
+ if (check_valera && check_allowedkeys && (check_EVB || !ersbcode.isEmpty())) {
+ result.add(new URSearchResult(nnpt, ersbcode, check_EVB));
+ }
+ else {
+ log.debug("No validity for " + nnpt.getRest().get(0).getValue()
+ + "(Validity era=" + String.valueOf(check_valera)
+ + " Allowed Keys="+ String.valueOf(check_allowedkeys)
+ + " EVB check=" + String.valueOf(check_EVB) +")");
+ }
+ }
+
+ return result;
+ }
+
+ private List<NichtNatuerlichePersonTyp> getNichtNatuerlichePersonen(List<ResultRecord> records) throws URClientException {
+
+ if (records == null || records.size() == 0) {
+ return new ArrayList<NichtNatuerlichePersonTyp>();
+ }
+
+ List<NichtNatuerlichePersonTyp> result = new ArrayList<NichtNatuerlichePersonTyp>();
+
+ log.debug("UR SOAP response with " + records.size() + "records");
+
+ for (ResultRecord rr : records) {
+ PersonenDatenTyp pdt = rr.getPersonenDaten();
+ NichtNatuerlichePersonTyp nnpt = pdt.getNichtNatuerlichePerson();
+ Zusatzdaten zsd = pdt.getZusatzdaten();
+
+ //check validity era
+ boolean check_valera = isInValidityEra(zsd);
+
+ //check allowed keys
+ boolean check_allowedkeys = hasAllowedKeys(nnpt.getIdentification());
+
+ //check EVB
+ boolean check_EVB = isEVB(zsd);
+
+ if (check_valera && check_allowedkeys && check_EVB) {
+ result.add(nnpt);
+ }
+ else {
+ log.debug("No validity for " + nnpt.getRest().get(0).getValue()
+ + "(Validity era=" + String.valueOf(check_valera)
+ + " Allowed Keys="+ String.valueOf(check_allowedkeys)
+ + " EVB check=" + String.valueOf(check_EVB) +")");
+ }
+ }
+
+ return result;
+ }
+
+ private List<String> hasAllowedEVBCode(Zusatzdaten zsd) {
+
+ Set<String> set = new HashSet<String>();
+
+ if ((this.allowedERsBKeys == null || this.allowedERsBKeys.size() == 0)) {
+ return new ArrayList<String>();
+
+ } else {
+
+ if(zsd != null) {
+ List<PersonenDatenZusatzdatenTyp> pd = zsd.getPersonenDaten();
+ for (PersonenDatenZusatzdatenTyp pdzd : pd) {
+
+ ZusatzdatenPersonenTyp zusatzdaten = pdzd.getZusatzdaten();
+ if (zusatzdaten != null) {
+
+ List<FunktionVollzug> function = zusatzdaten.getFunktion();
+ for (FunktionVollzug funct : function) {
+
+ if (this.allowedERsBKeys.contains(String.valueOf(funct.getFktName())))
+
+ set.add(String.valueOf(funct.getFktName()));
+ }
+ }
+ }
+ }
+
+ return new ArrayList<String>(set);
+ }
+ }
+
+ //check if corporation is in validity era
+ //TODO: check correctness of TRUE if no validity era is defined!!!
+ private boolean isInValidityEra(Zusatzdaten zsd) throws URClientException {
+ if(zsd != null) {
+ List<BestandszeitraumVollzug> validityera = zsd.getBestandszeitraum();
+ for ( BestandszeitraumVollzug valera_el : validityera) {
+ try {
+ GregorianCalendar now = new GregorianCalendar();
+ XMLGregorianCalendar xmldate = DatatypeFactory.newInstance().newXMLGregorianCalendar(now);
+
+ if ( !(valera_el.getBestandVon().compare(xmldate) == DatatypeConstants.LESSER
+ && valera_el.getBestandBis().compare(xmldate) == DatatypeConstants.GREATER) ) {
+
+ log.debug("Corporation is not within the validity period");
+ return false;
+ }
+
+ } catch (DatatypeConfigurationException e) {
+ log.warn("Internal error during date conversion", e);
+ }
+ }
+ }
+ return true;
+ }
+
+ // check if person is einzelvertretungsbefugt
+ private boolean isEVB(Zusatzdaten zsd) {
+ if (!this.evbCheck) {
+ return true;
+ }
+ else {
+ if(zsd != null) {
+ List<PersonenDatenZusatzdatenTyp> pd = zsd.getPersonenDaten();
+ for (PersonenDatenZusatzdatenTyp pdzd : pd) {
+
+ if (pdzd.getZusatzdaten() != null) {
+ EvbStatusTyp evbstatus = pdzd.getZusatzdaten().getEvbStatus();
+ if (evbstatus!=null && evbstatus.equals(EvbStatusTyp.J)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ //check allowedKeys
+ private boolean hasAllowedKeys(List<IdentificationType> list) throws URClientException {
+
+ if ((this.allowedKeys == null || this.allowedKeys.size() == 0)) {
+ return true;
+
+ } else {
+ for (IdentificationType idt : list) {
+ if (this.allowedKeys.contains(idt.getType())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ // search by example
+ public List<ResultRecord> searchByExample(SearchCriteriaType sct, int maxResults) throws URClientException {
+
+
+ SearchByExampleType body = new SearchByExampleType();
+
+ body.setSearchRequestId(createURSearchId());
+ ResultCriteriaType rc = new ResultCriteriaType();
+
+ log.debug("UR SOAP request with Id " + body.getSearchRequestId());
+
+ // set only value of max results if > 0
+ if (maxResults > 0) {
+ rc.setMaxRecords(BigInteger.valueOf(maxResults));
+ }
+
+ // set ExtraResultCriterias
+ ExtraResultCriteria ec = new ExtraResultCriteria();
+ ec.setErsbAttribute(true);
+ rc.setExtraResultCriteria(ec);
+ body.setResultCriteria(rc);
+
+ body.setSearchCriteria(sct);
+
+ SearchResponseType srt = this.urSuche.searchByExample(body);
+
+ // check number of records found
+// int numFound = 0;
+// if (srt.getResultInfo() != null) {
+// numFound = srt.getResultInfo().getReturnedRecords().intValue();
+// }
+ // check whether we have an error message
+ if (srt.getMessage() != null) {
+ if (srt.getMessage().getCode().intValue() != 2040) { // 2040 = no records found
+ throw new URClientException(srt.getMessage().getReason().get(0), srt.getMessage().getCode().intValue());
+ }
+ }
+
+ if (srt.getResultRecords() == null || srt.getResultRecords().getResultRecord() == null) {
+ return new ArrayList<ResultRecord>();
+ }
+ return srt.getResultRecords().getResultRecord();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void initialize() throws EgovUtilException {
+ URL url = URClient.class.getResource("/wsdl/ur_V2/URSucheService.wsdl");
+ URSucheService urService = null;
+ String urURL = null;
+ urService = new URSucheService(url, new QName("urn:at:statistik:ur:ws", "URSucheService"));
+ urSuche = urService.getURSucheService();
+
+ if (config.isURTestEnvironment()) {
+ log.trace("Initializing UR test configuration.");
+ urURL = config.getURTestEnvironmentURL();
+ } else {
+ log.trace("Initializing UR productive configuration.");
+ urURL = config.getURProductionEnvironmentURL();
+ }
+
+ log.trace("UR connection URL: " + urURL);
+ BindingProvider bindingProvider = (BindingProvider) urSuche;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+
+ LoggingHandler loggingHandler = new LoggingHandler();
+ if (this.logEnabled) {
+ handlerList.add(loggingHandler);
+ }
+
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getURPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ //check for ssl
+ if (urURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for SZR client request.");
+ SSLContext sslContext = this.config.getURsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getURsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ }
+
+ private String createURSearchId() {
+ return RandomStringUtils.randomAlphanumeric(8) + "-" +
+ RandomStringUtils.randomAlphanumeric(4) + "-" + RandomStringUtils.randomAlphanumeric(4) + "-" +
+ RandomStringUtils.randomAlphanumeric(12);
+ }
+
+ public class URSearchResult {
+ private NichtNatuerlichePersonTyp result;
+ private List<String> ersbcode;
+ private boolean evb;
+
+ public URSearchResult() {
+ this.result = null;
+ this.ersbcode = null;
+ this.evb = false;
+ }
+
+ public URSearchResult(NichtNatuerlichePersonTyp result, List<String> ersb_code, boolean isevb) {
+ this.result = result;
+ this.ersbcode = ersb_code;
+ this.evb = isevb;
+ }
+
+ public NichtNatuerlichePersonTyp getResult() {
+ return result;
+ }
+
+ public List<String> getErsbcode() {
+ return ersbcode;
+ }
+
+ public boolean isEVB() {
+ return evb;
+ }
+ }
+
+
+}
+
diff --git a/src/main/java/at/gv/util/client/ur_V2/URClientException.java b/src/main/java/at/gv/util/client/ur_V2/URClientException.java
new file mode 100644
index 0000000..a21f1a8
--- /dev/null
+++ b/src/main/java/at/gv/util/client/ur_V2/URClientException.java
@@ -0,0 +1,33 @@
+package at.gv.util.client.ur_V2;
+
+public class URClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ private int code = -1;
+
+ public URClientException(int code) {
+ super();
+ this.code = code;
+ }
+
+ public URClientException(String message, int code, Throwable cause) {
+ super(message, cause);
+ this.code = code;
+ }
+
+ public URClientException(String message, int code) {
+ super(message);
+ this.code = code;
+ }
+
+ public URClientException(int code, Throwable cause) {
+ super(cause);
+ this.code = code;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java b/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java
new file mode 100644
index 0000000..74ed951
--- /dev/null
+++ b/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java
@@ -0,0 +1,140 @@
+package at.gv.util.client.zuserech;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.moaid.MOAIDClient;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.szr.SZRException;
+import at.gv.util.wsdl.zuserech.ClearingPortType;
+import at.gv.util.wsdl.zuserech.ClearingService;
+import at.gv.util.wsdl.zuserech.ValidateTokenPortType;
+import at.gv.util.wsdl.zuserech.ValidateTokenService;
+import at.gv.util.xsd.zuserech.ClearingRequestType;
+import at.gv.util.xsd.zuserech.ClearingResponseType;
+import at.gv.util.xsd.zuserech.ValidateTokenRequest;
+import at.gv.util.xsd.zuserech.ValidateTokenResponse;
+
+import com.sun.xml.ws.developer.JAXWSProperties;
+
+public class ZuseRechClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ Logger log = LoggerFactory.getLogger(ZuseRechClient.class);
+
+ public ZuseRechClient() {}
+
+ public ZuseRechClient(EgovUtilConfiguration config) {
+ if (config == null) {
+ throw new NullPointerException("Parameter config must not be null.");
+ }
+ this.config = config;
+
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public ClearingResponseType sendClearingRequest(ClearingRequestType csr, String csrServiceURL) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(csr, "csr");
+ MiscUtil.assertNotNull(csrServiceURL, "csrServiceURL");
+
+ URL url = MOAIDClient.class.getResource("/wsdl/zkopf/zsuerech.wsdl");
+ ClearingService service = new ClearingService(url, new QName("http://reference.e-government.gv.at/namespaces/zustellung/rech/wsdl", "ClearingService"));
+ ClearingPortType port = service.getClearingPort();
+
+ log.debug("Clearing service connection URL: " + csrServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, csrServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (csrServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for clearing service client request.");
+ SSLContext sslContext = config.getClearingsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getClearingsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ return port.clearingOperation(csr);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public ValidateTokenResponse sendValidateTokenRequest(ValidateTokenRequest vtr, String vtrServiceURL) throws SZRException, EgovUtilException {
+ MiscUtil.assertNotNull(vtr, "vtr");
+ MiscUtil.assertNotNull(vtrServiceURL, "csrServiceURL");
+
+ URL url = MOAIDClient.class.getResource("/wsdl/zkopf/zsuerech.wsdl");
+ ValidateTokenService service = new ValidateTokenService(url, new QName("http://reference.e-government.gv.at/namespaces/zustellung/rech/wsdl", "ValidateTokenService"));
+ ValidateTokenPortType port = service.getValidateTokenPort();
+
+ log.debug("Validate token service connection URL: " + vtrServiceURL);
+ BindingProvider bindingProvider = (BindingProvider) port;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(
+ BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vtrServiceURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ handlerList.add(loggingHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ // check for ssl
+ if (vtrServiceURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for clearing service client request.");
+ SSLContext sslContext = config.getClearingsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+ }
+ requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getClearingsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier());
+ }
+ }
+ return port.validateTokenOperation(vtr);
+ }
+
+
+}
diff --git a/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java b/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java
new file mode 100644
index 0000000..5cdcf33
--- /dev/null
+++ b/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java
@@ -0,0 +1,23 @@
+package at.gv.util.client.zuserech;
+
+public class ZuseRechClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ public ZuseRechClientException() {
+ super();
+ }
+
+ public ZuseRechClientException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ZuseRechClientException(String message) {
+ super(message);
+ }
+
+ public ZuseRechClientException(Throwable cause) {
+ super(cause);
+ }
+
+}