Objectify + Eclipse +生成Cloud Endpoint客户端库:“变量不符合样式指南”

时间:2014-07-16 13:34:58

标签: android eclipse google-app-engine google-cloud-endpoints objectify

我正在使用的内容:Eclipse,Java,Objectify,Google App Engine SDK

如果这个问题已经解决,我很抱歉。但我找不到任何解决方案。情况如下:

我尝试了大约3个星期的时间来完成我的项目。起初,我有一个Android项目。然后,使用Google Eclipse插件,我生成了一个App Engine后端(在Eclipse上)并开始使用JPA。但是,我在关系方面遇到了太多问题。我只是浪费时间和耐心。所以,我决定转向客观化。

我按照Objectify文档的所有步骤构建了我的类。我定义了我的端点,用新的代码替换了之前的代码(使用JPA)。 objectify和guava jar都在WEB-INF / lib和构建路径中。

问题:当我尝试生成Cloud Endpoint客户端库时,我收到此错误:

为您的Cloud Endpoints类生成API元数据时出现问题:

com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 
400 Bad Request
{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}} 

错误日志:

java.lang.reflect.InvocationTargetException
    at com.google.gdt.eclipse.appengine.swarm.wizards.GenerateSwarmApiAction$1.run(GenerateSwarmApiAction.java:82)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmGenerationException: com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 400 Bad Request
{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}}
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createClientLibFromApiConfig(SwarmApiCreator.java:144)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createSwarmApi(SwarmApiCreator.java:258)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmServiceCreator.create(SwarmServiceCreator.java:444)
    at com.google.gdt.eclipse.appengine.swarm.wizards.GenerateSwarmApiAction$1.run(GenerateSwarmApiAction.java:80)
    ... 1 more
