HttpClientErrorException: 404 null Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!Avoiding != null statementsSpring REST ErrorFile Upload Java SpringMethod not allowed when calling sales force update contact API through Spring RestTemplateSend a String to a Spring(Jackson) REST controller in a POST methodCould not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [*/*;charset=UTF-8]Getting 400 for Spring RestTemplate POSTerror “org.springframework.web.client.HttpClientErrorException: 404 null” in spring bootorg.springframework.web.client.HttpClientErrorException: 403 null (Spring RestTemplate)nested exception is java.util.concurrent.ExecutionException

List *all* the tuples!

Why is "Consequences inflicted." not a sentence?

How does debian/ubuntu knows a package has a updated version

Why do we bend a book to keep it straight?

How do I keep my slimes from escaping their pens?

How to override model in magento2?

How to answer "Have you ever been terminated?"

What's the meaning of 間時肆拾貳 at a car parking sign

Is it true that "carbohydrates are of no use for the basal metabolic need"?

Dating a Former Employee

Do I really need recursive chmod to restrict access to a folder?

How can I make names more distinctive without making them longer?

In predicate logic, does existential quantification (∃) include universal quantification (∀), i.e. can 'some' imply 'all'?

How come Sam didn't become Lord of Horn Hill?

3 doors, three guards, one stone

What is known about the Ubaid lizard-people figurines?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Identifying polygons that intersect with another layer using QGIS?

Error "illegal generic type for instanceof" when using local classes

When were vectors invented?

Why do people hide their license plates in the EU?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Okay to merge included columns on otherwise identical indexes?

How to react to hostile behavior from a senior developer?



HttpClientErrorException: 404 null



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!Avoiding != null statementsSpring REST ErrorFile Upload Java SpringMethod not allowed when calling sales force update contact API through Spring RestTemplateSend a String to a Spring(Jackson) REST controller in a POST methodCould not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [*/*;charset=UTF-8]Getting 400 for Spring RestTemplate POSTerror “org.springframework.web.client.HttpClientErrorException: 404 null” in spring bootorg.springframework.web.client.HttpClientErrorException: 403 null (Spring RestTemplate)nested exception is java.util.concurrent.ExecutionException



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I try to call the address in the controller using RestTemplate and as a result I want to get OK or NOT FOUND status
I do so in this controller



@GetMapping(value = "/thanks")
public ModelAndView confirmAccount(
@RequestParam String token,
UriComponentsBuilder uriComponentsBuilder
)
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());

UriComponents uriComponents
= uriComponentsBuilder.path("/register/token/token").buildAndExpand(token);

ResponseEntity<Boolean> response = restTemplate
.exchange(uriComponents.toUri(),
HttpMethod.PUT,
entity,
Boolean.class);

return response.getStatusCode().toString().equals("200")
? new ModelAndView("redirect:/signIn") : new ModelAndView("tokenNotFound");



I call this address of the controller.



@RequestMapping(value = "/register/token/token", method = RequestMethod.PUT)
public
HttpEntity<Boolean> confirmAccount(
@PathVariable String token
)
Optional<User> userOptional = userService.findByActivationToken(token);

if(userOptional.isPresent())
User user = userOptional.get();

user.setActivationToken(null);
user.setEnabled(true);

userService.saveUser(user);
else
return ResponseEntity.notFound().build();


return ResponseEntity.ok(true);



As a result, she throws me out in the console



org.springframework.web.client.HttpClientErrorException: 404 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:549) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at com.service.app.controller.RegisterController.confirmAccount(RegisterController.java:40) ~[classes/:na]


Why does RestTemplate not want to return the status 404 as a result?
enter code here










share|improve this question
























  • What url are you calling to test the flow?

    – Amit K Bist
    Sep 12 '17 at 0:15











  • Sorry. I map the entire controller to' /register'. Here I corrected the address.

    – user8594721
    Sep 12 '17 at 0:17











  • When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

    – saurabh
    Sep 12 '17 at 0:21











  • First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

    – Amit K Bist
    Sep 12 '17 at 0:32

















0















I try to call the address in the controller using RestTemplate and as a result I want to get OK or NOT FOUND status
I do so in this controller



@GetMapping(value = "/thanks")
public ModelAndView confirmAccount(
@RequestParam String token,
UriComponentsBuilder uriComponentsBuilder
)
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());

UriComponents uriComponents
= uriComponentsBuilder.path("/register/token/token").buildAndExpand(token);

ResponseEntity<Boolean> response = restTemplate
.exchange(uriComponents.toUri(),
HttpMethod.PUT,
entity,
Boolean.class);

return response.getStatusCode().toString().equals("200")
? new ModelAndView("redirect:/signIn") : new ModelAndView("tokenNotFound");



I call this address of the controller.



@RequestMapping(value = "/register/token/token", method = RequestMethod.PUT)
public
HttpEntity<Boolean> confirmAccount(
@PathVariable String token
)
Optional<User> userOptional = userService.findByActivationToken(token);

if(userOptional.isPresent())
User user = userOptional.get();

user.setActivationToken(null);
user.setEnabled(true);

userService.saveUser(user);
else
return ResponseEntity.notFound().build();


return ResponseEntity.ok(true);



As a result, she throws me out in the console



org.springframework.web.client.HttpClientErrorException: 404 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:549) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at com.service.app.controller.RegisterController.confirmAccount(RegisterController.java:40) ~[classes/:na]


Why does RestTemplate not want to return the status 404 as a result?
enter code here










share|improve this question
























  • What url are you calling to test the flow?

    – Amit K Bist
    Sep 12 '17 at 0:15











  • Sorry. I map the entire controller to' /register'. Here I corrected the address.

    – user8594721
    Sep 12 '17 at 0:17











  • When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

    – saurabh
    Sep 12 '17 at 0:21











  • First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

    – Amit K Bist
    Sep 12 '17 at 0:32













0












0








0








I try to call the address in the controller using RestTemplate and as a result I want to get OK or NOT FOUND status
I do so in this controller



@GetMapping(value = "/thanks")
public ModelAndView confirmAccount(
@RequestParam String token,
UriComponentsBuilder uriComponentsBuilder
)
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());

UriComponents uriComponents
= uriComponentsBuilder.path("/register/token/token").buildAndExpand(token);

ResponseEntity<Boolean> response = restTemplate
.exchange(uriComponents.toUri(),
HttpMethod.PUT,
entity,
Boolean.class);

return response.getStatusCode().toString().equals("200")
? new ModelAndView("redirect:/signIn") : new ModelAndView("tokenNotFound");



I call this address of the controller.



@RequestMapping(value = "/register/token/token", method = RequestMethod.PUT)
public
HttpEntity<Boolean> confirmAccount(
@PathVariable String token
)
Optional<User> userOptional = userService.findByActivationToken(token);

if(userOptional.isPresent())
User user = userOptional.get();

user.setActivationToken(null);
user.setEnabled(true);

userService.saveUser(user);
else
return ResponseEntity.notFound().build();


return ResponseEntity.ok(true);



As a result, she throws me out in the console



org.springframework.web.client.HttpClientErrorException: 404 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:549) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at com.service.app.controller.RegisterController.confirmAccount(RegisterController.java:40) ~[classes/:na]


Why does RestTemplate not want to return the status 404 as a result?
enter code here










share|improve this question
















I try to call the address in the controller using RestTemplate and as a result I want to get OK or NOT FOUND status
I do so in this controller



@GetMapping(value = "/thanks")
public ModelAndView confirmAccount(
@RequestParam String token,
UriComponentsBuilder uriComponentsBuilder
)
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> entity = new HttpEntity<>(new HttpHeaders());

UriComponents uriComponents
= uriComponentsBuilder.path("/register/token/token").buildAndExpand(token);

ResponseEntity<Boolean> response = restTemplate
.exchange(uriComponents.toUri(),
HttpMethod.PUT,
entity,
Boolean.class);

return response.getStatusCode().toString().equals("200")
? new ModelAndView("redirect:/signIn") : new ModelAndView("tokenNotFound");



I call this address of the controller.



@RequestMapping(value = "/register/token/token", method = RequestMethod.PUT)
public
HttpEntity<Boolean> confirmAccount(
@PathVariable String token
)
Optional<User> userOptional = userService.findByActivationToken(token);

if(userOptional.isPresent())
User user = userOptional.get();

user.setActivationToken(null);
user.setEnabled(true);

userService.saveUser(user);
else
return ResponseEntity.notFound().build();


return ResponseEntity.ok(true);



As a result, she throws me out in the console



