Browse Source

Configure content type for update service

pull/8353/head
Andrii Shvaika 4 years ago
parent
commit
da6d3b6ca8
  1. 15
      application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java

15
application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java

@ -21,6 +21,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.thingsboard.common.util.ThingsBoardThreadFactory; import org.thingsboard.common.util.ThingsBoardThreadFactory;
@ -65,8 +68,8 @@ public class DefaultUpdateService implements UpdateService {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, ThingsBoardThreadFactory.forName("tb-update-service")); private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, ThingsBoardThreadFactory.forName("tb-update-service"));
private ScheduledFuture checkUpdatesFuture = null; private ScheduledFuture<?> checkUpdatesFuture = null;
private RestTemplate restClient = new RestTemplate(); private final RestTemplate restClient = new RestTemplate();
private UpdateMessage updateMessage; private UpdateMessage updateMessage;
@ -94,7 +97,7 @@ public class DefaultUpdateService implements UpdateService {
Path instanceIdPath = Paths.get(INSTANCE_ID_FILE); Path instanceIdPath = Paths.get(INSTANCE_ID_FILE);
if (instanceIdPath.toFile().exists()) { if (instanceIdPath.toFile().exists()) {
byte[] data = Files.readAllBytes(instanceIdPath); byte[] data = Files.readAllBytes(instanceIdPath);
if (data != null && data.length > 0) { if (data.length > 0) {
try { try {
result = UUID.fromString(new String(data)); result = UUID.fromString(new String(data));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -124,13 +127,15 @@ public class DefaultUpdateService implements UpdateService {
Runnable checkUpdatesRunnable = () -> { Runnable checkUpdatesRunnable = () -> {
try { try {
log.trace("Executing check update method for instanceId [{}], platform [{}] and version [{}]", instanceId, platform, version); log.trace("Executing check update method for instanceId [{}], platform [{}] and version [{}]", instanceId, platform, version);
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectNode request = new ObjectMapper().createObjectNode(); ObjectNode request = new ObjectMapper().createObjectNode();
request.put(PLATFORM_PARAM, platform); request.put(PLATFORM_PARAM, platform);
request.put(VERSION_PARAM, version); request.put(VERSION_PARAM, version);
request.put(INSTANCE_ID_PARAM, instanceId.toString()); request.put(INSTANCE_ID_PARAM, instanceId.toString());
UpdateMessage prevUpdateMessage = updateMessage; UpdateMessage prevUpdateMessage = updateMessage;
updateMessage = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v2/thingsboard/updates", request, UpdateMessage.class); updateMessage = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v2/thingsboard/updates", new HttpEntity<>(request.toString(), headers), UpdateMessage.class);
if (updateMessage.isUpdateAvailable() && !updateMessage.equals(prevUpdateMessage)) { if (updateMessage != null && updateMessage.isUpdateAvailable() && !updateMessage.equals(prevUpdateMessage)) {
notificationRuleProcessor.process(NewPlatformVersionTrigger.builder() notificationRuleProcessor.process(NewPlatformVersionTrigger.builder()
.updateInfo(updateMessage) .updateInfo(updateMessage)
.build()); .build());

Loading…
Cancel
Save