本文整理匯總了Java中com.google.appengine.api.utils.SystemProperty類的典型用法代碼示例。如果您正苦於以下問題:Java SystemProperty類的具體用法?Java SystemProperty怎麽用?Java SystemProperty使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SystemProperty類屬於com.google.appengine.api.utils包,在下文中一共展示了SystemProperty類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProfiles
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
public List<String> getProfiles() {
List<String> profiles = new ArrayList<>();
if (isProduction()) {
String applicationId = SystemProperty.applicationId.get();
if (StringUtils.isNotBlank(applicationId)) {
for (Function<String, String> extractorFunction : extractorFunctions) {
String extracted = extractorFunction.apply(applicationId);
if (StringUtils.isNotBlank(extracted)) {
profiles.add(extracted);
}
}
// We want the original applicationId to be the winning profile as it should be more specific
profiles.add(applicationId);
}
} else {
profiles.add("local");
}
return profiles;
}
示例2: notifyGCMServer
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
public void notifyGCMServer(String urlStr, String key) {
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
// In the development server, don't notify GCM
LOG.warning("Should notify the GCM server that new data is available, pinging URL "+urlStr);
} else {
try {
URL url = new URL(urlStr);
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Pinging GCM at URL: "+url);
}
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(1000 * 30); // 30 seconds
connection.setRequestProperty("Authorization", "key="+key);
connection.connect();
int statusCode = connection.getResponseCode();
if (statusCode < 200 || statusCode >= 300) {
LOG.severe("Unexpected response code from GCM server: "+statusCode+". "+connection.getResponseMessage());
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, "Unexpected error when pinging GCM server", ex);
}
}
}
示例3: readFileAsJsonObject
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
public JsonObject readFileAsJsonObject(GcsFilename file) throws IOException {
GcsFileMetadata metadata = gcsService.getMetadata(file);
if (metadata == null) {
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
// In the development server, try to fetch files on cloud storage via HTTP
Logger.getAnonymousLogger().info("fetching "+file.getObjectName()+" at "+Config.CLOUD_STORAGE_BASE_URL+file.getObjectName());
return RemoteJsonHelper.fetchJsonFromPublicURL(Config.CLOUD_STORAGE_BASE_URL+file.getObjectName());
}
return null;
}
GcsInputChannel readChannel = null;
try {
readChannel = gcsService.openReadChannel(file, 0);
JsonElement element = new JsonParser().parse(Channels.newReader(readChannel,
DEFAULT_CHARSET_NAME));
return element.getAsJsonObject();
} finally {
if (readChannel != null) {
readChannel.close();
}
}
}
示例4: extraExtraInfo
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
/**
* Gets extra system information to add to logs.
*
* @param req HTTP request (may be {@code null})
*/
private static String extraExtraInfo(HttpServletRequest req) {
StringBuilder s = new StringBuilder();
// If the app is running on App Engine...
if (Server.isProductionServer()) {
// the version ID of the runtime environment
String version = SystemProperty.version.get();
s.append("runtime.version").append("=").append(version).append("\n");
// the application major version number + deploy timestamp
version = SystemProperty.applicationVersion.get();
s.append("application.version").append("=").append(version).append("\n");
}
s.append("build.version").append("=").append(buildData).append("\n");
s.append("git.build.version").append("=").append(GitBuildId.getVersion()).append("\n");
if (req != null) {
s.append("request.details").append("=").append(req.toString()).append("\n");
}
return new String(s);
}
示例5: getTimestamp
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
/**
* Returns the timestamp for when the app was deployed (as a Unix time,
* in milliseconds, suitable for passing to the java.util.Date() constructor
*
*/
public static long getTimestamp() {
if (timestamp == 0) {
// Note: the applicationVersion string has the format version.timestamp
// The timestamp currently (when this was written) needs to be divided
// by 2^28 to get it into unix epoch seconds. This could change according
// to comments I found on the web, but there doesn't seem
// to be any more stable API to get this info.
String applicationVersion = SystemProperty.applicationVersion.get();
if (applicationVersion != null) {
String parts[] = applicationVersion.split("\\.");
timestamp = (Long.parseLong(parts[1]) >> 28) * 1000;
date = new Date(timestamp);
}
}
return timestamp;
}
示例6: fetch
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
@Override
public JsonElement fetch(Enum<?> entityType, Map<String, String> params)
throws IOException {
// On the first call, read all the files
if (object == null) {
object = new JsonObject();
for (String filename: filenames) {
JsonObject obj = fileManager.readFileAsJsonObject(filename);
if (obj == null &&
SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
// In the development server, cloud storage files cannot be directly accessed.
obj = RemoteJsonHelper.fetchJsonFromPublicURL(Config.CLOUD_STORAGE_BASE_URL + filename);
}
if (obj == null) {
LOGGER.warning("Could not find file "+filename);
} else {
for (Entry<String, JsonElement> entry: obj.entrySet()) {
object.add(entry.getKey(), entry.getValue());
}
}
}
}
return object.get(entityType.name());
}
示例7: getApplicationVersion
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
/**
* Method to get the application version.
*
* @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
* @since 13/10/2015
*
* @return the application version.
*/
public static String getApplicationVersion() {
String appVersion = SystemProperty.applicationVersion.get();
if (!appVersion.contains("$")) {
String namespace = appVersion;
String[] version = appVersion.split("\\.");
if (version.length > 0 && version[0].contains("-")) {
namespace = version[0].split("-")[0];
} else if (version.length > 0) {
namespace = version[0];
} else {
namespace = appVersion;
}
return namespace;
}
return appVersion;
}
示例8: reportDataCheckFailures
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
private void reportDataCheckFailures(CheckResult result, OutputStream optionalOutput) throws IOException {
StringBuilder errorMessage = new StringBuilder();
errorMessage.append(
"\nHey,\n\n"
+ "(this message is autogenerated)\n"
+ "The iosched data updater ran but found some inconsistent data.\n"
+ "Please, check the messages below and fix the sources. "
+ "\n\n" + result.failures.size() + " data non-compliances:\n");
for (CheckFailure f: result.failures) {
errorMessage.append(f).append("\n\n");
}
if (SystemProperty.environment.value() != SystemProperty.Environment.Value.Development ||
optionalOutput == null) {
// send email if user is not running in dev or interactive mode (show=true)
Message message = new Message();
message.setSender(Config.EMAIL_TO_SEND_UPDATE_ERRORS);
message.setSubject("[iosched-data-error] Updater - Inconsistent data");
message.setTextBody(errorMessage.toString());
MailServiceFactory.getMailService().sendToAdmins(message);
} else {
// dump errors to optionalOutput
optionalOutput.write(errorMessage.toString().getBytes());
}
}
示例9: fetch
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
@Override
public JsonElement fetch(Enum<?> entityType, Map<String, String> params)
throws IOException {
// On the first call, read all the files
if (object == null) {
object = new JsonObject();
for (String filename: filenames) {
JsonObject obj = fileManager.readFileAsJsonObject(filename);
if (obj == null &&
SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
// In the development server, cloud storage files cannot be directly accessed.
obj = RemoteJsonHelper.fetchJsonFromPublicURL(Config.CLOUD_STORAGE_BASE_URL+filename);
}
if (obj == null) {
LOGGER.warning("Could not find file "+filename);
} else {
for (Entry<String, JsonElement> entry: obj.entrySet()) {
object.add(entry.getKey(), entry.getValue());
}
}
}
}
return object.get(entityType.name());
}
示例10: newFactory
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
private static EntityManagerFactory newFactory(Map<String, String> extraProperties) {
LOGGER.info("Creating EntityManagerFactory...");
try {
Map<String, String> properties = new HashMap<>();
properties.putAll(extraProperties);
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.GoogleDriver");
properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url"));
} else {
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url.dev"));
}
properties.put(org.hibernate.ejb.AvailableSettings.INTERCEPTOR, TimingInterceptor.class.getName());
return Persistence.createEntityManagerFactory("Demo", properties);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to create EntityManagerFactory", e);
throw e;
}
}
示例11: doPost
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String email = request.getParameter("email");
String conferenceInfo = request.getParameter("conferenceInfo");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
String body = "Hi, you have created a following conference.\n" + conferenceInfo;
try {
Message message = new MimeMessage(session);
InternetAddress from = new InternetAddress(
String.format("[email protected]%s.appspotmail.com",
SystemProperty.applicationId.get()), "Conference Central");
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(email, ""));
message.setSubject("You created a new Conference!");
message.setText(body);
Transport.send(message);
} catch (MessagingException e) {
LOG.log(Level.WARNING, String.format("Failed to send an mail to %s", email), e);
throw new RuntimeException(e);
}
}
示例12: sendEmail
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
public static void sendEmail(EmailBean email) {
// TODO send email asynchronously - task queue
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
String applicationId=SystemProperty.applicationId.get();
log.info("Sending email from "+applicationId+" to "+email.toEmail+" with subject '"+email.subject+"'");
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"+applicationId+".appspotmail.com", "MindForger"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email.toEmail, email.toNickname));
msg.setSubject(email.subject);
msg.setText(email.body);
Transport.send(msg);
} catch (Exception e) {
log.severe("Unable to send email to "+email.toEmail+": "+e.getMessage());
}
}
示例13: reportDataCheckFailures
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
private void reportDataCheckFailures(CheckResult result, OutputStream optionalOutput) throws IOException {
StringBuilder errorMessage = new StringBuilder();
errorMessage.append(
"\nHey,\n\n"
+ "(this message is autogenerated)\n"
+ "The devfestnorte data updater ran but found some inconsistent data.\n"
+ "Please, check the messages below and fix the sources. "
+ "\n\n" + result.failures.size() + " data non-compliances:\n");
for (CheckFailure f: result.failures) {
errorMessage.append(f).append("\n\n");
}
if (SystemProperty.environment.value() != SystemProperty.Environment.Value.Development ||
optionalOutput == null) {
// send email if user is not running in dev or interactive mode (show=true)
Message message = new Message();
message.setSender(Config.EMAIL_TO_SEND_UPDATE_ERRORS);
message.setSubject("[devfestnorte-data-error] Updater - Inconsistent data");
message.setTextBody(errorMessage.toString());
MailServiceFactory.getMailService().sendToAdmins(message);
} else {
// dump errors to optionalOutput
optionalOutput.write(errorMessage.toString().getBytes());
}
}
示例14: createRawGcsService
import com.google.appengine.api.utils.SystemProperty; //導入依賴的package包/類
static RawGcsService createRawGcsService(Map<String, String> headers) {
ImmutableSet.Builder<HTTPHeader> builder = ImmutableSet.builder();
if (headers != null) {
for (Map.Entry<String, String> header : headers.entrySet()) {
builder.add(new HTTPHeader(header.getKey(), header.getValue()));
}
}
RawGcsService rawGcsService;
Value location = SystemProperty.environment.value();
if (location == SystemProperty.Environment.Value.Production || hasCustomAccessTokenProvider()) {
rawGcsService = OauthRawGcsServiceFactory.createOauthRawGcsService(builder.build());
} else if (location == SystemProperty.Environment.Value.Development) {
rawGcsService = LocalRawGcsServiceFactory.createLocalRawGcsService();
} else {
Delegate<?> delegate = ApiProxy.getDelegate();
if (delegate == null
|| delegate.getClass().getName().startsWith("com.google.appengine.tools.development")) {
rawGcsService = LocalRawGcsServiceFactory.createLocalRawGcsService();
} else {
rawGcsService = OauthRawGcsServiceFactory.createOauthRawGcsService(builder.build());
}
}
return rawGcsService;
}