在端点类中创建方法 - Google App Engine

时间:2014-03-07 09:47:13

标签: java android google-app-engine jpa google-cloud-datastore

我是App Engine应用程序开发的新手。我想在我的实体端点类中创建自定义方法。为此,我使用@ApiMethod注释来定义端点类中的自定义方法。问题是,当我从我的Android客户端调用此方法时,它会抛出IOException。我不知道我的代码有什么问题。请指导我。 谢谢。

端点代码:

@Api(name = "feedmasterendpoint", namespace = @ApiNamespace(ownerDomain = "sampleregistrationapp.com", ownerName = "sampleregistrationapp.com", packagePath = ""))
public class FeedMasterEndpoint {

    @SuppressWarnings("unchecked")
        @ApiMethod(name = "getUserFeed", httpMethod = HttpMethod.GET)
        public ArrayList<String> getUserFeed(@Named("userId_fk") String id) {
            EntityManager mgr = null;
            ArrayList<String> feedList = new ArrayList<String>();
            try {
                mgr = getEntityManager();
                Query query = mgr
                        .createQuery("select f.feedUrl from FeedMaster f where f.userId_fk= :userId");
                query.setParameter("userId", id);
                feedList = (ArrayList<String>) query.getResultList();
            } finally {
                mgr.close();
            }
            return feedList;
        }
}

Android客户端代码:

StringCollection urlList = new StringCollection();
Feedmasterendpoint.Builder builder = new Feedmasterendpoint.Builder(
                        AndroidHttp.newCompatibleTransport(),
                        new JacksonFactory(), new HttpRequestInitializer() {
                            public void initialize(HttpRequest arg0)
                                    throws IOException {

                            }
                        });

                Feedmasterendpoint endpoint = CloudEndpointUtils.updateBuilder(
                        builder).build();

                urlList = endpoint.getUserFeed(params[0]).execute(); //It throws IOException

1 个答案:

答案 0 :(得分:0)

经过大量的搜索,我知道可能没有这样的工具可以从app引擎的数据存储区中获取特定列,并解决了这个问题,我获取了整个实体并且它对我有效。