• Post Reply Bookmark Topic Watch Topic
  • New Topic

RESTful Web Service - Spring Tutorial - Localhost Cannot Be Found - Is This Expected Behaviour?

 
Simon Ritchie
Ranch Hand
Posts: 99
4
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I''m trying to educate myself in the way of Spring and RESTful web services so I completed this tutorial from the official Spring site. Everything works fine - the .jar file was completed as expected - but when I click on http://localhost:8080/greeting two things happen

* My browser asks if I'd like to download the file named greeting.json from localhost
* If I just go to http://localhost:8080/ I get a message saying "The webpage cannot be found"

My questions are what do I need to do to activate the local host and does the fact that I could download the greeting.json file mean that the tutorial is behaving as expected?

I'm a complete newbie when it comes to web services so apologies if I've asked some basic questions. I just don't see anywhere on that page where it mentions anything about the localhost.

Thanks
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What browser are you trying the localhost:8080/greeting URL on? Do you see the same behavior from other browsers?

As for "webpage not found", it's expected because the only valid request mapping currently is a "/greeting" REST endpoint.
If you want root URL to show something, it should be mapped to some controller that returns some view.
 
Simon Ritchie
Ranch Hand
Posts: 99
4
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Internet Explorer 11. I've just tried what happens with Chrome and this is the result for the localhost



I should point out that I'm not running Tomcat or any web hosting service at all. I've literally just put this project together in Eclipse Luna and run it.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that error you see for the localhost:8080/greeting URL? What does "localhost:8080/greeting" give in Chrome?

Spring boot starts an embedded servlet container (embedded tomcat is the default, I think). That's how it's listening on 8080.
 
Simon Ritchie
Ranch Hand
Posts: 99
4
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Shiraly wrote:What does "localhost:8080/greeting" give in Chrome?


In Chrome that URL gives me the following

{"id":1,"content":"Hello, World!"}
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means the REST endpoint is working fine.
It was just an IE issue - I guess it doesn't know how to handle "application/json" MIME type and asks you to download it instead of displaying it. A quick search says some registry hack can force it to display the JSON. Anyway, it doesn't matter because REST services are meant to be consumed programatically. Write a javascript ajax client to consume that JSON, and it'll work fine - even on IE.
 
Simon Ritchie
Ranch Hand
Posts: 99
4
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great - thanks Karthik.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!