スキップしてメイン コンテンツに移動

投稿

ラベル(Google App Engine)が付いた投稿を表示しています

Google Datastoreのインデックス削除

大昔にGoogle App Engineの開発で作成したGoogle Datastoreのインデックスを見つけたので掃除方法を検索したところ、公式の https://cloud.google.com/sdk/gcloud/reference/datastore/indexes/cleanup を見つけました。 筆者の場合は、インデックスを全削除したかったので、下記のような空のindex.yamlを作成し、 indexes: 下記のコマンドを実行しました。 gcloud datastore indexes cleanup index.yaml

Spring Bootのコンテンツ配信でgzip圧縮を有効にする方法

Google App EngineのJava 17のStandard EnvironmentでSpring Bootアプリケーションを運用していたところ、サーバーから送信されるhtmlにgzip圧縮が効いていないことに気が付きました。 gzip圧縮が効いているかどうかは、下記のようなサイトに調べたいページのURLを入力すれば確認できます。 https://pagespeed.web.dev/ https://www.giftofspeed.com/gzip-test/ Spring Bootでgzip圧縮を有効にするにはapplication.propertiesに下記のように追記すればOKでした。ちなみにGoogle App Engine側の設定は特にいじっていません。 # 圧縮を有効にするかどうか server.compression.enabled = true # 圧縮対象のmite type server.compression.mime-types = text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json # 圧縮を効かせる最小レスポンスサイズ server.compression.min-response-size = 1024 Google App EngineのDash Boardで確認したところ、見事にネットワークの使用帯域が1/5になりました!

Spring Bootでwarファイルを作成する方法

Google App Engine JavaでSpring Boot + Gradleを使ってアプリケーションをデプロイする方法を調べた。 まずは、下記のオフィシャルを参考に、Gradle App Engine Pluginを導入 Using Gradle and the App Engine Plugin | App Engine standard environment for Java docs | Google Cloud MavenでSpring Bootアプリケーションを作成する方法 https://cloud.google.com/appengine/docs/standard/java11/building-app/writing-web-service Spring Bootアプリケーションを作成→Gradle App Engine Pluginを導入 下記の記事の方が参考になりました。 https://blog.uoneweb.net/2021/09/04/695/ https://zenn.dev/donchan922/articles/ea76614f72b15e

Google App Engineで外部のURLにアクセス

Google App Engine(GAE)から外部のネットワークへ接続する際の注意 Google App Engine(GAE)の開発環境の移行の際にJava 7からJava 8へ移行しました。 その際、GAEから、java.net.URL.openConnectionを使って普通に外部ネットワークのAPIを呼び出そうとすると下記のエラーが発生するようになってしまいました。 java.net.UnknownHostException: ホスト名 いろいろ調べていくと、下記のページにたどり着きました。 https://cloud.google.com/appengine/docs/standard/java/issue-requests 上記の表を間単に日本語訳すると URLのフェッチ方法 Java 7 Java 8 UrlFetch API Calls com.google.appengine.urlfetch.*以下のクラスを使う。無料で使用できる部分あり。 com.google.appengine.urlfetch.*以下のクラスを使う。無料で使用できる部分あり。 Javaネイティブのjava.net.URL.openConnectionなどを使う方法 無料ユーザも制限なく利用可能。 無料ユーザは、利用不可。 java.net.UnknownHostException、java.net.SocketTimeoutException、java.io.IOException とかが投げられる。 まとめると、 GAEで外部ネットワークへアクセスする方法には「GAEが提供するUrlFetch API Calls」「Javaネイティブのjava.net.URL.openConnection」の2つ方法がある。 Java 7では、「GAEが提供するUrlFetch API Calls」「Javaネイティブのjava.net.URL.openConnection」は無料でどちらの方法も利用可能。 Java 8で無料で利用できるのは「GAEが提供するUrlFetch API Calls」のみ。 Java 8で「Javaネイティブのjava.net.URL.openConnectionの方法」は課金ユーザーのみ利

Goolge App Engineの開発環境の更新 (Java)

Google Plugins for EclipseからCloud Tools for Eclipseの移行 長らくEclipse Luna (4.4) + Google Plugin for Eclipseで開発を続けてきたのですが、Google App Engineの開発ページを覗いたら下記のようなメッセージが出ていてびっくり。 The Google Plugin for Eclipse is deprecated and will be removed in January 2018. Migrate to Cloud Tools for Eclipse and/or the GWT Eclipse Plugin as soon as possible to avoid disruption. Google Plugin for Eclipseは、2018年の1月でサポート打ち切りで、Cloud Tools for Eclipseに移行しなさいとのこと。 せっかくなので最新のeclipseを使って下記の設定で開発環境を再構築することにしました。 移行方法 最新のJDK 8 を http://www.oracle.com/technetwork/java/javase/downloads/index.html からダウンロードしてインストール。JDKをダウンロード Java 9 も試そうかとも思ったのですが、2017年9月現在Google App Engine側はまだJava 8までしかサポートしていないので、 Eclipseを  http://www.eclipse.org/downloads/eclipse-packages/  からダウンロード。私は、Eclipse IDE for Java Developersをダウンロードしました。 EclipseでGoogle App Engineの開発を行うための設定を https://cloud.google.com/eclipse/docs/quickstart  を読んで実施。 Google Cloud SDKをダウンロード Google Cloud Tools for Eclipse をEclipse Marketplace.を通してインストール 古いプロジェクト

Google App Engine Java: Setup Test Configuration

If you want to test a class which depends on Google App Engine infrastructure, such as data storing functionality with "PersistenceManagerFactory", you should set up LocalServiceTestHelper before testing. I don't tell you the details very much, but I will show you the minimum test setup in the code below. This code was enough for me to test my data access object functionality. package com.dukesoftware.gaej.test; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; public class GoogleAppEngineTest { private static final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); @BeforeClass public static void setUp() { helper.setUp(); } @AfterClass public static void tearDown() { he

