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.

Comments:

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

Posted by Marcelo on January 27, 2014 at 01:31 AM CET #

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.

Posted by Binod on April 08, 2014 at 12:39 PM CEST #

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

Posted by Pavel on April 08, 2014 at 01:34 PM CEST #

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.

Posted by guest on October 08, 2014 at 11:06 PM CEST #

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

Posted by Pavel on October 09, 2014 at 12:29 AM CEST #

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

Posted by guest on October 24, 2014 at 10:35 AM CEST #

Hi Sudhakar,

1.9 final is not ready yet, but you can try 1.9-SNAPSHOT: https://maven.java.net/content/repositories/snapshots/org/glassfish/tyrus/bundles/tyrus-standalone-client/1.9-SNAPSHOT/tyrus-standalone-client-1.9-20141024.085328-6.jar

Regards,
Pavel

Posted by Pavel on October 24, 2014 at 11:15 AM CEST #

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?

Posted by guest on April 16, 2015 at 11:34 PM CEST #

Hey guest,

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

Posted by Pavel on April 16, 2015 at 11:41 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Pavel Bucek-Oracle

Search

Categories
Archives
« July 2015
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today