0

I am trying to make a Call by the org.springframework.web.client.RestClient.

The address/resource does definetly exist GET http://localhost:8080/someResource.
It is retrievable by simple call in the browser or via curl.

Using the RestClient returns a 404 - not found. Why is it that way. What do I have to tweak to get a 200 success answer?

final var restClient = RestClient.create(); String result = restClient.get() .uri("http://localhost:8080/someResource") .header("User-Agent", "Mozilla/5.0") .accept( MediaType.ALL ) .retrieve() .body(String.class); 

Also the IntelliJ's http tooling (https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html) also does return a 404.

Strange to say, e.g. a request with RestClient to https://google.com does properly work.

I build an even more simplified example on github which does not work, see test class test.Tester: https://github.com/greyshine/springboot-simple-http-call

Is there a special minimal set of headers needed or anything else?

A call on the browser does work.
A call via curl localhost:8080/test-get does work.
A call via RESTer Chrome extension does work.

5
  • Can you try generating uri using uri-builder and use it. Commented Aug 10 at 6:17
  • @shaileshpatil no that doesn't do the job. I used the example from here stackoverflow.com/a/70044681/845117 Commented Aug 10 at 8:53
  • Well if other tools (i.e. Inteij client are also getting a 404 it does not sound like your call is the problem. That suggests there is some problem with what ever is serving up the localhost:8080/someResource URL. What does it show is happening when it gets the request? Commented Aug 12 at 15:27
  • Oh. Might be this. What MIME type is the end point you are calling configured to accept? JSON maybe? .accept( MediaType.ALL ) Commented Aug 12 at 15:28
  • @BrianC that will not do it either. I build the example on github, as stated in my updated question... Commented Aug 22 at 20:20

1 Answer 1

0

Well, I did get it running. No code change it does work properly as expected when I programmed it.

I guess this is an issue with IntelliJ and not the programming.
I observed that when 'messing' around with IntelliJ and Springboot-Web there is sometimes an nginx process in the background which 'still' serves requests on the http port though the web-app with the same port is shut down (on error or properly).
I may be mistaken that the process is started by intellij i.e. the springboot app. I will keep watching this.
(Using Springboot 3.5.0, Oracle OpenJdk22, IntelliJ 2024.1.7 UE)
Thanks to all who had an eye on it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.