Reputation: 509
I have just begun creating my first restlet application. I have followed the restlet first steps tutorial. I have created all the files exactly as stated and the server runs perfectly when I run it but then when I call my service via postman I get this error:
Error:
2015-04-20 20:39:53 0:0:0:0:0:0:0:1 - - 8182 GET /firstSteps/hello - 200 12 0 156 http://localhost:8182 Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36 -
An exception occured writing the response entity
java.lang.ClassCastException: org.restlet.data.Header cannot be cast to org.restlet.engine.header.Header
at org.restlet.ext.simple.internal.SimpleCall.writeResponseHead(SimpleCall.java:304)
at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:450)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:187)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:144)
at org.restlet.ext.simple.internal.SimpleContainer.handle(SimpleContainer.java:80)
at org.simpleframework.http.core.Dispatcher.dispatch(Dispatcher.java:121)
at org.simpleframework.http.core.Dispatcher.run(Dispatcher.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Error while handling an HTTP server call
Here is my code:
Helloworld Class:
package smartRoom;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
/**
* Resource which has only one representation.
*/
public class Helloworld extends ServerResource {
@Get
public String represent() {
return "hello, world";
}
}
and here is my application class:
package smartRoom;
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;
public class HelloworldAppilcation extends Application {
public static void main(String[] args) throws Exception {
// Create a new Component.
Component component = new Component();
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
// Attach the sample application.
component.getDefaultHost().attach("/firstSteps",
new HelloworldAppilcation());
// Start the component.
component.start();
}
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public synchronized Restlet createInboundRoot() {
// Create a router Restlet that routes each call to a new instance of HelloWorldResource.
Router router = new Router(getContext());
// Defines only one route
router.attach("/hello", Helloworld.class);
return router;
}
}
I have been unable to find any content online regarding this error. I re-created the project from scratch following the instructions to the tee and still got the same error. I am unsure as to what I am doing wrong and any help would be greatly apprecaited.
Update
yes I can confirm the port is open and listening
update Two
http://restlet.com/technical-resources/restlet-framework/guide/2.2/editions/jse/overview
I have now also tried the maven tutorial and got the same result.
Update Three
I gave it another go today and started from scratch re-downloading everything and it work perfectly this time. Not exactly sure what the problem was, but was most likely to do with the version of restlet is was using.
Upvotes: 0
Views: 2005
Reputation: 41
for me it worked after I added extension org.restlet.ext.jetty to classpath as suggested. BTW I used Gradle to build project.
Upvotes: 0
Reputation: 202176
I would suggest you to use the version 2.3 of Restlet with a server connector like Jetty (add extension org.restlet.ext.jetty in your classpath).
As far as I can see, you did the right things to implement a starter application with Restlet.
Can you give us the exact version of Restlet you use?
Here is a sample of file pom.xml
that you can try for your application:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.restlet</groupId>
<artifactId>restlet-starter</artifactId>
<name>${project.artifactId}</name>
<packaging>jar</packaging>
<version>1.0.0-snapshot</version>
<properties>
<restlet-version>2.3.1</restlet-version>
</properties>
<dependencies>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet</artifactId>
<version>${restlet-version}</version>
</dependency>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.jetty</artifactId>
<version>${restlet-version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.com</url>
</repository>
</repositories>
</project>
Hope it helps you, Thierry
Upvotes: 1