【问题标题】:understanding of google-cloud-endpoints?了解谷歌云端点?
【发布时间】:2015-05-02 06:46:45
【问题描述】:

云端点。
我正在关注 Udacity 教程。我对请求和响应的流程有点困惑,以下是我的理解
端点应该用 @Api 注释,端点方法用注释@ApiMethod 并且这些方法不应该返回原始数据类型。下面是一个端点方法

@ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST)

public Profile saveProfile(ProfileForm profileForm) throws UnauthorizedException {

    String userId = null;
    String mainEmail = null;
    String displayName = "Your name will go here";
    TeeShirtSize teeShirtSize = TeeShirtSize.NOT_SPECIFIED;

    if(profileForm.getTeeShirtSize() != null)
        teeShirtSize = profileForm.getTeeShirtSize();

    displayName = profileForm.getDisplayName();

    Profile profile = new Profile(userId, displayName, mainEmail, teeShirtSize);

    return profile;
}


以下是我的 ProfileForm 和 Profile 类

public class ProfileForm {
private String displayName;

private TeeShirtSize teeShirtSize;

private ProfileForm () {}

    public ProfileForm(String displayName, TeeShirtSize teeShirtSize) {
    this.displayName = displayName;
    this.teeShirtSize = teeShirtSize;
}

public String getDisplayName() {
    return displayName;
}

public TeeShirtSize getTeeShirtSize() {
    return teeShirtSize;
}

public static enum TeeShirtSize {
    NOT_SPECIFIED,
    XS,
    S,
    M,
    L, 
    XL, 
    XXL,
    XXXL
  }
}


public class Profile {
String displayName;
String mainEmail;
TeeShirtSize teeShirtSize;


String userId;

    public Profile (String userId, String displayName, String mainEmail, TeeShirtSize teeShirtSize) {
    this.userId = userId;
    this.displayName = displayName;
    this.mainEmail = mainEmail;
    this.teeShirtSize = teeShirtSize;
}

public String getDisplayName() {
    return displayName;
}

public String getMainEmail() {
    return mainEmail;
}

public TeeShirtSize getTeeShirtSize() {
    return teeShirtSize;
}

public String getUserId() {
    return userId;
}

    private Profile() {}

}

这里ProfileForm 是请求参数,Profile 是响应。我部署在 locahost 中,并使用下面的 url 我测试了
http://localhost:8080/_ah/api/explorer 在请求正文中,我添加了两个参数作为 displayName,teeShirtSize 那么任何人都可以解释为什么我得到响应为 404 吗?下面是屏幕截图

据我了解,我不需要加载 appengine client.js,因为我没有在网页中进行测试。我正在 api-explorer 中进行测试。请说明调用 google-cloud-endpoint 时如何生成响应?
谢谢

【问题讨论】:

  • 你能发布你的 ProfileForm 代码吗?
  • @Eliot 感谢您的回复,现在我添加了 ProfileForm 和 Profile 类。
  • 您的 GAE 服务器中是否有任何日志显示您确实到达了端点?
  • 不,我没有得到任何日志。

标签: java google-app-engine google-cloud-endpoints


【解决方案1】:

我使用 1.9.3 版本的 google-app-engine ,然后我更改为 1.9.20 现在它工作正常。我仍然在思考为什么它在 1.9.3 中不起作用?
谢谢

【讨论】:

    【解决方案2】:

    很可能(但不确定,因为我没有看到您的 @Api 注释)它不起作用,因为您在注释中设置了 root 参数。最近有一些变化使得 API 浏览器总是尊重根,这破坏了本地开发体验。最近的 SDK 版本对此进行了更改以使其再次工作。如果您注意到,您的资源管理器屏幕截图会显示:

    POST https://your-app-id.appspot.com/_ah/api/conference/v1/profile

    应该在哪里写:

    POST http://localhost:8080/_ah/api/conference/v1/profile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-27
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多