【发布时间】: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