尝试从Android活动中公开Restlet服务

时间:2015-01-31 19:53:49

标签: android restlet

我正在尝试按如下方式创建Restlet服务(根据Restlet in Action书中的说明):

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8182);
        component.getDefaultHost().attachDefault(HttpListener.class);

        try {
            component.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

我的AndroidManifest.xml中的权限:

<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="android.permission.INTERNET"/>

我在build.gradle中的依赖项:

compile("org.restlet.jse:org.restlet:2.1-M7") {
    exclude group: 'org.osgi', module: 'org.osgi.core'
}
compile("org.restlet.jse:org.restlet.ext.simple:2.1-M7")

日志输出:

E/libprocessgroup﹕ failed to make and chown /acct/uid_10053: Read-only file system
W/Zygote﹕ createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
I/art﹕ Not late-enabling -Xcheck:jni (already on)
W/art﹕ Suspending all threads took: 6.497ms
I/art﹕ Background partial concurrent mark sweep GC freed 2599(114KB) AllocSpace objects, 1(27KB) LOS objects, 25% free, 1651KB/2MB, paused 10.530ms total 27.594ms
W/System.err﹕ java.net.SocketException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:623)
W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
W/System.err﹕ at java.net.PlainServerSocketImpl.create(PlainServerSocketImpl.java:38)
W/System.err﹕ at java.net.ServerSocket.<init>(ServerSocket.java:64)
W/System.err﹕ at java.nio.ServerSocketChannelImpl$ServerSocketAdapter.<init>(ServerSocketChannelImpl.java:120)
W/System.err﹕ at java.nio.ServerSocketChannelImpl.<init>(ServerSocketChannelImpl.java:51)
W/System.err﹕ at java.nio.SelectorProviderImpl.openServerSocketChannel(SelectorProviderImpl.java:45)
W/System.err﹕ at java.nio.channels.ServerSocketChannel.open(ServerSocketChannel.java:61)
W/System.err﹕ at org.restlet.engine.connector.ServerConnectionHelper.createServerSocketChannel(ServerConnectionHelper.java:148)
W/System.err﹕ at org.restlet.engine.connector.ServerConnectionHelper.start(ServerConnectionHelper.java:313)
W/System.err﹕ at org.restlet.Server.start(Server.java:587)
W/System.err﹕ at com.example.snowch.myapplication.MainActivity.onCreate(MainActivity.java:38)
W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/System.err﹕ Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.Posix.socket(Native Method)
W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:608)
W/System.err﹕ ... 24 more
D/OpenGLRenderer﹕ Render dirty regions requested: true
D/﹕ HostConnection::get() New Host Connection established 0xa6ec1890, tid 1956
W/System.err﹕ Stopping the internal [HTTP/1.1] server
D/Atlas﹕ Validating map...
D/﹕ HostConnection::get() New Host Connection established 0xa6ec1930, tid 1973
I/OpenGLRenderer﹕ Initialized EGL, version 1.4
D/OpenGLRenderer﹕ Enabling debug mode 0
W/EGL_emulation﹕ eglSurfaceAttrib not implemented
W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6eb3800, error=EGL_SUCCESS
W/System.err﹕ java.net.SocketException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:623)
W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
W/System.err﹕ at java.net.PlainServerSocketImpl.create(PlainServerSocketImpl.java:38)
W/System.err﹕ at java.net.ServerSocket.<init>(ServerSocket.java:64)
W/System.err﹕ at java.nio.ServerSocketChannelImpl$ServerSocketAdapter.<init>(ServerSocketChannelImpl.java:120)
W/System.err﹕ at java.nio.ServerSocketChannelImpl.<init>(ServerSocketChannelImpl.java:51)
W/System.err﹕ at java.nio.SelectorProviderImpl.openServerSocketChannel(SelectorProviderImpl.java:45)
W/System.err﹕ at java.nio.channels.ServerSocketChannel.open(ServerSocketChannel.java:61)
W/System.err﹕ at org.restlet.engine.connector.ServerConnectionHelper.createServerSocketChannel(ServerConnectionHelper.java:148)
W/System.err﹕ at org.restlet.engine.connector.ServerConnectionHelper.start(ServerConnectionHelper.java:313)
W/System.err﹕ at org.restlet.Server.start(Server.java:587)
W/System.err﹕ at com.example.snowch.myapplication.MainActivity.onCreate(MainActivity.java:38)
W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
W/System.err﹕ at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912)
W/System.err﹕ at android.app.ActivityThread.access$900(ActivityThread.java:144)
W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/System.err﹕ Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.Posix.socket(Native Method)
W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:608)
W/System.err﹕ ... 25 more
W/EGL_emulation﹕ eglSurfaceAttrib not implemented
W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6eb3800, error=EGL_SUCCESS

任何指针都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

似乎我还需要以下许可:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />