Java GoogleAppEngine服务器将数据发送到云数据存储,即使它是通过localhost:8080运行的
我已经设置了一个服务器,可以通过带有java的google应用程序引擎运行。当我尝试从客户端的web UI端调用调用消息时,出于某种原因,它会将数据发送到云中的数据存储,而不是本地数据存储。我使用oauth2进行身份验证,web UI要求web UI进行身份验证,即使它位于本地主机:8080上Java GoogleAppEngine服务器将数据发送到云数据存储,即使它是通过localhost:8080运行的,java,google-app-engine,maven,oauth-2.0,Java,Google App Engine,Maven,Oauth 2.0,我已经设置了一个服务器,可以通过带有java的google应用程序引擎运行。当我尝试从客户端的web UI端调用调用消息时,出于某种原因,它会将数据发送到云中的数据存储,而不是本地数据存储。我使用oauth2进行身份验证,web UI要求web UI进行身份验证,即使它位于本地主机:8080上 /** * @ngdoc service * @name oauth2Provider * * @description * Service that holds the OAuth2 i
/**
* @ngdoc service
* @name oauth2Provider
*
* @description
* Service that holds the OAuth2 information shared across all the pages.
*
*/
app.factory('oauth2Provider', function ($modal) {
var oauth2Provider = {
####################################.apps.googleusercontent.com',
SCOPES: 'https://www.googleapis.com/auth/userinfo.email profile',
signedIn: false
};
Api使用maven获取依赖项。我正在使用控制器发送Http请求这里是controller.js文件的一部分,该文件显示了根应用程序和其中一个控制器的设置。(我从中获得所有这些代码)
然后我有了映射出的Api类
import static com.google.devrel.training.conference.service.OfyService.ofy;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.api.server.spi.response.UnauthorizedException;
import com.google.appengine.api.users.User;
import com.google.devrel.training.conference.Constants;
import com.google.devrel.training.conference.domain.Conference;
import com.google.devrel.training.conference.domain.Profile;
import com.google.devrel.training.conference.form.ConferenceForm;
import com.google.devrel.training.conference.form.ProfileForm;
import com.google.devrel.training.conference.form.ProfileForm.TeeShirtSize;
import com.google.devrel.training.conference.service.OfyService;
import com.googlecode.objectify.Key;
/**
* Defines conference APIs.
*/
@Api(name = "conference", version = "v1", scopes = { Constants.EMAIL_SCOPE }, clientIds = {
Constants.WEB_CLIENT_ID, Constants.API_EXPLORER_CLIENT_ID }, description = "API for the Conference Central Backend application.")
public class ConferenceApi {
/*
* Get the display name from the user's email. For example, if the email is
* lemoncake@example.com, then the display name becomes "lemoncake."
*/
private static String extractDefaultDisplayNameFromEmail(String email) {
return email == null ? null : email.substring(0, email.indexOf("@"));
}
...
...
...
/**
* Returns a Profile object associated with the given user object. The cloud
* endpoints system automatically inject the User object.
*
* @param user
* A User object injected by the cloud endpoints.
* @return Profile object.
* @throws UnauthorizedException
* when the User object is null.
*/
@ApiMethod(name = "getProfile", path = "profile", httpMethod = HttpMethod.GET)
public Profile getProfile(final User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Authorization required");
}
// TODO
// load the Profile Entity
String userId = user.getUserId();
Key key = Key.create(Profile.class, userId);
Profile profile = (Profile) ofy().load().key(key).now();
return profile;
}
}
常量类如下所示:
package com.google.devrel.training.conference;
import com.google.api.server.spi.Constant;
/**
* Contains the client IDs and scopes for allowed clients consuming the conference API.
*/
public class Constants {
public static final String WEB_CLIENT_ID = "###################################.apps.googleusercontent.com";
public static final String ANDROID_CLIENT_ID = "replace this with your Android client ID";
public static final String IOS_CLIENT_ID = "replace this with your iOS client ID";
public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
public static final String EMAIL_SCOPE = Constant.API_EMAIL_SCOPE;
public static final String API_EXPLORER_CLIENT_ID = Constant.API_EXPLORER_CLIENT_ID;
public static final String MEMCACHE_ANNOUNCEMENTS_KEY = "RECENT_ANNOUNCEMENTS";
}
web UI的Html对我来说完全不可理解,因为Udacity类的目的不是开发Html,而是如下所示:
controller="MyProfileCtrl" ng-init="init()">
<div class="row">
<div class="col-lg-12">
<div id="messages" class="alert alert-{{alertStatus}}" ng-show="messages">
<span ng-bind="messages"></span>
<i class="dismiss-messages pull-right glyphicon glyphicon-remove" ng-click="messages = ''"
ng-show="messages"></i>
</div>
<img class="spinner" src="/img/ajax-loader.gif" ng-show="loading"/>
</div>
</div>
<div class="row">
<div class="col-md-8">
<h3>My Profile</h3>
<form name="profileForm" novalidate role="form">
<div class="form-group" ng-class="{'has-warning': profile.displayName != initialProfile.displayName}">
<label for="displayName">Display Name </label>
<span class="label label-warning"
ng-show="profile.displayName != initialProfile.displayName"> Changed</span>
<input id="displayName" type="text" name="displayName" ng-model="profile.displayName"
class="form-control"/>
</div>
<div class="form-group" ng-class="{'has-warning': profile.teeShirtSize != initialProfile.teeShirtSize}">
<label for="teeShirtSize">Tee shirt size</label>
<span class="label label-warning"
ng-show="profile.teeShirtSize != initialProfile.teeShirtSize"> Changed</span>
<select id="teeShirtSize" ng-model="profile.teeShirtSize" name="teeShirtSize" ng-options="size for size in teeShirtSizes"
class="form-control">
</select>
</div>
<button ng-click="saveProfile(profileForm)" class="btn btn-primary"
ng-disabled="loading">Update profile
</button>
</form>
</div>
</div>
</div>
controller=“MyProfileCtrl”ng init=“init()”>
我的个人资料
显示名称
改变
T恤尺寸
改变
更新配置文件
本课程中的说明希望在服务器上提交之前在本地测试api。奇怪的是,只有当我通过API资源管理器菜单调用调用时,API才会向本地云创建数据条目。我也有同样的问题(我也参加了Udacity课程)。对我来说,这似乎与maven有关——也许POM已经过时了,因为这门课已经是很久以前的事了。 我花了很长时间才把它修好,老实说,我甚至不知道最后是怎么修好的。 我做了两件事:
- 检查是否存在“local_db.bin”文件(数据存储的本地版本)。它应该位于/target/conference-1.0/WEB-INF/appengine-generated/中。 但我猜情况就是这样,因为你说本地API资源管理器正在为你工作
- 更新pom.xml:1.9.17中的SDK版本,该版本以前是1.9.3
我也在学同样的课程,我一直在努力解决这个问题。没有创建local_db.bin,所有更改都直接上载到appspot实例。 但幸运的是,在谷歌搜索之后,我找到了这个解决方案 你只要加上
<jvmFlags>
<jvmFlag>-Dappengine.generated.dir=/tmp/blabla</jvmFlag>
</jvmFlags>
-Dappengine.generated.dir=/tmp/blabla
进入pom.xml文件中appengine maven插件的配置部分
应该是这样的
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
<configuration>
<jvmFlags>
<jvmFlag>-Dappengine.generated.dir=/tmp/blabla</jvmFlag>
</jvmFlags>
<enableJarClasses>false</enableJarClasses>
</configuration>
<executions>
<execution>
<goals>
<goal>endpoints_get_discovery_doc</goal>
</goals>
</execution>
</executions>
</plugin>
com.google.appengine
appengine maven插件
${appengine.target.version}
-Dappengine.generated.dir=/tmp/blabla
错误的
端点\u获取\u发现\u文档
现在它运行得非常完美:)
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
<configuration>
<jvmFlags>
<jvmFlag>-Dappengine.generated.dir=/tmp/blabla</jvmFlag>
</jvmFlags>
<enableJarClasses>false</enableJarClasses>
</configuration>
<executions>
<execution>
<goals>
<goal>endpoints_get_discovery_doc</goal>
</goals>
</execution>
</executions>
</plugin>