1 package com.samsung.dsm.rest.alive;
3 import org.apache.log4j.Logger;
4 import org.springframework.http.ResponseEntity;
5 import org.springframework.web.client.HttpClientErrorException;
6 import org.springframework.web.client.ResourceAccessException;
7 import org.springframework.web.client.RestTemplate;
10 import java.net.URISyntaxException;
12 import static java.lang.String.format;
15 public class AliveApiSenderImpl implements AliveApiSender {
17 private static final Logger LOG = Logger.getLogger(AliveApiSenderImpl.class);
19 private RestTemplate restTemplate;
23 private String password;
26 public AliveApiSenderImpl(String host, String password) {
28 this.password = password;
29 this.restTemplate = new RestTemplate();
31 LOG.debug("Server host: " + host);
35 public boolean alive(String login) throws AliveApiSenderError {
37 String path = "%s/restapi/alive/devices/%s/%s";
38 String stringURI = format(path, host, login, password);
39 LOG.debug("Alive Api Sender: " + format(path, host, login, "<hidden>"));
41 ResponseEntity<Boolean> result = restTemplate.getForEntity(new URI(stringURI), Boolean.class);
43 return result.getBody();
45 } catch (URISyntaxException | HttpClientErrorException | ResourceAccessException e) {
46 throw new AliveApiSenderError("Error occurred on Alive Api sender", e);