Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Exploring Your API With New Tools - HAL Browser

Dmitry Ponomarenko
Dmitry Ponomarenko
18,175 Points

HAL browser returns itself in Response Body

So here what I get:

http://i.imgur.com/QwJ3E3Z.png

Everything works fine when I put "/reviews" or "/courses" into Explorer field, but when I am trying to get root uri, I see HTML of HAL Browser instead of JSON. Does anyone know why this is happening? I tried to google this problem, but seems like we don't have a lot of information about HAL Browser yet.

Craig Dennis
Craig Dennis
Treehouse Teacher

Ha weird I hadn't seen that before! That makes sense though, it is what is served from the / route.

What are you expecting to see there?

Dmitry Ponomarenko
Dmitry Ponomarenko
18,175 Points

I imagine it should return content of the root page like on your video.

http://i.imgur.com/3gcXkBq.png

Because in my case I have a body of HAL browser instead, I don't have those links with green and orange buttons.

5 Answers

Chris Ramacciotti
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Chris Ramacciotti
Treehouse Guest Teacher

It turns out that this problem is rooted in Spring 4.3, not in the HAL browser itself. The Spring team is using a Spring 4.2 build for Spring Data REST, so the conflict wasn't detected.

If you're using version 1.3.x of the Spring Boot Gradle plugin, you'll get Spring 4.2. If you use version 1.4.x of the Spring Boot Gradle plugin, you'll get Spring 4.3. The problem is that the Spring Web module is unable to successfully resolve the default content-type of a request to the root of the HAL browser. In 4.2, it would default to 'application/json'. But, in Spring 4.3 (i.e. with Spring Boot 1.4), you'll need to explicitly ask for JSON.

To do this in the HAL browser, enter the following under Custom Request Headers:

Accept: application/json

Note that you should only have to do that at the root of the HAL browser, and not for specific resources.

See the following link for more details on the bug:

https://jira.spring.io/browse/DATAREST-863

Dmitry Ponomarenko
Dmitry Ponomarenko
18,175 Points

Okay, I fixed this.

I have another "group" and package naming, instead of "com.teamtreehouse" I have "com.sameperson". But couple videos ago I had problem with dependencies so I just copypasted them from Craig's project with his "group" field in Gradle build file. I fixed that and now problem is gone.

Robin Damsgaard Larsen
Robin Damsgaard Larsen
13,929 Points

I experienced this problem as well. Spring 1.4.0 had just been released, so in the gradle.build file I had configured the spring boot gradle plugin to use that version instead of Craig's version. Mostly because, you know, it's newer and shinier and I like to use the latest stuff. It turned out, however, that using 1.4.0 broke the HAL browser somehow, and upon reverting to version 1.3.3, everything worked as in the videos.

The HAL browser can work with spring boot 1.4.0, I'm sure, but I didn't research it further.

I ran into a strange issue with HAL, but fixed whith Chris's workaround put Accept: application/json in Customer Request Header and press GO (not Reload page)

Lingyong Wang
Lingyong Wang
176 Points

Upgrade to newer version (1.5.0) of the spring boot also fixed the problem. So you don't have to enter the header very time you use the HAL browser.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.0.RELEASE')
    }
}