org.springframework.web.client.HttpClientErrorException

tip

Check if your path is correct, if it's correct already you have to register your path to the mapping configuration.


rafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • 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)
    via by Roy Clarkson,
  • 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)
    via by Roy Clarkson,
  • spring security 403 error
    via Stack Overflow by ken
    ,
  • GitHub comment 42#208904220
    via GitHub by samynathan17
    ,
    • org.springframework.web.client.HttpClientErrorException: 401 Unauthorized at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:504) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:419) at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:239) at org.springframework.web.client.AbstractRestTemplateIntegrationTests.testGetEntityNotAuthorized(AbstractRestTemplateIntegrationTests.java:128) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

    Users with the same issue

    osvzs
    9 times, last one,
    tvrmsmith
    5 times, last one,
    batwalrus76
    27 times, last one,
    pulse00
    1 times, last one,
    Victor_IT
    3 times, last one,
    118 more bugmates