Merge pull request #5157 from thingsboard/develop/3.3.1
Refactoring: Introduced Edge License service.
This commit is contained in:
		
						commit
						f47985ccc6
					
				@ -27,6 +27,7 @@ import org.springframework.http.MediaType;
 | 
			
		||||
import org.springframework.security.core.Authentication;
 | 
			
		||||
import org.springframework.security.core.context.SecurityContextHolder;
 | 
			
		||||
import org.springframework.web.bind.annotation.ExceptionHandler;
 | 
			
		||||
import org.thingsboard.server.cluster.TbClusterService;
 | 
			
		||||
import org.thingsboard.server.common.data.Customer;
 | 
			
		||||
import org.thingsboard.server.common.data.Dashboard;
 | 
			
		||||
import org.thingsboard.server.common.data.DashboardInfo;
 | 
			
		||||
@ -122,12 +123,12 @@ import org.thingsboard.server.queue.provider.TbQueueProducerProvider;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.action.RuleEngineEntityActionService;
 | 
			
		||||
import org.thingsboard.server.service.component.ComponentDiscoveryService;
 | 
			
		||||
import org.thingsboard.server.service.edge.EdgeLicenseService;
 | 
			
		||||
import org.thingsboard.server.service.edge.EdgeNotificationService;
 | 
			
		||||
import org.thingsboard.server.service.edge.rpc.EdgeRpcService;
 | 
			
		||||
import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository;
 | 
			
		||||
import org.thingsboard.server.service.ota.OtaPackageStateService;
 | 
			
		||||
import org.thingsboard.server.service.profile.TbDeviceProfileCache;
 | 
			
		||||
import org.thingsboard.server.cluster.TbClusterService;
 | 
			
		||||
import org.thingsboard.server.service.resource.TbResourceService;
 | 
			
		||||
import org.thingsboard.server.service.security.model.SecurityUser;
 | 
			
		||||
import org.thingsboard.server.service.security.permission.AccessControlService;
 | 
			
		||||
