X

Pavel Bucek's Weblog

  • January 21, 2014

WebSocket Client on Android – Tyrus

Running some Java EE libraries or frameworks in non-standard VM is not an uncommon task and same is for Tyrus. I have to admit that this task was driven mainly by issue report TYRUS-256 from Reza. There is no official support from Tyrus running on Dalvik and I'm not even sure if it is a good idea, but important fact is that it works and you can do it if you want :-).

Whole issue which blocked runtime from being able to run on Android was in usage of javax.naming.InitialContext class. There is no simple alternative to it, but fortunately there is always a possibility to do little bit of reflection hacking to get rid of the dependency if it's not there. The rest was only about creating the sample application and testing it on my phone, which was not that hard. I have to give kudos to IntelliJ IDEA team for their support, but not for Android Studio - it uses gradle as build tool and it seems like you cannot include java library because android plugin clashes with java plugin (I'm not very familiar with gradle as you might have noticed). Using and build script and build in support was better for my task.

The application I used for testing is available on github in my personal workspace: https://github.com/pavelbucek/tyrus-client-android-test. Feel free to test it and/or provide pull requests. I would be particularly interested in gradle build script.

That's it for today. If you are using Tyrus on Android or if you have any related comments, please share them with us on Tyrus mailing list or as an enhancement request.

Join the discussion

Comments ( 9 )
  • Marcelo Monday, January 27, 2014

    Pretty cool stuff Pavel! I forked the repo and got this running in no time.


  • Binod Tuesday, April 8, 2014

    which version of Android have you tested this with? Is Tyrus written in Java 6 or Java 7? If it is written in Java 6, older android versions would work too.


  • Pavel Tuesday, April 8, 2014

    Hi Binod,

    this example was tested on Android v4.4.2, but the client bundle used there is usable on JDK 1.6+, so it should be possible to use it on older Android platform; we did not tested that though, so there might be some issues. If you find anything related, please file it against Tyrus on its JIRA: https://java.net/jira/browse/TYRUS.

    Thanks and regards,

    Pavel


  • guest Wednesday, October 8, 2014

    I have been trying to run your example but run into problems.

    I am using the latest tyrus-standalone-client-1.8.3.jar - on the call to ClientManager.createClient(); the log reports...

    ### 0 Button.onClick

    Failed resolving Lorg/glassfish/tyrus/core/OsgiRegistry; interface 2482 'Lorg/osgi/framework/SynchronousBundleListener;'

    Link of class 'Lorg/glassfish/tyrus/core/OsgiRegistry;' failed

    Could not find method org.glassfish.tyrus.core.OsgiRegistry.getInstance, referenced from method org.glassfish.tyrus.core.ReflectionHelper.getOsgiRegistryInstance

    unable to resolve static method 17086: Lorg/glassfish/tyrus/core/OsgiRegistry;.getInstance ()Lorg/glassfish/tyrus/core/OsgiRegistry;

    There are other issues reported to the subsequent connect attempt but these are likely a result of the initial problem.

    Is this a known issue or should I create a JIRA issue?

    Geoff.


  • Pavel Wednesday, October 8, 2014

    Hi Geoff,

    seems like we introduced some regression in latest 1.8.x branch. Can you please retry with Tyrus 1.8?

    And yes, please file this as an issue against Tyrus: https://java.net/jira/browse/TYRUS

    Thanks!

    Pavel


  • guest Friday, October 24, 2014

    Pavel,

    I have come across with the similar problem reported by Geoff in android for ClientManager.

    Could you share the binaries of the fixed ones, so that I will try with my android project. I am not sure how to download the tyrus jar files for the version 1.9

    Kindly do the needful. Thanks.

    regards,

    Sudhakar


  • Pavel Friday, October 24, 2014
  • guest Thursday, April 16, 2015

    I get the same exception stated above with tyrus-standalone-client-1.10, 1.9, 1.8.3:

    Failed resolving Lorg/glassfish/tyrus/core/OsgiRegistry; interface 4566 'Lorg/osgi/framework/SynchronousBundleListener;'

    04-16 21:31:42.917 W/dalvikvm(24181): Link of class 'Lorg/glassfish/tyrus/core/OsgiRegistry;' failed

    04-16 21:31:42.917 I/dalvikvm(24181): Could not find method org.glassfish.tyrus.core.OsgiRegistry.getInstance, referenced from method org.glassfish.tyrus.core.ReflectionHelper.getOsgiRegistryInstance

    04-16 21:31:42.917 W/dalvikvm(24181): VFY: unable to resolve static method 35259: Lorg/glassfish/tyrus/core/OsgiRegistry;.getInstance ()Lorg/glassfish/tyrus/core/OsgiRegistry;

    04-16 21:31:42.917 D/dalvikvm(24181): VFY: replacing opcode 0x71 at 0x0008

    04-16 21:31:42.917 I/dalvikvm(24181): Failed resolving Lorg/glassfish/tyrus/core/OsgiRegistry; interface 4566 'Lorg/osgi/framework/SynchronousBundleListener;'

    04-16 21:31:42.917 W/dalvikvm(24181): Link of class 'Lorg/glassfish/tyrus/core/OsgiRegistry;' failed

    04-16 21:31:42.917 W/dalvikvm(24181): VFY: unable to find class referenced in signature (Lorg/glassfish/tyrus/core/OsgiRegistry;)

    04-16 21:31:42.917 D/dalvikvm(24181): VFY: dead code 0x000b-000b in Lorg/glassfish/tyrus/core/ReflectionHelper;.getOsgiRegistryInstance ()Lorg/glassfish/tyrus/core/OsgiRegistry;

    Any suggestions on which stable version to use?


  • Pavel Thursday, April 16, 2015

    Hey guest,

    that exception is just logged - you should be able to suppress that log message, it's harmless.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha