From defceef8afef538555c13d33e344a89a828a3d97 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 20 Dec 2013 12:35:28 +0100 Subject: inital --- .../java/at/gv/util/client/omsp/OMSPClient.java | 46 ++++++++++++++++++++++ .../gv/util/client/omsp/OMSPClientException.java | 23 +++++++++++ .../java/at/gv/util/client/omsp/OMSPStatus.java | 14 +++++++ 3 files changed, 83 insertions(+) create mode 100644 src/main/java/at/gv/util/client/omsp/OMSPClient.java create mode 100644 src/main/java/at/gv/util/client/omsp/OMSPClientException.java create mode 100644 src/main/java/at/gv/util/client/omsp/OMSPStatus.java (limited to 'src/main/java/at/gv/util/client/omsp') 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 ALLOWED_CODES = Arrays.asList(ACTIVE, REVOKED, UNKNOWN); + +} -- cgit v1.2.3