RESTLET Client for Android 2.2
I am using Android 2.2 phone and the Adroid SDK 2.3.3 (API 10)
And I am trying to use REST Client from my phone using RESTLET for Android following the tutorial 开发者_开发知识库given in RESTLET Tutorial to access the REST Service running on RESTURL But everytime when I install this application both in phone and emulator it crashes with message "Stopped Unexpectedly" and hence Force Close. I have tried to include both org.restlet.ext.httpclient.jar and org.restlet.jar of different RESTLET versions like 2.0.0, 2.0.5, 2.1m2 but the result is always "FORCE CLOSE"
Can anyone please tell me if I am doing something wrong? Any advice also would be fine on Restlful client in Android 2.2
Code:
ClientResource cr = new ClientResource("http://androidgroundapps.appspot.com/rest/contacts/123");
ContactResource resource = cr.wrap(ContactResource.class);
// Get the remote contact
Contact contact = resource.retrieve();
if(contact == null){
toast("Contact is Null buddy!");
}
contact is always null!!
Here is the logcat (my app's name is myapp
):
E/wifi ( 1361): [android_net_wifi_getRssiHelper] rssi -50
I/ActivityManager( 1361): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.androidground
.apps.myapp/.MyApp }
W/Flex ( 1453): getString FLEX_OPERATOR_CODE OPEN
W/System.err( 9188): Starting the internal [HTTP/1.1] client
I/ActivityManager( 1361): Displayed activity com.androidground.apps.myapp/.MyApp: 1414 ms (total 1414 ms)
E/wifi ( 1361): [android_net_wifi_getRssiHelper] rssi -53
W/System.err( 9188): Stopping the internal[HTTP/1.1] client
E/wifi ( 1361): [android_net_wifi_getRssiHelper] rssi -51
E/Tethering( 1361): active iface (usb0) reported as added, ignoring
D/WifiService( 1361): BroadcastReceiver : android.intent.action.BATTERY_CHANGED
Add this in front:
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
But i only get back a LinkedHashMap, i expect an Object of the type (Contact). If you manage that, tell me
Yes I agree with you, this behavior can appear puzzling! The issue is specific to Android since auto discovery for connectors and converters provided by Restlet can't be used in this context. As a matter of fact this is due to a limitation in the way Android repackages JAR files leaving out the descriptor files in the META-INF/services folder.
The solution is to manually register Restlet converters and connectors as described by Nitromouse in its answer.
Thierry
精彩评论