rsanchez
2014-09-29 464f9fc6047ff994728acf69f6f0d3971984b492
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -11,6 +11,7 @@
1111 import net.curisit.securis.beans.LicenseBean;
1212 import net.curisit.securis.beans.RequestBean;
1313 import net.curisit.securis.beans.SignedLicenseBean;
14
+import net.curisit.securis.beans.StatusBean;
1415 import net.curisit.securis.utils.JsonUtils;
1516 import net.curisit.securis.utils.Params;
1617 import net.curisit.securis.utils.SignatureHelper;
....@@ -86,37 +87,48 @@
8687 * @return The license bean returned by the server
8788 * @throws SeCurisException
8889 */
89
- public LicenseBean requestLicense() throws SeCurisException {
90
+ public SignedLicenseBean requestLicense() throws SeCurisException {
9091 RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
9192
92
- LicenseBean lic = requestLicenseToServer(req);
93
+ SignedLicenseBean lic = requestLicenseToServer(req);
9394 return lic;
9495 }
9596
96
- /**
97
- * Generate a license file using a {@link LicenseBean}
98
- *
99
- * @param license
100
- * @param file
101
- * @throws SeCurisException
102
- */
103
- public void save(LicenseBean license, File file) throws SeCurisException {
104
- SignedLicenseBean signedLic = new SignedLicenseBean(license);
105
- byte[] json;
106
- try {
107
- json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
108
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
109
- } catch (UnsupportedEncodingException e) {
110
- LOG.error("Error creating json doc from license: " + license, e);
111
- throw new SeCurisException("Error creating json doc from license: " + license, e);
112
- } catch (IOException e) {
113
- LOG.error("Error creating license file: " + file, e);
114
- throw new SeCurisException("Error creating json doc from license: " + license, e);
115
- }
97
+ /**
98
+ * Generate a license file using a {@link LicenseBean}
99
+ *
100
+ * @param license
101
+ * @param file
102
+ * @throws SeCurisException
103
+ */
104
+ public void save(LicenseBean license, File file) throws SeCurisException {
105
+ SignedLicenseBean signedLic = new SignedLicenseBean(license);
106
+ save(signedLic, file);
107
+ }
116108
117
- LOG.debug("License saved in {}", file);
109
+ /**
110
+ * Generate a license file using a {@link LicenseBean}
111
+ *
112
+ * @param license
113
+ * @param file
114
+ * @throws SeCurisException
115
+ */
116
+ public void save(SignedLicenseBean signedLic, File file) throws SeCurisException {
117
+ byte[] json;
118
+ try {
119
+ json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
120
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
121
+ } catch (UnsupportedEncodingException e) {
122
+ LOG.error("Error creating json doc from license: " + signedLic, e);
123
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
124
+ } catch (IOException e) {
125
+ LOG.error("Error creating license file: " + file, e);
126
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
127
+ }
118128
119
- }
129
+ LOG.debug("License saved in {}", file);
130
+
131
+ }
120132
121133 private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
122134 SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
....@@ -157,8 +169,8 @@
157169 }
158170
159171 public void testServer() throws SeCurisException {
160
- String pingMsg = ConnectionManager.getInstance().executeGet(Command.RENEW_LIC, String.class);
161
- if (!PING_MESSAGE.equals(pingMsg)) {
172
+ StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
173
+ if (!PING_MESSAGE.equals(status.getMessage())) {
162174 throw new SeCurisException("SeCuris Server is not running in given URL");
163175 }
164176 }