Caused by: com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 400 Bad Request
{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}}
    at com.google.appengine.repackaged.com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
    at com.google.api.server.spi.tools.CloudClientLibGenerator.postRequest(CloudClientLibGenerator.java:53)
    at com.google.api.server.spi.tools.CloudClientLibGenerator.generateClientLib(CloudClientLibGenerator.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createClientLibFromApiConfig(SwarmApiCreator.java:142)
    ... 4 more
Root exception:
com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmGenerationException: com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 400 Bad Request
{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}}
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createClientLibFromApiConfig(SwarmApiCreator.java:144)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createSwarmApi(SwarmApiCreator.java:258)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmServiceCreator.create(SwarmServiceCreator.java:444)
    at com.google.gdt.eclipse.appengine.swarm.wizards.GenerateSwarmApiAction$1.run(GenerateSwarmApiAction.java:80)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 400 Bad Request
{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}}
    at com.google.appengine.repackaged.com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
    at com.google.api.server.spi.tools.CloudClientLibGenerator.postRequest(CloudClientLibGenerator.java:53)
    at com.google.api.server.spi.tools.CloudClientLibGenerator.generateClientLib(CloudClientLibGenerator.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createClientLibFromApiConfig(SwarmApiCreator.java:142)
    ... 4 more

一些例子(包括实体注册)。我会压制包裹,进口和吸气/装置。如果有人知道如何提供帮助,我将非常感激。如果有任何代码我应该放在这里,请告诉我。

User.java

@Entity
    public class User {
    @Id
    private Long id;

    private String name;

    @Index
    private PhoneNumber phoneNumber;

    private String friendCode;

    @Load
    private List<Ref<Group>> groups = new ArrayList<Ref<Group>>(); //groups that a User can be simple member

    //...
    }

Group.java

@Entity
public class Group {
    @Id
    private Long id;

    @Index(IfNotNull.class)
    private String name;

    @Load
    @Index
    private Ref<User> owner; // Owner of the group. The creator.

OfyService.java

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;

public class OfyService {
    static {
        factory().register(Group.class);
        factory().register(User.class);      
    }

    public static Objectify ofy() {
        return ObjectifyService.ofy();
    }

    public static ObjectifyFactory factory() {
        return ObjectifyService.factory();
    }
}

UserEndpoint.java

import static com.uandq.lychee.OfyService.ofy;
@Api(name = "sampleEndpoint", namespace = @ApiNamespace(ownerDomain = "sample.com", ownerName = "sample.com", packagePath = ""))
public class UserEndpoint {


    @ApiMethod(name = "listUser")
    public List<User> listUser() {
        List<User> result = new ArrayList<User>();
        result = ofy().load().type(User.class).list();
        return result;
    }

    @ApiMethod(name = "getUser")
    public User getUser(@Named Long id) {
        User user = ofy().load().type(User.class).id(id).now();
        return user;
    }

    @ApiMethod(name = "insertUser")
    public User insertUser(User user) {
        ofy().save().entity(user).now();
        return user;
    }

    @ApiMethod(name = "removeUser")
    public void removeUser(@Named Long id) {
        ofy().delete().type(User.class).id(id).now();
    }

    @ApiMethod(name = "findUserByPhoneNumber")
    public User findUserByPhoneNumber(PhoneNumber phone) {

        User user = ofy().load().type(User.class)
                .filter("phoneNumber ==", phone).first().now();

        return user;
    }
}

GroupEndpoint.java

import static com.uandq.lychee.OfyService.ofy;

@Api(name = "sampleEndpoint", namespace = @ApiNamespace(ownerDomain = "sample.com", ownerName = "sample.com", packagePath = ""))
public class GroupEndpoint {

    @ApiMethod(name = "listGroup")
    public List<Group> listGroup() {
        List<Group> result = new ArrayList<Group>();
        result = ofy().load().type(Group.class).list();
        return result;
    }

    @ApiMethod(name = "getGroup")
    public Group getGroup(@Named Long id) {
        Group group = ofy().load().type(Group.class).id(id).now();
        return group;
    }

    @ApiMethod(name = "insertGroup")
    public Group insertGroup(Group group) {
        ofy().save().entity(group).now();
        return group;
    }

    @ApiMethod(name = "removeGroup")
    public void removeGroup(@Named Long id) {
        ofy().delete().type(Group.class).id(id).now();
    }

}

的web.xml

<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app version="2.5">
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet
        </servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>com.sample.GroupEndpoint, com.sample.UserEndpoint</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>ObjectifyFilter</filter-name>
        <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ObjectifyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

此外,我现在尝试按照以下步骤生成Endpoint库: 使用endpoints.sh为Android生成客户端库 通过终端。它也不起作用。我还是得到了:

Error: 400 Bad Request

{"error": {"message": "Bad Request", "code": 400, "errors": [{"message": "api exception", "debug_info": "Variable  does not conform to style guide"}]}}

欢迎任何帮助。 问题也发布在https://groups.google.com/forum/?hl=en-GB#!topic/objectify-appengine/981f4LlXscg

1 个答案:

答案 0 :(得分:3)

现在的问题是解决了。

解决方案:https://groups.google.com/forum/?hl=en-GB#!topic/objectify-appengine/981f4LlXscg

我发现了问题。实际上我跟踪了这​​个链接https://cloud.google.com/developers/articles/google-cloud-endpoints-for-android上的所有内容。然后,有:

  

大多数参数类型必须是可序列化的,因为JSON需要这样做   对象是可序列化的。您也可以使用任何JavaBean   包括模型中的任何内容,因为模型对象应该是   符合上面描述的JavaBean标准。   一组有限的   类型无需序列化,但必须使用@Named注释。   这些是类型:String,int / Integer,boolean / Boolean,long / Long。

在我的端点中,一些参数以错误的方式使用注释@Named:没​​有参数的实际名称。我甚至不需要实现Serializable。我刚换了:

public User getUser(@Named Long id)

通过

public User getUser(@Named("id") Long id)

所有其他@Named参数。现在我能够生成端点库。