Android Studio中的AppEngine端点不包括建设者 [英] Android Studio appengine endpoint does not include builder

查看:308
本文介绍了Android Studio中的AppEngine端点不包括建设者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我AndroidStudio项目我有两个模块:应用程序,这是Android组件和API是应用程序引擎模块。通过在AndroidStudio创建一个端点应用程序引擎模块生成的应用程序引擎模块API。

In my AndroidStudio project I have two modules: app, which is the android module and api which is the app-engine module. The App-Engine module api was generated by creating an Endpoints App Engine Module in AndroidStudio.

我有一个从客观化注解的类名为评论生成的端点类。

I have an Endpoint class generated from an objectify annotated class called Comment.

package com.example.pontuse.api;

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

/**
 * Created by pontuse on 2014-09-08.
 */
@Entity
public class Comment {
    @Id
    Long id;
    String who;
    String txt;

    public Comment() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getWho() {
        return who;
    }

    public void setWho(String who) {
        this.who = who;
    }

    public String getTxt() {
        return txt;
    }

    public void setTxt(String txt) {
        this.txt = txt;
    }
}

后来我产生一个端点从类调用CommentEndpoint通过点击工具>谷歌云工具>生成端点

Later on I generated an Endpoint called CommentEndpoint from the class by hitting Tools > Google Cloud Tools > Generate Endpoint

package com.example.pontuse.api;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.config.Nullable;
import com.google.api.server.spi.response.CollectionResponse;
import com.google.api.server.spi.response.ConflictException;
import com.google.api.server.spi.response.NotFoundException;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator;
import com.googlecode.objectify.cmd.Query;

import static com.example.pontuse.api.OfyService.ofy;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.inject.Named;
import javax.xml.ws.Endpoint;

/** An endpoint class we are exposing */
@Api(name = "commentEndpoint", version = "v1", namespace = @ApiNamespace(ownerDomain = "api.pontuse.example.com", ownerName = "api.pontuse.example.com", packagePath=""))
public class CommentEndpoint{

    // Make sure to add this endpoint to your web.xml file if this is a web application.

    private static final Logger LOG = Logger.getLogger(CommentEndpoint.class.getName());

    public CommentEndpoint(){

    }

    @ApiMethod(name = "listComment")
    public CollectionResponse<Comment> listComment(@Nullable @Named("cursor") String cursorString,
                                                   @Nullable @Named("count") Integer count) {
        Query<Comment> query = ofy().load().type(Comment.class);
        if (count != null) query.limit(count);
        if (cursorString != null && cursorString != "") {
            query = query.startAt(Cursor.fromWebSafeString(cursorString));
        }
        LOG.info("Calling listComment method");
        List<Comment> records = new ArrayList<Comment>();
        QueryResultIterator<Comment> iterator = query.iterator();
        int num = 0;
        while (iterator.hasNext()) {
            records.add(iterator.next());
            if (count != null) {
                num++;
                if (num == count) break;
            }
        }

        if (cursorString != null && cursorString != "") {
            Cursor cursor = iterator.getCursor();
            if (cursor != null) {
                cursorString = cursor.toWebSafeString();
            }
        }

        return CollectionResponse.<Comment>builder().setItems(records).setNextPageToken(cursorString).build();
    }

    /**
     * This inserts a new <code>Comment</code> object.
     * @param comment The object to be added.
     * @return The object to be added.
     */
    @ApiMethod(name = "insertComment")
    public Comment insertComment(Comment comment) throws ConflictException{
        if(comment.getId() != null)
            if(findRecord(comment.getId()) != null) throw new ConflictException("Object already exists");
        LOG.info("Calling insertComment method");
        ofy().save().entity(comment).now();
        return comment;
    }

    @ApiMethod (name = "updateComment")
    public Comment updateComment(Comment comment) throws NotFoundException{
        if(findRecord(comment.getId()) == null) throw new NotFoundException("Object does not exist");
        ofy().save().entity(comment).now();
        return comment;
    }

    @ApiMethod (name = "removeComment")
    public void removeComment(@Named ("id") Long id) throws NotFoundException{
        Comment record = findRecord(id);
        if(record == null) throw new NotFoundException("Comment record does not exist!");
        LOG.info("Calling removeComment method");
        ofy().delete().entity(record).now();
    }

    private Comment findRecord(Long id){
        return ofy().load().type(Comment.class).id(id).now();
    }
}

当我尝试在我的应用程序模块创建的AsyncTask做到这一点的Andr​​oid应用程序可以使用App-Engine后端工作,我所需要的端点成员类生成器应该被实例化这样

When I try to create an AsyncTask in my app module do that the Android Application can work with the App-Engine Backend I need the Endpoints member class Builder which should be instantiated like this

CommentEndpoint.Builder builder = new CommentEndpoint.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)

但IDE告诉我,有作为CommentEndpoint.Builder没有这样的事情。我用Google搜索<一个href=\"http://stackoverflow.com/questions/16726745/endpoint-builder-missing-for-generated-cloud-endpoint\">this问题但无济于事,由于Android工作室的作品与现在,而不是在应用程序引擎和Android应用两个独立的项目在同一项目中两个模块。
我错过了什么?

But the IDE tells me there is no such thing as CommentEndpoint.Builder. I googled this question but to no avail, since Android Studio works with two modules in the same project now and not in two separate projects for the app-engine and android application. Have I missed something?

推荐答案

我刚刚安装为0.8.9,并开始对涉及GAE的一个项目工作。
我有同样的问题,建设者没有确定。

I just recently installed AS 0.8.9 and began to work on a project involving GAE. I had this same problem with 'builder not identified'.

什么固定它,我被删除你的情况:

What fixed it for me was deleting the "in your case":

import com.example.pontuse.api.CommentEndpoint;

和重新导入它,它更改为

and re importing it which changed it to

import com.example.pontuse.api.commentEndpoint.CommentEndpoint;

添加依赖时,这一定是一个错误。
希望这有助于。

this must be a bug when adding the dependency. Hope this helps.

这篇关于Android Studio中的AppEngine端点不包括建设者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