1

We are trying to access the Lithium Rest Api using HTTPS through Spring Rest Template as below

String plainCreds = lswUserName + ":" + lswPassword;
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
String base64Creds = new String(base64CredsBytes); 
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
HttpEntity<String> request = new HttpEntity<String>(headers);
ResponseEntity<String> sRawResp = restTemplate.exchange(completeURL.toString(), HttpMethod.GET, request, String.class);

Above code always gives

org.springframework.web.client.HttpClientErrorException: 401 Unauthorized Exception

There were no issues when invoking the same web service through postman, however when ever accessed through java code, getting the above 401 unauthorized exception

Previously I faced this issue with Windows OS, and I added below entry related to proxy in to catalina.bat:

JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=hy**1.*****.co.in -Dhttp.proxyPort=8080` 

Now we moved the entire setup to Linux OS and I get the same error. In Linux I don't have any proxy set. I checked through wget http://www.google.com and no proxy details are displayed.

How do I resolve this issue in Linux when no proxy is set?

Please Help.

jww
  • 97,681
  • 90
  • 411
  • 885
  • 2
    I think you'd be better treating this as a programming question and having it migrated to StackOverflow – roaima May 26 '18 at 20:56
  • It seems like you should set the proxy information for Linux, too. See questions like [How do I make HttpURLConnection use a proxy?](https://stackoverflow.com/q/1432961/608639) and [Tomcat and proxy settings](https://stackoverflow.com/q/12309800/608639). – jww May 27 '18 at 09:59

0 Answers0