View Javadoc
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   * Setup server.
17   * User: Kirill
18   * Date: 25.07.13 11:14
19   */
20  public class ServerService {
21      private URL url;
22      private Credentials credentials;
23      private Transport transport;
24  
25      /**
26       * Constructs the service.
27       *
28       * @param url         of the server
29       * @param credentials to work with the server
30       * @param transport   to know the method to reach the server
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       * Is server jndi configured?
40       *
41       * @return true if yes
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       * @return server timezone abbreviation, such as UTC
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       * @return server time
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  }