@ -274,6 +275,9 @@ public abstract class BaseController {
 | 
			
		||||
    @Autowired(required = false)
 | 
			
		||||
    protected EdgeRpcService edgeGrpcService;
 | 
			
		||||
 | 
			
		||||
    @Autowired(required = false)
 | 
			
		||||
    protected EdgeLicenseService edgeLicenseService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    protected RuleEngineEntityActionService ruleEngineEntityActionService;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -572,7 +572,7 @@ public class EdgeController extends BaseController {
 | 
			
		||||
    public ResponseEntity<JsonNode> checkInstance(@RequestBody JsonNode request) throws ThingsboardException {
 | 
			
		||||
        log.debug("Checking instance [{}]", request);
 | 
			
		||||
        try {
 | 
			
		||||
            return edgeService.checkInstance(request);
 | 
			
		||||
            return edgeLicenseService.checkInstance(request);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error("Error occurred: [{}]", e.getMessage(), e);
 | 
			
		||||
            throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);
 | 
			
		||||
@ -585,7 +585,7 @@ public class EdgeController extends BaseController {
 | 
			
		||||
                                                     @RequestParam String releaseDate) throws ThingsboardException {
 | 
			
		||||
        log.debug("Activating instance [{}], [{}]", licenseSecret, releaseDate);
 | 
			
		||||
        try {
 | 
			
		||||
            return edgeService.activateInstance(licenseSecret, releaseDate);
 | 
			
		||||
            return edgeLicenseService.activateInstance(licenseSecret, releaseDate);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error("Error occurred: [{}]", e.getMessage(), e);
 | 
			
		||||
            throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,110 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright © 2016-2021 The Thingsboard Authors
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.service.edge;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.http.HttpHost;
 | 
			
		||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
 | 
			
		||||
import org.apache.http.impl.client.CloseableHttpClient;
 | 
			
		||||
import org.apache.http.impl.client.HttpClients;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 | 
			
		||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.web.client.RestTemplate;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.PostConstruct;
 | 
			
		||||
import java.net.InetSocketAddress;
 | 
			
		||||
import java.net.Proxy;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@TbCoreComponent
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class DefaultEdgeLicenseService implements EdgeLicenseService {
 | 
			
		||||
 | 
			
		||||
    private RestTemplate restTemplate;
 | 
			
		||||
 | 
			
		||||
    private static final String EDGE_LICENSE_SERVER_ENDPOINT = "https://license.thingsboard.io";
 | 
			
		||||
 | 
			
		||||
    @Value("${edges.enabled:false}")
 | 
			
		||||
    private boolean edgesEnabled;
 | 
			
		||||
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    public void init() {
 | 
			
		||||
        if (edgesEnabled) {
 | 
			
		||||
            initRestTemplate();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ResponseEntity<JsonNode> checkInstance(JsonNode request) {
 | 
			
		||||
        return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ResponseEntity<JsonNode> activateInstance(String edgeLicenseSecret, String releaseDate) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("licenseSecret", edgeLicenseSecret);
 | 
			
		||||
        params.put("releaseDate", releaseDate);
 | 
			
		||||
        return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initRestTemplate() {
 | 
			
		||||
        boolean jdkHttpClientEnabled = isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true");
 | 
			
		||||
        boolean systemProxyEnabled = isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true");
 | 
			
		||||
        boolean proxyEnabled = isNotEmpty(System.getProperty("tb.proxy.host")) && isNotEmpty(System.getProperty("tb.proxy.port"));
 | 
			
		||||
        if (jdkHttpClientEnabled) {
 | 
			
		||||
            log.warn("Going to use plain JDK Http Client!");
 | 
			
		||||
            SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
 | 
			
		||||
            if (proxyEnabled) {
 | 
			
		||||
                log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port"));
 | 
			
		||||
                factory.setProxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")))));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory());
 | 
			
		||||
        } else {
 | 
			
		||||
            CloseableHttpClient httpClient;
 | 
			
		||||
            HttpComponentsClientHttpRequestFactory requestFactory;
 | 
			
		||||
            if (systemProxyEnabled) {
 | 
			
		||||
                log.warn("Going to use System Proxy Server!");
 | 
			
		||||
                httpClient = HttpClients.createSystem();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            } else if (proxyEnabled) {
 | 
			
		||||
                log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port"));
 | 
			
		||||
                httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).setProxy(new HttpHost(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")), "https")).build();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            } else {
 | 
			
		||||
                httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).build();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,26 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright © 2016-2021 The Thingsboard Authors
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.service.edge;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
 | 
			
		||||
public interface EdgeLicenseService {
 | 
			
		||||
 | 
			
		||||
    ResponseEntity<JsonNode> checkInstance(JsonNode request);
 | 
			
		||||
 | 
			
		||||
    ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate);
 | 
			
		||||
}
 | 
			
		||||
@ -85,11 +85,6 @@
 | 
			
		||||
            <artifactId>spring-boot-autoconfigure</artifactId>
 | 
			
		||||
            <scope>provided</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework</groupId>
 | 
			
		||||
            <artifactId>spring-web</artifactId>
 | 
			
		||||
            <scope>provided</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.datastax.oss</groupId>
 | 
			
		||||
            <artifactId>java-driver-core</artifactId>
 | 
			
		||||
 | 
			
		||||
@ -15,9 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.dao.edge;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.Edge;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.EdgeInfo;
 | 
			
		||||
@ -86,9 +84,5 @@ public interface EdgeService {
 | 
			
		||||
 | 
			
		||||
    PageData<EdgeId> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink);
 | 
			
		||||
 | 
			
		||||
    ResponseEntity<JsonNode> checkInstance(JsonNode request);
 | 
			
		||||
 | 
			
		||||
    ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate);
 | 
			
		||||
 | 
			
		||||
    String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,6 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.dao.edge;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import com.fasterxml.jackson.databind.ObjectMapper;
 | 
			
		||||
import com.fasterxml.jackson.databind.node.ArrayNode;
 | 
			
		||||
import com.fasterxml.jackson.databind.node.ObjectNode;
 | 
			
		||||
@ -24,23 +23,14 @@ import com.google.common.util.concurrent.Futures;
 | 
			
		||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
			
		||||
import com.google.common.util.concurrent.MoreExecutors;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.http.HttpHost;
 | 
			
		||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
 | 
			
		||||
import org.apache.http.impl.client.CloseableHttpClient;
 | 
			
		||||
import org.apache.http.impl.client.HttpClients;
 | 
			
		||||
import org.hibernate.exception.ConstraintViolationException;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.cache.Cache;
 | 
			
		||||
import org.springframework.cache.CacheManager;
 | 
			
		||||
import org.springframework.cache.annotation.CacheEvict;
 | 
			
		||||
import org.springframework.cache.annotation.Cacheable;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 | 
			
		||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
import org.springframework.web.client.RestTemplate;
 | 
			
		||||
import org.thingsboard.server.common.data.Customer;
 | 
			
		||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
@ -74,20 +64,14 @@ import org.thingsboard.server.dao.tenant.TenantDao;
 | 
			
		||||
import org.thingsboard.server.dao.user.UserService;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import javax.annotation.PostConstruct;
 | 
			
		||||
import java.net.InetSocketAddress;
 | 
			
		||||
import java.net.Proxy;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
 | 
			
		||||
import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE;
 | 
			
		||||
import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
 | 
			
		||||
@ -108,10 +92,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
 | 
			
		||||
 | 
			
		||||
    private static final int DEFAULT_PAGE_SIZE = 1000;
 | 
			
		||||
 | 
			
		||||
    private RestTemplate restTemplate;
 | 
			
		||||
 | 
			
		||||
    private static final String EDGE_LICENSE_SERVER_ENDPOINT = "https://license.thingsboard.io";
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private EdgeDao edgeDao;
 | 
			
		||||
 | 
			
		||||
@ -133,16 +113,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RelationService relationService;
 | 
			
		||||
 | 
			
		||||
    @Value("${edges.enabled:false}")
 | 
			
		||||
    private boolean edgesEnabled;
 | 
			
		||||
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    public void init() {
 | 
			
		||||
        if (edgesEnabled) {
 | 
			
		||||
            initRestTemplate();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Edge findEdgeById(TenantId tenantId, EdgeId edgeId) {
 | 
			
		||||
        log.trace("Executing findEdgeById [{}]", edgeId);
 | 
			
		||||
@ -544,19 +514,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
 | 
			
		||||
        return new PageData<>(edgeIds, pageData.getTotalPages(), pageData.getTotalElements(), pageData.hasNext());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ResponseEntity<JsonNode> checkInstance(JsonNode request) {
 | 
			
		||||
        return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ResponseEntity<JsonNode> activateInstance(String edgeLicenseSecret, String releaseDate) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("licenseSecret", edgeLicenseSecret);
 | 
			
		||||
        params.put("releaseDate", releaseDate);
 | 
			
		||||
        return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) {
 | 
			
		||||
        List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId);
 | 
			
		||||
@ -602,43 +559,4 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
 | 
			
		||||
        } while (pageData != null && pageData.hasNext());
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initRestTemplate() {
 | 
			
		||||
        boolean jdkHttpClientEnabled = isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true");
 | 
			
		||||
        boolean systemProxyEnabled = isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true");
 | 
			
		||||
        boolean proxyEnabled = isNotEmpty(System.getProperty("tb.proxy.host")) && isNotEmpty(System.getProperty("tb.proxy.port"));
 | 
			
		||||
        if (jdkHttpClientEnabled) {
 | 
			
		||||
            log.warn("Going to use plain JDK Http Client!");
 | 
			
		||||
            SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
 | 
			
		||||
            if (proxyEnabled) {
 | 
			
		||||
                log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port"));
 | 
			
		||||
                factory.setProxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")))));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory());
 | 
			
		||||
        } else {
 | 
			
		||||
            CloseableHttpClient httpClient;
 | 
			
		||||
            HttpComponentsClientHttpRequestFactory requestFactory;
 | 
			
		||||
            if (systemProxyEnabled) {
 | 
			
		||||
                log.warn("Going to use System Proxy Server!");
 | 
			
		||||
                httpClient = HttpClients.createSystem();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            } else if (proxyEnabled) {
 | 
			
		||||
                log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port"));
 | 
			
		||||
                httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).setProxy(new HttpHost(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")), "https")).build();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            } else {
 | 
			
		||||
                httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).build();
 | 
			
		||||
                requestFactory = new HttpComponentsClientHttpRequestFactory();
 | 
			
		||||
                requestFactory.setHttpClient(httpClient);
 | 
			
		||||
                this.restTemplate = new RestTemplate(requestFactory);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user