Document is empty error while returning get response in Chrome

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Document is empty error while returning get response in Chrome

Binoy Dalal
Hello everyone,
I've just started out with the restlet framework.
I've written simple server and resource classes to get started. Here's the code:
Resource:
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class HelloWorldResource extends ServerResource {
        @Get
        public String represent(){
                return "Hello World";
        }
}


Server:
import org.restlet.Server;
import org.restlet.data.Protocol;

public class HelloWorldServer {
        public static void main(String[] args) throws Exception {
                Server server = new Server(Protocol.HTTP, 8989, HelloWorldResource.class);
                server.start();
        }
}


When I try to run the code in Chrome by hitting http://localhost:8989/ I get the following error:



This error goes away when I enclose the resource return value in xml tags like so <sometag>Hello World</sometag> and the default XML template is displayed in Chrome with "Hello World" in the tags.

Using a ClientResource variable to access the resource via code works just fine without the tags.

Additionally, while running the same code in IE, it automatically downloads a JSON file with the message to my computer.

What is the reason behind this kind of behavior?

Thanks.