Matthias247 / jawampa

Web Application Messaging Protocol (WAMP v2) support for Java
Apache License 2.0
148 stars 56 forks source link

ApplicationError(wamp.error.invalid_uri, [], {}) even when URI is completely valid #102

Closed cdrandin closed 7 years ago

cdrandin commented 7 years ago

I have tested the process I have been doing on multiple devices, however, when I start using it on Android it always fails.

I have been using WAMP to communicate between multiple devices. There doesn't seem to be any official support for Autobahn on Android that supports WAMP jawampa should do the trick.

I included this module into the Android project using Android Studios. I am rather new to Android development so I tried resolving the issues from places I have more experience in. I think that this is possibly something going wrong when using this with Android.

Here are my settings for the project.

app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.cdrandin.androidapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/io.netty.versions.properties'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/rxjava.properties'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    testCompile 'junit:junit:4.12'
    compile 'ws.wamp.jawampa:jawampa-core:0.4.2'
    compile 'ws.wamp.jawampa:jawampa-netty:0.4.2'
    compile 'io.reactivex.rxjava2:rxjava:2.0.5'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
}

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

WAMP code:

package com.example.cdrandin.androidapp;

import android.util.Log;

import java.util.concurrent.TimeUnit;

import rx.functions.Action1;
import rx.schedulers.Schedulers;
import ws.wamp.jawampa.WampClient;
import ws.wamp.jawampa.WampClientBuilder;
import ws.wamp.jawampa.WampError;
import ws.wamp.jawampa.transport.netty.NettyWampClientConnectorProvider;

public class WampTasks {
    private static WampTasks _ourInstance = new WampTasks();
    private static String _host = "192.168.2.201";
    private static String _port = "8080";

    public static WampTasks getInstance() {
        return _ourInstance;
    }

    public WampClient client = null;

