我是使用restlet的新手。我想在控制台中打印一个简单的Hello World,所以我创建了三个简单的类:
public class Server扩展Application {
@Override
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
// Defines only one route
router.attach("/getGrid", Grid.class);
return router;
}
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, 8080);
// Attach the sample application.
component.getDefaultHost().attach("", new Server());
// Start the component.
component.start();
}
}
public class Client {
private static Representation response;
public static void main(String[] args) throws Exception {
ClientResource r = new ClientResource("http://localhost:8080/getGrid");
response = r.get() ;
System.out.println(response.getText());
}
}
public class Grid扩展ServerResource {
@Get
public void getGrid(){
getResponse().setEntity(new StringRepresentation("hello world!"));
}
}
不幸的是我无法在控制台上打印我的“hello world”,我只能看到与端口的连接和其他类似信息。你有想法帮我解决问题吗?怎么了? 提前致谢