Google 엔드 포인트 및 Google 앱 엔진을 사용하여 Android 애플리케이션을 개발 중입니다. 내 백엔드는 실제로 아무 것도하지 않는 것 같습니다. 아무 것도 데이터 저장소에 저장되지 않아서 아무것도 검색 할 수없는 것처럼 보입니다.Google 애플리케이션 엔진 엔티티가 생성되지 않습니다.
private static String getUserId(User user) {
String userId = user.getUserId();
if (userId == null) {
AppEngineUser appEngineUser = new AppEngineUser(user);
ofy().save().entity(appEngineUser).now();
// Begin new session for not using session cache.
Objectify objectify = ofy().factory().begin();
AppEngineUser savedUser = objectify.load().key(appEngineUser.getKey()).now();
userId = savedUser.getUser().getUserId();
}
return userId;
}
@ApiMethod(name = "saveProfile", path = "profile", httpMethod = ApiMethod.HttpMethod.POST)
public Profile saveProfile(final User user, final ProfileForm profileForm) throws UnauthorizedException {
if(user == null) {
throw new UnauthorizedException("Authorization required.");
}
String firstName = profileForm.getFirstName();
String surname = profileForm.getLastName();
String userEmail = user.getEmail();
int year = profileForm.getYear();
int month = profileForm.getMonth();
int day = profileForm.getDay();
Profile profile = ofy().load().key(Key.create(Profile.class, getUserId(user))).now();
if (profile == null) {
// the user does not have a profile and is creating one for the first time
profile = new Profile(getUserId(user), firstName, surname, userEmail, year, month, day);
} else {
profile.update(firstName, surname, userEmail, year, month, day);
}
ofy().save().entity(profile).now();
return profile;
}
@ApiMethod(name = "getProfile", path = "profile", httpMethod = ApiMethod.HttpMethod.GET)
public Profile getProfile(User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Authentication required.");
}
return ofy().load().key(Key.create(Profile.class, getUserId(user))).now();
}
}
프로파일 클래스 @Entity
주석을 가지며과 같이 정적 블록 객관화 등록된다 : 작동하지 않는 것은 여기
static {
factory().register(AppEngineUser.class);
factory().register(Profile.class);
}
사용자 ID는
com.google.appengine.api.users.User
통해 GAE 의해 생성 userId 속성은 @Index
주석이있는 문자열입니다.
나는 API 탐색기와이 방법에 어떻게 반응하는지 혼동합니다. saveProfile API 메서드를 호출 할 때마다 userId
이 0
이고 이메일이 "[email protected]"
인 경우 프로필 개체가 반환됩니다. 로컬 호스트에서 실행될 때 기본 전자 메일이라고 생각합니다.
HTTP를 통해 api explorer도 실행 중이므로 Google에서이 문제가 발생할 수 있다고 말합니다. 이것이 아무 것도 작동하지 않는 이유입니다. 내 API를 사용하기 위해 안전하지 않은 스크립트를로드해야했지만, HTTPS 대신 HTTP를 통해 호스팅되기 때문에 작동하지 않을 수도 있습니다.
GAE를 이해하는 데있어 근본적인 결함이 있거나 로컬 호스트에서 실행되고 있기 때문에 완전히 내 방법을 테스트 할 수없는 문제입니다. 아마 후자의 경우 Appspot에 배포해야하며 상황이 더 원활하게 수행 될 수 있습니다.
도움이 필요한 추가 사항이있는 경우 그냥 물어보십시오.
감사합니다.