Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic Authentication 401 Unauthorized error calling restful web service  RSS feed

 
john smiths
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All:

I am using spring-web-4.3.6.RELEASE.jar which contains Spring RestTemplate.java.
I wrote 4 junit test case to call the "https" basic authentication restfull web services. I already dealt with the "https" issue by registering the certificate to the java keystore cacerts file. Now I getting "http 401 Unauthorized" error when I call the restfull web services through java but not through soapUI or postman:

In Junit test case 2("testLocalCreateABCVersion2()"), I used custom ContextAwareHttpComponentsClientHttpRequestFactory.java class. Which I provided at the bottom.

In Junit test case 3("testLocalCreateABCVersion3()"), I used custom BasicAuthRestTemplate.java which I provided below.

In Junit test case 4(testLocalCreateABCVersion4()), I used org.apache.commons.httpclient.HttpClient and set client.getParams().setAuthenticationPreemptive(true) to true. This HttpClients comes from commons-httpClient-3.1.jar and does why the "setAuthenticationPreemptive" exists. In org.apache.httpcomponents.httpClient_4.5.3.jar it doesnt't contain the method setAuthenticationPreemptive.

Any help or hint would be greatly appreciated it!!


   


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!