6 posts / 0 new
Last post
#1 Thu, 24/10/2019 - 19:22
pcampanella

Download files using opensearch returned link: error 401

Dear Support,                    our system supports the possibility to get images from the shared drive or via OpenSearch from different nodes. In the past we were able to search and donwload files. Now we receive http 401 when we try to download. The system makes and opensearch query, it works, then takes the link from the Atom result and make a request to download the file. Our code (in Java) used the http authentication that worked before.  The code snippet is: ________________________________________
// Basic HTTP Authentication
m_oLogger.debug("ProviderAdapter.downloadViaHttp: sDownloadUser = " + sDownloadUser);
Authenticator.setDefault(new Authenticator() {
     protected PasswordAuthentication getPasswordAuthentication() {
          try {
               return new PasswordAuthentication(sDownloadUser, sDownloadPassword.toCharArray());
          } catch (Exception oEx) {
                  m_oLogger.error("ProviderAdapter.downloadViaHttp: exception setting auth " + org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(oEx));
          }
          return null;
    }
});

m_oLogger.debug("ProviderAdapter.downloadViaHttp: FileUrl = " + sFileURL);
URL oUrl = new URL(sFileURL);
HttpURLConnection oHttpConn = (HttpURLConnection) oUrl.openConnection();
oHttpConn.setRequestMethod("GET");
oHttpConn.setRequestProperty("Accept", "*/*");
oHttpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
int responseCode = oHttpConn.getResponseCode();
// always check HTTP response code first
if (responseCode == HttpURLConnection.HTTP_OK) {
                  m_oLogger.debug("ProviderAdapter.downloadViaHttp: Connected");
________________________________________   I'm sure that user and password are correct (tried with user interface).   Can you help us to solve this issue? Is Basic Authentication already supported? Is there any other way to authenticate "by code" ? Or any other way to download the products by code and not by hand? Thank you very much Paolo 
Wed, 30/10/2019 - 10:41
jurgen_everaerts

Hi Paolo,

Hi Paolo, sorry for the delay - many colleagues are on holiday. We will come back to you early next week. Jurgen
Tue, 05/11/2019 - 14:55
daemsd

Hi Paolo,

Hi Paolo, can you give us an example URL for which the download fails? Thanks, Dirk
Tue, 05/11/2019 - 21:07
pcampanella
Thu, 07/11/2019 - 09:18
daemsd

Hi Paolo, basic

Hi Paolo, basic authentication is still supported. We tried to download the link using two different accounts via basic authentication and it seems to work fine. Some clients (e.g wget) first send an GET request without an Authorization header, so then it is normal that the server first replies with a 401 error code, then the client will do another request including the basic authentication header. I am not sure how your Java client handles this. So, if you did not already, can you try to download the same file via wget or curl? Does the server also provide more info in the body of the response? Thanks, Dirk
Thu, 07/11/2019 - 13:29
pcampanella

Dear Dirk, we made some test

Dear Dirk, we made some test and you are right. We changed the code to generate the http header "by hand" and it is working now. In this moment, I'm not able to read the downloaded file with SNAP, but I'll check more before bothering you :) Thank you very much Paolo