gpt4 book ai didi

android - 带有 AppEngine 通信错误的 ReSTLet Android

转载 作者:行者123 更新时间:2023-11-30 04:23:06 26 4
gpt4 key购买 nike

我有同样的问题:http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2838513

我尝试制作一个非常简单的应用程序,在 GAE 和 android 之间进行通信,但我遇到了同样的问题。

我有 2.1 Snapshot (2012-01-15) android 版本我有 2.1 Snapshot (2012-01-15) gae 版本

在android的类路径中我有:

  • org.reSTLet.ext.jackson
  • 组织.reSTLet
  • jackson-all.1.9.3

我有一个与我的 GAE 应用程序共享的源文件夹,用于共享资源和 bean

在 GAE 的类路径中,我有: * org.reSTLet.ext.jackson * 组织.reSTLet.ext.json * org.reSTLet.ext.servlet * 组织.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;
}

}

And here is the implementation of my service :



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;
}

}

and



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;
}

}

If I try the url : http://localhost:8888/rest/ it works, I have {"objectB":{"name":"ObjectB"},"listObjectB":[{"name":"ObjectB"}],"name":"ObjectA"} as return which is totaly normal.

Here is my android code :



// 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 server01-23 14:09:12.594: E/TestAndroidActivity(1620): Communication Error (1001) - The connector failed to complete the communication with the server01-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)

你知道如何解决这个问题吗?

问候

最佳答案

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

请注意,我们打算解决 2.1.0 连接器的稳定性问题。

关于android - 带有 AppEngine 通信错误的 ReSTLet Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8972848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com