src/main/java/org/edgegallery/appstore/infrastructure/util/AppUtil.java
public byte[] downloadImageFromFileSystem(String token, String url) {
        LOGGER.info("download images status from fileSystem, url: {}", url);
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(600000);// 设置超时
        requestFactory.setReadTimeout(600000);
        RestTemplate restObject = new RestTemplate(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setConnection("close");
        headers.set("access_token", token);
        byte[] result = null;
        ResponseEntity<byte[]> response;
        try {
            response = restObject.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), byte[].class);
            if (response.getStatusCode() != HttpStatus.OK) {
                LOGGER.error("download file error, response is {}", response.getBody());
                throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
            }
            result = response.getBody();
            if (result == null) {
                LOGGER.error("download file error, response is null");
                throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
            }

        } catch (RestClientException e) {
            LOGGER.error("Failed to get image status which imageId exception {}", e.getMessage());
            throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
        }

        return result;
    }
/**
     * download image by imageUrl from fileSystem.
     *
     * @param url image url
     * @param token token
     * @return boolean
     */
download image by imageUrl from fileSystem.
@param url image url
@param token token
@return boolean
download image by imageUrl from fileSystem . @param url image url @param token token @return boolean
public byte[] downloadImageFromFileSystem(String token, String url) {
        LOGGER.info("download images status from fileSystem, url: {}", url);
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(600000);
        requestFactory.setReadTimeout(600000);
        RestTemplate restObject = new RestTemplate(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setConnection("close");
        headers.set("access_token", token);
        byte[] result = null;
        ResponseEntity<byte[]> response;
        try {
            response = restObject.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), byte[].class);
            if (response.getStatusCode() != HttpStatus.OK) {
                LOGGER.error("download file error, response is {}", response.getBody());
                throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
            }
            result = response.getBody();
            if (result == null) {
                LOGGER.error("download file error, response is null");
                throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
            }
        } catch (RestClientException e) {
            LOGGER.error("Failed to get image status which imageId exception {}", e.getMessage());
            throw new AppException(DOWNLOAD_IMAGE_FAIL, ResponseConst.RET_DOWNLOAD_IMAGE_FAILED, url);
        }
        return result;
    }
public byte [ ] downloadImageFromFileSystem ( String token , String url ) { LOGGER . info ( "download images status from fileSystem, url: {}" , url ) ; SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory ( ) ; requestFactory . setConnectTimeout ( 600000 ) ; requestFactory . setReadTimeout ( 600000 ) ; RestTemplate restObject = new RestTemplate ( requestFactory ) ; HttpHeaders headers = new HttpHeaders ( ) ; headers . setContentType ( MediaType . APPLICATION_JSON ) ; headers . setConnection ( "close" ) ; headers . set ( "access_token" , token ) ; byte [ ] result = null ; ResponseEntity < byte [ ] > response ; try { response = restObject . exchange ( url , HttpMethod . GET , new HttpEntity < > ( headers ) , byte [ ] . class ) ; if ( response . getStatusCode ( ) != HttpStatus . OK ) { LOGGER . error ( "download file error, response is {}" , response . getBody ( ) ) ; throw new AppException ( DOWNLOAD_IMAGE_FAIL , ResponseConst . RET_DOWNLOAD_IMAGE_FAILED , url ) ; } result = response . getBody ( ) ; if ( result == null ) { LOGGER . error ( "download file error, response is null" ) ; throw new AppException ( DOWNLOAD_IMAGE_FAIL , ResponseConst . RET_DOWNLOAD_IMAGE_FAILED , url ) ; } } catch ( RestClientException e ) { LOGGER . error ( "Failed to get image status which imageId exception {}" , e . getMessage ( ) ) ; throw new AppException ( DOWNLOAD_IMAGE_FAIL , ResponseConst . RET_DOWNLOAD_IMAGE_FAILED , url ) ; } return result ; }
download image by imageUrl from fileSystem.
download image by imageUrl from fileSystem .
// 设置超时