org.springframework.web.client.HttpClientErrorException: 404 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:549) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at com.service.app.controller.RegisterController.confirmAccount(RegisterController.java:40) ~[classes/:na]


Why does RestTemplate not want to return the status 404 as a result?
enter code here







java spring rest spring-mvc spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 12 '17 at 0:35

























asked Sep 12 '17 at 0:12







user8594721



















  • What url are you calling to test the flow?

    – Amit K Bist
    Sep 12 '17 at 0:15











  • Sorry. I map the entire controller to' /register'. Here I corrected the address.

    – user8594721
    Sep 12 '17 at 0:17











  • When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

    – saurabh
    Sep 12 '17 at 0:21











  • First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

    – Amit K Bist
    Sep 12 '17 at 0:32

















  • What url are you calling to test the flow?

    – Amit K Bist
    Sep 12 '17 at 0:15











  • Sorry. I map the entire controller to' /register'. Here I corrected the address.

    – user8594721
    Sep 12 '17 at 0:17











  • When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

    – saurabh
    Sep 12 '17 at 0:21











  • First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

    – Amit K Bist
    Sep 12 '17 at 0:32
















What url are you calling to test the flow?

– Amit K Bist
Sep 12 '17 at 0:15





What url are you calling to test the flow?

– Amit K Bist
Sep 12 '17 at 0:15













Sorry. I map the entire controller to' /register'. Here I corrected the address.

– user8594721
Sep 12 '17 at 0:17





Sorry. I map the entire controller to' /register'. Here I corrected the address.

– user8594721
Sep 12 '17 at 0:17













When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

– saurabh
Sep 12 '17 at 0:21





When is HttpClientErrorException exception occurring, while calling "/thanks" or "/register/token"? More stacktrace can be useful

– saurabh
Sep 12 '17 at 0:21













First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

– Amit K Bist
Sep 12 '17 at 0:32





First you need to check if you are calling /register/token/token it correctly? If it is actually going inside confirmAccount Method, that you can check by putting a breakpoint of a log statement. If it is not hitting this method then problem is in calling the method which will also throw 404 but it will be thrown by Spring.

– Amit K Bist
Sep 12 '17 at 0:32












2 Answers
2






active

oldest

votes


















0














a simple explanation can be HttpClientErrorException is unchecked exception. Java docs for this exception tells, 'Exception thrown when an HTTP 4xx is received'
ref - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html



so try handling exception with appropriate try/catch and throws






share|improve this answer






























    0














    In my case, I left out a forward slash at the end of my endpoint and got the error. After putting it on at the end of my url it worked fine.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46166049%2fhttpclienterrorexception-404-null%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown
























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      a simple explanation can be HttpClientErrorException is unchecked exception. Java docs for this exception tells, 'Exception thrown when an HTTP 4xx is received'
      ref - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html



      so try handling exception with appropriate try/catch and throws






      share|improve this answer



























        0














        a simple explanation can be HttpClientErrorException is unchecked exception. Java docs for this exception tells, 'Exception thrown when an HTTP 4xx is received'
        ref - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html



        so try handling exception with appropriate try/catch and throws






        share|improve this answer

























          0












          0








          0







          a simple explanation can be HttpClientErrorException is unchecked exception. Java docs for this exception tells, 'Exception thrown when an HTTP 4xx is received'
          ref - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html



          so try handling exception with appropriate try/catch and throws






          share|improve this answer













          a simple explanation can be HttpClientErrorException is unchecked exception. Java docs for this exception tells, 'Exception thrown when an HTTP 4xx is received'
          ref - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html



          so try handling exception with appropriate try/catch and throws







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 12 '17 at 0:29









          saurabhsaurabh

          348718




          348718























              0














              In my case, I left out a forward slash at the end of my endpoint and got the error. After putting it on at the end of my url it worked fine.






              share|improve this answer



























                0














                In my case, I left out a forward slash at the end of my endpoint and got the error. After putting it on at the end of my url it worked fine.






                share|improve this answer

























                  0












                  0








                  0







                  In my case, I left out a forward slash at the end of my endpoint and got the error. After putting it on at the end of my url it worked fine.






                  share|improve this answer













                  In my case, I left out a forward slash at the end of my endpoint and got the error. After putting it on at the end of my url it worked fine.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 18 '18 at 12:32









                  OAMOAM

                  468




                  468



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46166049%2fhttpclienterrorexception-404-null%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript