1 package com.srv4pos.server.api.server;
2
3 import com.srv4pos.server.api.infrastructure.HttpMethod;
4 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
5 import com.srv4pos.server.api.infrastructure.http.Transport;
6 import com.srv4pos.server.api.infrastructure.request.StringResponse;
7
8 import java.net.URL;
9 import java.util.Date;
10
11 import static com.srv4pos.server.api.infrastructure.EmptyConnectionWriter.EMPTY_CONNECTION_WRITER;
12 import static com.srv4pos.server.api.infrastructure.http.HttpHelper.CONTENT_TYPE_APPLICATION_JSON;
13 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
14
15
16
17
18
19
20 public class ServerService {
21 private URL url;
22 private Credentials credentials;
23 private Transport transport;
24
25
26
27
28
29
30
31
32 public ServerService(URL url, Credentials credentials, Transport transport) {
33 this.url = url;
34 this.credentials = credentials;
35 this.transport = transport;
36 }
37
38
39
40
41
42
43 public boolean jndi() {
44 StringResponse response = requestString("server/jndi", HttpMethod.GET, url, null, null, null,
45 EMPTY_CONNECTION_WRITER, CONTENT_TYPE_APPLICATION_JSON, transport);
46 return Boolean.valueOf(response.getContent());
47 }
48
49
50
51
52 public String getTimezone() {
53 StringResponse response = requestString("server/timezone", HttpMethod.GET, url, null, null, null,
54 EMPTY_CONNECTION_WRITER, CONTENT_TYPE_APPLICATION_JSON, transport);
55 return TimezoneInfo.fromJsonToTimezoneInfo(response.getContent()).getTimezone();
56 }
57
58
59
60
61 public Date getTime() {
62 StringResponse response = requestString("server/time", HttpMethod.GET, url, null, null, null,
63 EMPTY_CONNECTION_WRITER, CONTENT_TYPE_APPLICATION_JSON, transport);
64 return TimeInfo.fromJsonToTimeInfo(response.getContent()).getTime();
65 }
66 }