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

Spring JIRA | Roy Clarkson | 5 years ago
  1. 0

    This was identified while investigating ANDROID-80. The Commons Http Client and HttpComponents Client both correctly set a 401 status code, while HttpURLConnection throws an IOException: java.io.IOException: Received authentication challenge is null The logs from unit testing illustrate this very clearly. Commons Http Client: I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) W/System.err(10439): 2012-05-02 16:04:46.842::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:46.855::INFO: Started SocketConnector@0.0.0.0:8080 I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.HttpClientErrorException: 401 Unauthorized I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) HttpComponents Http Client: I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) W/System.err(10439): 2012-05-02 16:04:51.069::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:51.081::INFO: Started SocketConnector@0.0.0.0:8080 D/dalvikvm(10439): GC_FOR_MALLOC freed 553K, 46% free 4493K/8263K, external 1625K/2137K, paused 53ms W/DefaultRequestDirector(10439): Authentication error: Unable to respond to any of these challenges: {} I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.HttpClientErrorException: 401 Unauthorized I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) Standard J2SE facilities (HttpURLConnection): I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests) W/System.err(10439): 2012-05-02 16:04:56.329::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:56.343::INFO: Started SocketConnector@0.0.0.0:8080 I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.ResourceAccessException: I/O error: Received authentication challenge is null; nested exception is java.io.IOException: Received authentication challenge is null I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:471) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): Caused by: java.io.IOException: Received authentication challenge is null I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:1095) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1048) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726) I/TestRunner(10439): at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:49) I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:457) I/TestRunner(10439): ... 15 more I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests)

    Spring JIRA | 5 years ago | Roy Clarkson
    org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
  2. 0

    This was identified while investigating ANDROID-80. The Commons Http Client and HttpComponents Client both correctly set a 401 status code, while HttpURLConnection throws an IOException: java.io.IOException: Received authentication challenge is null The logs from unit testing illustrate this very clearly. Commons Http Client: I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) W/System.err(10439): 2012-05-02 16:04:46.842::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:46.855::INFO: Started SocketConnector@0.0.0.0:8080 I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.HttpClientErrorException: 401 Unauthorized I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationCommonsClientTests) HttpComponents Http Client: I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) W/System.err(10439): 2012-05-02 16:04:51.069::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:51.081::INFO: Started SocketConnector@0.0.0.0:8080 D/dalvikvm(10439): GC_FOR_MALLOC freed 553K, 46% free 4493K/8263K, external 1625K/2137K, paused 53ms W/DefaultRequestDirector(10439): Authentication error: Unable to respond to any of these challenges: {} I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.HttpClientErrorException: 401 Unauthorized I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationHttpComponentsClientTests) Standard J2SE facilities (HttpURLConnection): I/TestRunner(10439): started: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests) W/System.err(10439): 2012-05-02 16:04:56.329::INFO: jetty-0.0 W/System.err(10439): 2012-05-02 16:04:56.343::INFO: Started SocketConnector@0.0.0.0:8080 I/TestRunner(10439): failed: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests) I/TestRunner(10439): ----- begin exception ----- I/TestRunner(10439): I/TestRunner(10439): org.springframework.web.client.ResourceAccessException: I/O error: Received authentication challenge is null; nested exception is java.io.IOException: Received authentication challenge is null I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:471) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) I/TestRunner(10439): at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) I/TestRunner(10439): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(10439): at java.lang.reflect.Method.invoke(Method.java:507) I/TestRunner(10439): at junit.framework.TestCase.runTest(TestCase.java:154) I/TestRunner(10439): at junit.framework.TestCase.runBare(TestCase.java:127) I/TestRunner(10439): at junit.framework.TestResult$1.protect(TestResult.java:106) I/TestRunner(10439): at junit.framework.TestResult.runProtected(TestResult.java:124) I/TestRunner(10439): at junit.framework.TestResult.run(TestResult.java:109) I/TestRunner(10439): at junit.framework.TestCase.run(TestCase.java:118) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) I/TestRunner(10439): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) I/TestRunner(10439): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) I/TestRunner(10439): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) I/TestRunner(10439): Caused by: java.io.IOException: Received authentication challenge is null I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:1095) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1048) I/TestRunner(10439): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726) I/TestRunner(10439): at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:49) I/TestRunner(10439): at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46) I/TestRunner(10439): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:457) I/TestRunner(10439): ... 15 more I/TestRunner(10439): ----- end exception ----- I/TestRunner(10439): finished: testGetEntityNotAuthorized(org.springframework.web.client.RestTemplateIntegrationSimpleClientTests)

    Spring JIRA | 5 years ago | Roy Clarkson
    org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
  3. 0

    While logged in as a custom created administrator role an error is displayed when attempting to edit a user in BES12 version 12.5

    blackberry.com | 4 months ago
    org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Android AsyncTask with Spring web-services

    Stack Overflow | 2 years ago | Kyniu
    java.lang.RuntimeException: An error occured while executing doInBackground()
  6. 0

    JHipster Registry rejects gateways and microservices

    Stack Overflow | 7 months ago | CidTori
    java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.web.client.HttpClientErrorException

      401 Unauthorized

      at org.springframework.web.client.DefaultResponseErrorHandler.handleError()
    2. Spring
      AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized
      1. org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
      2. org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504)
      3. org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461)
      4. org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419)
      5. org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239)
      6. org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128)
      6 frames
    3. Java RT
      Method.invoke
      1. java.lang.reflect.Method.invokeNative(Native Method)
      2. java.lang.reflect.Method.invoke(Method.java:507)
      2 frames
    4. JUnit
      TestCase.run
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      2. junit.framework.TestCase.runBare(TestCase.java:127)
      3. junit.framework.TestResult$1.protect(TestResult.java:106)
      4. junit.framework.TestResult.runProtected(TestResult.java:124)
      5. junit.framework.TestResult.run(TestResult.java:109)
      6. junit.framework.TestCase.run(TestCase.java:118)
      6 frames
    5. Android Platform
      Instrumentation$InstrumentationThread.run
      1. android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
      2. android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
      3. android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
      4. android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
      4 frames