summaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/util/client/omsp
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2013-12-20 12:35:28 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2013-12-20 12:35:28 +0100
commitdefceef8afef538555c13d33e344a89a828a3d97 (patch)
tree24b44f970f161d5b139dde501ca0f5d883f9fdea /src/main/java/at/gv/util/client/omsp
downloadegovutils-defceef8afef538555c13d33e344a89a828a3d97.tar.gz
egovutils-defceef8afef538555c13d33e344a89a828a3d97.tar.bz2
egovutils-defceef8afef538555c13d33e344a89a828a3d97.zip
inital
Diffstat (limited to 'src/main/java/at/gv/util/client/omsp')
-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
3 files changed, 83 insertions, 0 deletions
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);
+
+}