使用AppEngine通信错误重启Android

时间:2012-01-23 14:03:58

标签: android google-app-engine restlet

我遇到与http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2838513

相同的问题

我试图通过GAE和android之间的通信来创建一个非常简单的应用程序而且我面临同样的问题。

我有2.1快照(2012-01-15)Android版本 我有2.1快照(2012-01-15)gae版本

在android的classPath中我有:

  • org.restlet.ext.jackson
  • org.restlet
  • 杰克逊all.1.9.3

我的GAE应用程序共享源文件夹用于共享资源和bean

在GAE的classPath中我有:  * org.restlet.ext.jackson  * org.restlet.ext.json  * org.restlet.ext.servlet  * org.restlet  * jackson-all.1.9.3

这是我的web.xml:

<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.binomed.server.rest.RestletApplication</param-value>
</init-param>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

以下是共享代码:



    package com.binomed.client.rest;
    import org.restlet.resource.Get;
    import com.binomed.client.rest.dto.RestletObjectA;

    public interface IRestletService {

    @Get
    RestletObjectA getMessage() throws Exception;

    }

    package com.binomed.client.rest.dto;

    import java.io.Serializable;
    import java.util.List;

    public class RestletObjectA implements Serializable {



    /**
    * 
    */
    private static final long serialVersionUID = 1L;



    public RestletObjectA() {
    super();
    }



    private RestletObjectB objectB;

    private List listObjectB;

    private String name;


    public RestletObjectB getObjectB() {
    return objectB;
    }


    public void setObjectB(RestletObjectB objectB) {
    this.objectB = objectB;
    }


    public List getListObjectB() {
    return listObjectB;
    }



    public void setListObjectB(List listObjectB) {
    this.listObjectB = listObjectB;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    }

    package com.binomed.client.rest.dto;

    import java.io.Serializable;

    public class RestletObjectB implements Serializable {



    /**
    * 
    */
    private static final long serialVersionUID = 1L;

    public RestletObjectB() {
    super();
    }

    private String name;

    public String getName() {
    return name;
    }



    public void setName(String name) {
    this.name = name;
    }

    }


以下是我的服务的实施:



    package com.binomed.server.rest;

    import java.util.ArrayList;

    import org.restlet.resource.Get;
    import org.restlet.resource.ServerResource;

    import com.binomed.client.rest.IRestletService;
    import com.binomed.client.rest.dto.RestletObjectA;
    import com.binomed.client.rest.dto.RestletObjectB;

    public class RestResource extends ServerResource implements IRestletService {



    @Override
    @Get
    public RestletObjectA getMessage() throws Exception {
    RestletObjectB objB = new RestletObjectB();
    objB.setName("ObjectB");

    RestletObjectA result = new RestletObjectA();
    result.setName("ObjectA");
    result.setListObjectB(new ArrayList());
    result.getListObjectB().add(objB);
    result.setObjectB(objB);

    return result;
    }

    }




    package com.binomed.server.rest;

    import org.restlet.Application;
    import org.restlet.Restlet;
    import org.restlet.routing.Router;

    public class RestletApplication extends Application {



    /**
    * Creates a root Restlet that will receive all incoming calls.
    */
    @Override
    public Restlet createInboundRoot() {
    // Create a router Restlet that routes each call to a
    // new instance of HelloWorldResource.
    Router router = new Router(getContext());

    // Defines only one route
    // router.attachDefault(new Directory(getContext(), "war:///"));
    // router.attach("/test/", RestResource.class);
    router.attachDefault(RestResource.class);

    return router;
    }

    }


如果我尝试使用网址:http://localhost:8888/rest/它有效,我有 {“objectB”:{“name”:“ObjectB”},“listObjectB”:[{“name”:“ObjectB”}],“name”:“ObjectA”}作为返回,完全正常。

这是我的android代码:



    // Use an AsyncTask to avoid blocking the UI thread
    new AsyncTask() {

    @Override
    protected RestletObjectA doInBackground(Void... arg0) {
    try {
    return RestletAccesClass.callService();
    } catch (Exception e) {
    Log.e(TAG, "Error during calling rest server", e);
    return null;
    }
    }
    @Override
    protected void onPostExecute(RestletObjectA result) {
    if (result != null) {
    restlet.setText(result.getName() + ", B : " + result.getObjectB().getName());
    } else {
    restlet.setText("Failure during getting result");
    }
    btnRestlet.setEnabled(true);
    }
    }.execute();


and : 
    

    public static RestletObjectA callService() throws Exception {
    ClientResource clientResource = new ClientResource(TestRpcAndroidActivity.LOCALHOST + "/rest/");

    IRestletService service = clientResource.wrap(IRestletService.class);
    RestletObjectA result = service.getMessage();
    return result;
    }

使用android项目我总是有以下错误:

01-23 14:09:12.594: E/TestAndroidActivity(1620): Error during calling rest server
01-23 14:09:12.594: E/TestAndroidActivity(1620): Communication Error (1001) - The connector failed to complete the communication with the server
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at org.restlet.resource.ClientResource.doError(ClientResource.java:579)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at org.restlet.engine.resource.ClientInvocationHandler.invoke(ClientInvocationHandler.java:233)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at $Proxy5.getMessage(Native Method)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at com.binomed.android.rpc.rest.RestletAccesClass.callService(RestletAccesClass.java:14)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at com.binomed.android.rpc.TestRpcAndroidActivity$3.doInBackground(TestRpcAndroidActivity.java:153)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at com.binomed.android.rpc.TestRpcAndroidActivity$3.doInBackground(TestRpcAndroidActivity.java:1)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
01-23 14:09:12.594: E/TestAndroidActivity(1620):    at java.lang.Thread.run(Thread.java:1096)

您对如何解决此问题有任何想法吗?

问候

1 个答案:

答案 0 :(得分:1)

您是否可以尝试添加基于Apache HTTP Client的客户端连接器而不是内部连接器(尚未完全稳定)?请参阅此处的说明 http://wiki.restlet.org/docs_2.1/13-restlet/275-restlet/266-restlet.html

请注意,我们打算在此连接器上修复2.1.0的稳定性问题。