Restlet Rest server on android

三世轮回 提交于 2019-12-23 05:48:25

问题


I want to host a simple rest server on an android phone to get remote access to some data. I followed the descriptions on the restlet website but I cant even get a simple example running.

I downloaded the android restlet package and added the org.restlet.jar as dependency.

In my onCreate method of the activity I have added these lines to start a simple server component.

Component serverComponent = new Component();
serverComponent.getServers().add(Protocol.HTTP, 80);  
final Router router = new Router(serverComponent.getContext().createChildContext());  
router.attach("/gamedata", GameDataResourceServer.class);  
serverComponent.getDefaultHost().attach(router);  
serverComponent.start();

The last call throws an Exception:

05-20 11:06:14.040 29947-29947/com.example.restserver E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.restserver, PID: 29947 java.lang.NoClassDefFoundError: com.sun.net.httpserver.HttpServer at org.restlet.engine.connector.HttpServerHelper.start(HttpServerHelper.java:68) ...

Why does the restlet framework tries to use the httpserver from java. This in not part of the android framework as I think.

P.S.: I figured out, that this issue only appears since restlet 2.2. The 2.1 branch works for me.


回答1:


The Android edition of Restlet shouldn't offer this internal HTTP server based on com.sun.net as this class isn't available on Android, only on Java SE/EE.

The previous internal HTTP server that is used in version 2.1 has been moved to the org.restlet.ext.nio extension. You can still use it in version 2.2 if you do the proper declaration.



来源:https://stackoverflow.com/questions/23755563/restlet-rest-server-on-android

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