我无法让Android上的Restlet工作。我有相同的jar,相同的生成类等我在普通Java中使用(它在那里工作)。问题似乎与HttpClientHelper有关。
我也读过这个:http://wiki.restlet.org/docs_2.1/13-restlet/275-restlet/266-restlet.html。
这是我的代码:
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());
}
这是追踪:
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's 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's 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)
我还尝试导入org.restlet.ext.httpclient.HttpClientHelper(以及Eclipse建议的任何其他HttpClientHelper),这会产生略微不同的痕迹:
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.
我不知道还能做什么,如果有人有一个正在运行的Restlet / oData android项目,也许他/她可以给我一个提示?