• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great - thanks Karthik.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic