0

would appreciate any help to fix it with some detailed explanation , one of the solution saying to use Digest authentication, if it's correct, how do we use in the below code, the error pointed to "httppost.setHeader("Authorization", "Basic " + encoding);" this line

try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {

            String encoding;
            LOGGER.info("Entered into try");
            if (direction != null && direction.equalsIgnoreCase(ASPERA_DIRECTION_DOWNLOAD)) {
                LOGGER.info("entered if");
                url = acceleratorUtilConfig.getAccelDownloadSetupUrl();
                path = acceleratorUtilConfig.getS3DownloadRootPath() + path;
                
                encoding = new String(Base64.encodeBase64((acceleratorUtilConfig.getAccelDownloadAccessKey() + ":" + acceleratorUtilConfig.getAccelDownloadSecret()).getBytes()));
                
            } else {
                LOGGER.info("entered else");
                url = acceleratorUtilConfig.getAccelUploadSetupUrl();
                path = acceleratorUtilConfig.getS3UploadRootPath() + path;
                
                encoding = new String(Base64.encodeBase64((acceleratorUtilConfig.getAccelUploadAccessKey() + ":" + acceleratorUtilConfig.getAccelUploadSecret()).getBytes()));
            }

            LOGGER.debug("GenerateToken : {} : {}", url, path); 
            LOGGER.debug(": {}", encoding);
            LOGGER.debug(" : {} : {}", direction, filePathArray);
            LOGGER.debug("NewGenerateToken : {}", acceleratorUtilConfig.getAccelDownloadSetupUrl());
            TokenRequest tokreq = new TokenRequest(
                    Stream.of(new TransferRequest(new TransferRequestAttribute(true, "always", direction, path,
                            pathModel.getPathList(filePathArray), null), null)).collect(Collectors.toList()),
                    null);

            ObjectMapper mapper = new ObjectMapper();
            String inJson = "";
            inJson = mapper.writeValueAsString(tokreq);

            HttpPost httppost = new HttpPost(url);
            httppost.setHeader("Authorization", "Basic " + encoding);
            StringEntity input = new StringEntity(inJson);
            httppost.setEntity(input);
            LOGGER.debug("GenerateToken : Request sent");
            HttpResponse response1 = httpClient.execute(httppost);
            LOGGER.debug("GenerateToken : response returned");
Karthikeyan
  • 7,700
  • 10
  • 46
  • 66

0 Answers0