Android - 第一次运行Restlet 2.2服务器 - 没有可用的服务器连接器

时间:2014-08-25 09:55:20

标签: java android restlet restlet-2.0

我正在尝试使用以下代码运行我的第一个Restlet服务器:

import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class WebServer extends ServerResource {

    /**
     * @param args
     * @throws Exception
     */
    public WebServer() throws Exception {
        // Create the HTTP server and listen on port 8182
        Server server = new Server(Protocol.HTTP, 8182, WebServer.class);
        server.start();

    }

    @Get
    public String present() {
        return "hello, world";
    }
}

但是当我启动服务器时,收到此错误消息:

No available server connector supports the required protocols: 'HTTP' . Please add the JAR of a matching connector to your classpath. Then, register this connector helper manually.

我将“org.restlet.jar”复制到\ libs文件夹,并将JAR添加到Java Build Path中的Libraries。我该怎么办?有什么问题?

1 个答案:

答案 0 :(得分:3)

如果将其配置为使用NIO HttpServerHelper,则可以运行它。只需下载NIO扩展并在RestLet引擎中进行配置,您就可以再次启动HTTP服务器。 (经2.3.1测试)。

import org.restlet.ext.nio.HttpServerHelper; 

...

Engine.getInstance().getRegisteredServers().clear();
Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(null));

要查看NIO扩展程序是否适用于您的版本,您可以查看: http://restlet.com/technical-resources/restlet-framework/guide/2.3/extensions/editions-matrix