I just can't get Restlet on Android to work. I have the same banks, the same generated classes, etc., which I use in simple Java (it works there). The problem seems to be related to the HttpClientHelper.
I also read this: http://wiki.restlet.org/docs_2.1/13-restlet/275-restlet/266-restlet.html .
Here is my code:
import netflix.catalog.v2.Genre; import org.restlet.engine.Engine; import org.restlet.ext.net.HttpClientHelper; import org.restlet.ext.odata.Query; Engine.getInstance().getRegisteredClients().clear(); Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null)); SystemDataObjectsService service = new SystemDataObjectsService(); Query<Genre> query = service.createGenreQuery("/Genres"); for (Genre g : query) { Log.d(TAG, g.getName()); }
Here's the trace:
11-16 13:02:31.915: I/org.restlet(1344): Starting the HTTP client 11-16 13:02:31.924: I/org.restlet(1344): A recoverable error was detected (1001), attempting again in 2000 ms. 11-16 13:02:33.935: I/org.restlet(1344): A recoverable error was detected (1001), attempting again in 2000 ms. 11-16 13:02:35.955: E/org.restlet(1344): Can't get the metadata for http://odata.netflix.com/v2/Catalog/ (response status: Communication Error (1001) - The connector failed to complete the communication with the server) 11-16 13:02:35.965: W/org.restlet(1344): Can't parse the content of http://odata.netflix.com/v2/Catalog/Genres 11-16 13:02:35.965: W/org.restlet(1344): java.lang.Exception: Can't execute the query without the service metadata. 11-16 13:02:35.965: W/org.restlet(1344): at org.restlet.ext.odata.Query.execute(Query.java:350) 11-16 13:02:35.965: W/org.restlet(1344): at org.restlet.ext.odata.Query.iterator(Query.java:645) 11-16 13:02:35.965: W/org.restlet(1344): at net.ascorbin.locaspo.MainActivity$LoginTask.doInBackground(MainActivity.java:74) 11-16 13:02:35.965: W/org.restlet(1344): at net.ascorbin.locaspo.MainActivity$LoginTask.doInBackground(MainActivity.java:1) 11-16 13:02:35.965: W/org.restlet(1344): at android.os.AsyncTask$2.call(AsyncTask.java:264) 11-16 13:02:35.965: W/org.restlet(1344): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 11-16 13:02:35.965: W/org.restlet(1344): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 11-16 13:02:35.965: W/org.restlet(1344): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) 11-16 13:02:35.965: W/org.restlet(1344): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 11-16 13:02:35.965: W/org.restlet(1344): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 11-16 13:02:35.965: W/org.restlet(1344): at java.lang.Thread.run(Thread.java:856) 11-16 13:02:35.965: W/dalvikvm(1344): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
I also tried importing org.restlet.ext.httpclient.HttpClientHelper (and any other HttpClientHelper that Eclipse offers) that lead to a slightly different trace:
11-16 13:06:27.775: I/org.restlet(1446): Get the metadata for http://odata.netflix.com/v2/Catalog/ at http://odata.netflix.com/v2/Catalog/$metadata 11-16 13:06:27.815: I/org.restlet(1446): Starting the HTTP client 11-16 13:06:27.836: W/org.restlet(1446): An error occurred during the communication with the remote HTTP server. 11-16 13:06:27.836: W/org.restlet(1446): java.net.UnknownHostException: Unable to resolve host "odata.netflix.com": No address associated with hostname 11-16 13:06:27.836: W/org.restlet(1446): at java.net.InetAddress.lookupHostByName(InetAddress.java:400) 11-16 13:06:27.836: W/org.restlet(1446): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242) 11-16 13:06:27.836: W/org.restlet(1446): at java.net.InetAddress.getAllByName(InetAddress.java:220) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 11-16 13:06:27.836: W/org.restlet(1446): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.ext.httpclient.internal.HttpMethodCall.sendRequest(HttpMethodCall.java:335) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.engine.http.adapter.ClientAdapter.commit(ClientAdapter.java:120) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.engine.http.HttpClientHelper.handle(HttpClientHelper.java:113) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.Client.handle(Client.java:180) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.handle(ClientResource.java:944) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.handle(ClientResource.java:912) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.handle(ClientResource.java:867) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.handle(ClientResource.java:892) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.handle(ClientResource.java:801) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.resource.ClientResource.get(ClientResource.java:544) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.ext.odata.Service.getMetadata(Service.java:483) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.ext.odata.Query.<init>(Query.java:232) 11-16 13:06:27.836: W/org.restlet(1446): at org.restlet.ext.odata.Service.createQuery(Service.java:277) 11-16 13:06:27.836: W/org.restlet(1446): at net.ascorbin.locaspo.SystemDataObjectsService.createGenreQuery(SystemDataObjectsService.java:87) 11-16 13:06:27.836: W/org.restlet(1446): at net.ascorbin.locaspo.MainActivity$LoginTask.doInBackground(MainActivity.java:71) 11-16 13:06:27.836: W/org.restlet(1446): at net.ascorbin.locaspo.MainActivity$LoginTask.doInBackground(MainActivity.java:1) 11-16 13:06:27.836: W/org.restlet(1446): at android.os.AsyncTask$2.call(AsyncTask.java:264) 11-16 13:06:27.836: W/org.restlet(1446): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 11-16 13:06:27.836: W/org.restlet(1446): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 11-16 13:06:27.836: W/org.restlet(1446): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) 11-16 13:06:27.836: W/org.restlet(1446): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 11-16 13:06:27.836: W/org.restlet(1446): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 11-16 13:06:27.836: W/org.restlet(1446): at java.lang.Thread.run(Thread.java:856) 11-16 13:06:27.836: I/org.restlet(1446): A recoverable error was detected (1001), attempting again in 2000 ms.
I do not know what else to do if someone has a working project-restart / oData-android, maybe he / she can give me a hint?
source share