Google App Engine Task Queue - Using DeferredTask

When to Use Google App Engine Task Queue? You should use task queue when you try to do something taking time such as storing or updating bunch of data to datastore. In Google App Engine, a http request which isn't returned by timeout should be simply failed. The timeout configured on Google App Engine is 60 seconds. Please see https://developers.google.com/appengine/articles/deadlineexceedederrors . So in order to response back to the client quickly, you should use Task Queue for tasks which takes long time. Push Tasks to Task Queue I have read an official document of Task Queue and tried to use it. What frustrates me is the document only explains how to create a task with parameters, push the task to the task queue and pass to the worker servlet. i.e. actual heavy part is treated in the worker servlet. Of course it is fine, but I felt it was a bit indirect way to push tasks to queue. What I desired to do is creating task object and pushing it to the queue in one single

Java: How to Create Indexed PNG Using PNGJ Library

I'm working on Google App Engine for Java (GAEJ) now. Very excited about working on it because can develop Java Web App quite easliy & quickly! However I faced a limitation of image processing on GAEJ. On GAEJ, java.awt pakage.* is not supported. That means we cannot use BufferedImage etc!! As you know, Google provides com.google.appengine.api.images.* for image processing on GAEJ, something like below: ImagesService imagesService = ImagesServiceFactory.getImagesService(); Image srcImage = ImagesServiceFactory.makeImage(srcImageData); // some transformations. Transform crop = ImagesServiceFactory.makeCrop(0.3, 0, 1, 0.70); OutputSettings settings = new OutputSettings(OutputEncoding.PNG); // apply transform Image newImage = imagesService.applyTransform(crop, srcImage, settings); byte[] newImageData = newImage.getImageData(); It can read jpg, png, gif images accroding to the official document. And if transformation is applied, the output binary data becomes png forma

Youtube API + GAEJ + FreeMarker + Spring

I have developed very very simple youtube sample application on Google App Engine. Internally I have used FreeMarker and Spring. The purpose of this blog entry is just giving hints how to use Spring + FreeMarker on GAEJ with youtube API example. Youtube API Here is the code for extracting video url etc from Youtube API response. I frequently use JDOM for parsing XML. package com.dukesoftware.gaej.youtube; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Namespace; import org.jdom.input.SAXBuilder; import org.jdom.xpath.XPath; import com.dukesoftware.utils.io.JDOMUtils; import com.dukesoftware.utils.io.MinimumIOUtils; public class YouTube { private final static XPath XPATH_MEDIA; private final static Namespace NS_MEDIA = Namesp

Javascriptで実装された画像ギャラリーライブラリ

(2020年5月更新) こちらの下記理由により、デモを非公開にしました。 picasaはもうGoogle Photosに統合されてAPIが変わった。 Gallerifficももうアクティブに開発されていない。JQueryのプラグイン化されたようです。 記録目的で記事は残してあります。 Javascriptで実装された画像ギャラリーのライブラリ集です。 試しにいくつか使ってみた中で実際に使えると思ったものを選びました。 他にもかっこいいものがいっぱいあるのですが、実際使うとなると、なかなか厳しい(=使いにくい)ものも多いです。 最近はブラウザのJavascriptエンジンの性能も上がっていますし、HTML5やCSS3も徐々に浸透してきていますので、 ブラウザでお手軽に見栄えのするものが作れるのが魅力かなと思います。 注意点をいくつか。 上記のデモの場合、1つのオリジナル画像につき、「75px程度の正方形にクロップされた画像」と「幅が500px程度にサイズ変更された画像」の2つが必要です。 Picasaについては画像サイズを指定してクエリを投げられるので、ちょうどよい大きさの画像のクエリを作成して投げれば簡単にサムネイルが画像を取得できます。 肝はデモで使っているURLの https://picasaweb.google.com/data/feed/api/all?alt=rss&kind=photo&thumbsize=72c,512&access=public&imgmax=1600&hl=en_US&max-results=50 のthumbsize=72c,512の部分です。 簡単に説明しますと、サイズの後にcをつけると画像を正方形にクロップしてくれます。何もつけないとアスペクト比を固定して画像をリサイズしてくれます。 詳しく知りたい方は Picasa Data APIの公式ドキュメント を参照してください。 自分で大量の画像のサイズ変更するのは面倒くさいと思います。私の場合はJavaやC#で画像サイズを変更するプログラムを書きました。バッチ処理が可能な画像処理用のソフトを使うのもいいかもしれません。 C#のコードは簡潔で、実行性能もいいので載せておきます。画像を指定したサイズの正方形

Google App Engine

はじめに Google App Engineを試して見ようと思い、 Google App Engine for Java実践クラウド・プログラミング を購入して、ちょっと触って見ました。一通りできることは解説してあるので、とりあえずGoogle App Engineで動くサイトを作りたい人にはいい本かもしれません。 2012年7月8日追記: リンク先をチェックしたら 絶版 になってしまったようです。。。 必要なもの Java SDK: 私はJava SE Development Kit 7u3をインストールしました Eclipse: 私はEclipse IndigoのJava EE IDE for Web Developersをインストールしました Google App Engine Eclipse Plugin:私は以下の画像のものをとりあえずチェックしてインストールしました Bigtable Google App EngineのデータストアサービスであるBigtableのクエリに関しては、以下のリンクが参考になります。 Datastore Queries - Google App Engine — Google Developers 以下のコードでローカル環境に仮想のデータストアサービスがセットアップされます。 package com.dukesoftware.gaej.dao; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; public class DaoTest { private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreSer