Android - First run of Restlet 2.2 server - No available server connector

泪湿孤枕 提交于 2019-12-06 06:48:15

问题


I´m trying to run my first Restlet server with this code:

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";
    }
}

But when I start the server, I get this error message:

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.

I copied the "org.restlet.jar" to the \libs folder and add JAR to the Libraries in Java Build Path. What should I do? What is wrong?


回答1:


it's possible to run it if you configure it to use the NIO HttpServerHelper. Simply downloading the NIO extension and configuring it in the RestLet Engine will allow you to spin up an HTTP server again. (Tested on 2.3.1).

import org.restlet.ext.nio.HttpServerHelper; 

...

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

To see if the NIO extension is available for your edition you can have a look on: http://restlet.com/technical-resources/restlet-framework/guide/2.3/extensions/editions-matrix



来源:https://stackoverflow.com/questions/25483312/android-first-run-of-restlet-2-2-server-no-available-server-connector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!