• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Basic Authentication 401 Unauthorized error calling restful web service

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!


Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic