From 4be65eae04c0ed497bf404d43f9a11a4993a239d Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 29 Sep 2014 15:25:59 +0000
Subject: [PATCH] #2021 fix - Added HTTP client to connect to SeCuris server

---
 src/main/java/net/curisit/securis/LicenseManager.java |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/main/java/net/curisit/securis/LicenseManager.java b/src/main/java/net/curisit/securis/LicenseManager.java
index c754def..ecec7a5 100644
--- a/src/main/java/net/curisit/securis/LicenseManager.java
+++ b/src/main/java/net/curisit/securis/LicenseManager.java
@@ -7,6 +7,7 @@
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 
+import net.curisit.securis.ConnectionManager.Command;
 import net.curisit.securis.beans.LicenseBean;
 import net.curisit.securis.beans.RequestBean;
 import net.curisit.securis.beans.SignedLicenseBean;
@@ -29,10 +30,9 @@
 
 	private static LicenseManager singleton = new LicenseManager();
 
-	String serverUrl = null;
-
+	public static final String PING_MESSAGE = "SeCuris API OK";	
+	
 	private LicenseManager() {
-		serverUrl = Params.get(Params.KEYS.LICENSE_SERVER_URL);
 	}
 
 	public static LicenseManager getInstance() {
@@ -88,9 +88,7 @@
 	 */
 	public LicenseBean requestLicense() throws SeCurisException {
 		RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
-		if (true) {
-			throw new SeCurisException("Action not implemented yet");
-		}
+
 		LicenseBean lic = requestLicenseToServer(req);
 		return lic;
 	}
@@ -120,9 +118,10 @@
 
 	}
 
-	private LicenseBean requestLicenseToServer(RequestBean req) {
-		// TODO Prepare call to server sending the request bean to get a valid license
-		return null;
+	private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
+	    SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
+ 
+ 		return lic;
 	}
 
 	/**
@@ -149,13 +148,19 @@
 	 * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
 	 * @throws SeCurisException
 	 */
-	public LicenseBean renew(File licenseFile) throws SeCurisException {
+	public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
 		LicenseBean lic = validateLicense(licenseFile);
-		if (true) {
-			throw new SeCurisException("Action not implemented yet");
-		}
-		// TODO: Send the current LicenseBean to server to check if a new one is prepared.
-		return lic;
+
+        SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
+
+		return newLic;
 	}
 
+    public void testServer() throws SeCurisException {
+        String pingMsg = ConnectionManager.getInstance().executeGet(Command.RENEW_LIC, String.class);
+        if (!PING_MESSAGE.equals(pingMsg)) {
+            throw new SeCurisException("SeCuris Server is not running in given URL");
+        }
+    }
+
 }

--
Gitblit v1.3.2