    private WampTasks() {
        try {
            // Create a builder and configure the client
            WampClientBuilder builder = new WampClientBuilder();
            NettyWampClientConnectorProvider connectorProvider = new NettyWampClientConnectorProvider();
            builder.withConnectorProvider(connectorProvider)
                    .withUri(String.format("ws://%s:%s/ws", _host, _port))
                    .withRealm("realm1")
                    .withStrictUriValidation(false)
                    .withInfiniteReconnects()
                    .withReconnectInterval(5, TimeUnit.SECONDS);

            // Create a client through the builder. This will not immediately start
            // a connection attempt
            client = builder.build();
            client.open();
        } catch (WampError e) {
            // Catch exceptions that will be thrown in case of invalid configuration
            e.printStackTrace();
            return;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }

    public void Alert() {
        client.publish("com.app.test", "hello world");
    }
}

crash report:

I/ActivityManager( 1525): START u0 {cmp=com.example.cdrandin.androidapp/.SelectedDevice} from uid 10059 on display 0
W/AudioTrack( 1525): AUDIO_OUTPUT_FLAG_FAST denied by client
V/WindowManager( 1525): addAppToken: AppWindowToken{236e690d token=Token{11db07a4 ActivityRecord{15693637 u0 com.example.cdrandin.androidapp/.SelectedDevice t64}}} to stack=1 task=64 at 1
I/art     ( 2981): Background sticky concurrent mark sweep GC freed 99(3KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 2045KB/2045KB, paused 13.131ms total 48.272ms
W/System.err( 2981): ApplicationError(wamp.error.invalid_uri, [], {})
W/System.err( 2981):    at ws.wamp.jawampa.transport.netty.NettyWampClientConnectorProvider.createConnector(NettyWampClientConnectorProvider.java:102)
W/System.err( 2981):    at ws.wamp.jawampa.WampClientBuilder.build(WampClientBuilder.java:127)
W/System.err( 2981):    at com.example.cdrandin.androidapp.WampTasks.<init>(WampTasks.java:42)
W/System.err( 2981):    at com.example.cdrandin.androidapp.WampTasks.<clinit>(WampTasks.java:18)
W/System.err( 2981):    at com.example.cdrandin.androidapp.SelectedDevice.onCreate(SelectedDevice.java:13)
W/System.err( 2981):    at android.app.Activity.performCreate(Activity.java:5990)
W/System.err( 2981):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
W/System.err( 2981):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
W/System.err( 2981):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err( 2981):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err( 2981):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err( 2981):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 2981):    at android.os.Looper.loop(Looper.java:135)
W/System.err( 2981):    at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err( 2981):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 2981):    at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 2981):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
W/System.err( 2981):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
D/AndroidRuntime( 2981): Shutting down VM
E/AndroidRuntime( 2981): FATAL EXCEPTION: main
E/AndroidRuntime( 2981): Process: com.example.cdrandin.androidapp, PID: 2981
E/AndroidRuntime( 2981): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cdrandin.androidapp/com.example.cdrandin.androidapp.SelectedDevice}: java.lang.NullPointerException: Attempt to invoke virtual method 'rx.Observable ws.wamp.jawampa.WampClient.publish(java.lang.String, java.lang.Object[])' on a null object reference
E/AndroidRuntime( 2981):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
E/AndroidRuntime( 2981):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
E/AndroidRuntime( 2981):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
E/AndroidRuntime( 2981):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
E/AndroidRuntime( 2981):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2981):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2981):    at android.app.ActivityThread.main(ActivityThread.java:5254)
E/AndroidRuntime( 2981):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2981):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 2981):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/AndroidRuntime( 2981):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E/AndroidRuntime( 2981): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'rx.Observable ws.wamp.jawampa.WampClient.publish(java.lang.String, java.lang.Object[])' on a null object reference
E/AndroidRuntime( 2981):    at com.example.cdrandin.androidapp.WampTasks.Alert(WampTasks.java:69)
E/AndroidRuntime( 2981):    at com.example.cdrandin.androidapp.SelectedDevice.onCreate(SelectedDevice.java:13)
E/AndroidRuntime( 2981):    at android.app.Activity.performCreate(Activity.java:5990)
E/AndroidRuntime( 2981):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/AndroidRuntime( 2981):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E/AndroidRuntime( 2981):    ... 10 more
W/ActivityManager( 1525):   Force finishing activity 1 com.example.cdrandin.androidapp/.SelectedDevice
W/ActivityManager( 1525):   Force finishing activity 2 com.example.cdrandin.androidapp/.MainActivity
I/OpenGLRenderer( 1525): Initialized EGL, version 1.4
I/art     ( 1993): Background sticky concurrent mark sweep GC freed 9534(828KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 8MB/9MB, paused 10.492ms total 82.320ms
W/EGL_emulation( 1525): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 1525): Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f271a8da9c0, error=EGL_SUCCESS
W/ActivityManager( 1525): Activity pause timeout for ActivityRecord{15693637 u0 com.example.cdrandin.androidapp/.SelectedDevice t64 f}
W/EGL_emulation( 1838): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 1838): Failed to set EGL_SWAP_BEHAVIOR on surface 0xf43d7d20, error=EGL_SUCCESS
W/ResourceType( 1647): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1647): Failure retrieving resources for com.example.cdrandin.androidapp: Resource ID #0x0
W/OpenGLRenderer( 1838): Incorrectly called buildLayer on View: aep, destroying layer...
W/AudioTrack( 1525): AUDIO_OUTPUT_FLAG_FAST denied by client
I/Process ( 2981): Sending signal. PID: 2981 SIG: 9
I/WindowState( 1525): WIN DEATH: Window{213957e5 u0 com.example.cdrandin.androidapp/com.example.cdrandin.androidapp.MainActivity}
I/ActivityManager( 1525): Process com.example.cdrandin.androidapp (pid 2981) has died
D/OpenGLRenderer( 1525): endAllStagingAnimators on 0x7f27263ac400 (RippleDrawable) with handle 0x7f272624c9c0
W/InputMethodManagerService( 1525): Got RemoteException sending setActive(false) notification to pid 2981 uid 10059
I/HotwordRecognitionRnr( 1965): Starting hotword detection.
I/MicrophoneInputStream( 1965): mic_starting gzi@1c2c0f5b
E/audio_hw_generic( 1134): Error opening input stream format 1, channel_mask 0010, sample_rate 16000
I/AudioFlinger( 1134): AudioFlinger's thread 0xf5969000 ready to run
I/MicrophoneInputStream( 1965): mic_started gzi@1c2c0f5b
I/HotwordWorker( 1965): onReady
W/IcingInternalCorpora( 2204): getNumBytesRead when not calculated.
I/Icing   ( 2204): Usage reports 0 indexed 0 rejected 0 imm upload true
W/AudioFlinger( 1134): write blocked for 382 msecs, 3 delayed writes, thread 0xf58ac000
Matthias247 commented 7 years ago

Now that I once again look through the issues I think you have an issue with static initialization order: WampTasks _ourInstance is initialized and the WampTasks() constructor code is called before _host and _port are initialized. Therefore the formatted uri is garbage. Should also be easily checkable in the debugger.