【发布时间】:2015-01-25 09:45:53
【问题描述】:
我在概念验证中使用 restlet,如下所示:
final Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
final Router router = new Router(component.getContext().createChildContext());
router.attachDefault(HttpListener.class);
component.start();
这应该给我一个http://localhost:8182/* 的 URL 路径。但是,当我尝试从这个 URL 获取 404 错误时:
http://localhost:8182/ -> 404
http://localhost:8182/xyz -> 404
Restlet 没有将任何请求路由到我的 HttpListener 类。
我的 HttpListener 类:
public class HttpListener extends ServerResource {
public static void main(String[] args) throws Exception {
final Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
final Router router = new Router(component.getContext().createChildContext());
router.attachDefault(HttpListener.class);
component.start();
}
@Get()
public Representation getDBName() {
String body = "hello, world";
Representation representation = new StringRepresentation(body, MediaType.APPLICATION_JSON);
representation.setCharacterSet(CharacterSet.UTF_8);
return representation;
}
}
【问题讨论】:
标签: restlet restlet-2.0