60
© 2016 IBM Corporation IBM MobileFirst Foundation V8.0 開発構成ガイド アプリケーション開発 日本IBM(株) 日本IBMシステムズ・エンジニアリング(株)

MFF 8.0 アプリケーション開発

  • Upload
    dinhnhi

  • View
    244

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation

IBM MobileFirst Foundation V8.0開発構成ガイド

アプリケーション開発

日本IBM(株)日本IBMシステムズ・エンジニアリング(株)

Page 2: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 2

© Copyright IBM Corporation 2015. All rights reserved. The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, these materials. Nothing contained in these materials is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in these materials to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in these materials may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. IBM, the IBM logo, Rational, the Rational logo, Telelogic, the Telelogic logo, and other IBM products and services are trademarks of the International Business Machines Corporation, in the United States, other countries or both. Other company, product, or service names may be trademarks or service marks of others.

ワークショップ、セッション、および資料は、IBMまたはセッション発表者によって準備され、それぞれ独自の見解を反映したものです。それらは情報提供の目的のみで提供されており、いかなる参加者に対しても法律的またはその他の指導や助言を意図したものではなく、またそのような結果を生むものでもありません。本講演資料に含まれている情報については、完全性と正確性を期するよう努力しましたが、「現状のまま」提供され、明示または暗示にかかわらずいかなる保証も伴わないものとします。本講演資料またはその他の資料の使用によって、あるいはその他の関連によって、いかなる損害が生じた場合も、IBMは責任を負わないものとします。 本講演資料に含まれている内容は、IBMまたはそのサプライヤーやライセンス交付者からいかなる保証または表明を引きだすことを意図したものでも、IBMソフトウェアの使用を規定する適用ライセンス契約の条項を変更することを意図したものでもなく、またそのような結果を生むものでもありません。

本講演資料でIBM製品、プログラム、またはサービスに言及していても、IBMが営業活動を行っているすべての国でそれらが使用可能であることを暗示するものではありません。本講演資料で言及している製品リリース日付や製品機能は、市場機会またはその他の要因に基づいてIBM独自の決定権をもっていつでも変更できるものとし、いかなる方法においても将来の製品または機能が使用可能になると確約することを意図したものではありません。本講演資料に含まれている内容は、参加者が開始する活動によって特定の販売、売上高の向上、またはその他の結果が生じると述べる、または暗示することを意図したものでも、またそのような結果を生むものでもありません。 パフォーマンスは、管理された環境において標準的なIBMベンチマークを使用した測定と予測に基づいています。ユーザーが経験する実際のスループットやパフォーマンスは、ユーザーのジョブ・ストリームにおけるマルチプログラミングの量、入出力構成、ストレージ構成、および処理されるワークロードなどの考慮事項を含む、数多くの要因に応じて変化します。したがって、個々のユーザーがここで述べられているものと同様の結果を得られると確約するものではありません。

記述されているすべてのお客様事例は、それらのお客様がどのようにIBM製品を使用したか、またそれらのお客様が達成した結果の実例として示されたものです。実際の環境コストおよびパフォーマンス特性は、お客様ごとに異なる場合があります。

IBM、IBM ロゴ、ibm.com、CICS、Tivoli、WebSphere、Zseriesは、世界の多くの国で登録されたInternational Business Machines Corporationの商標です。他の製品名およびサービス名等は、それぞれIBMまたは各社の商標である場合があります。現時点での IBM の商標リストについては、www.ibm.com/legal/copytrade.shtmlをご覧ください。

Linuxは、Linus Torvaldsの米国およびその他の国における登録商標です。Microsoft, Windows, Windows NT および Windowsロゴは Microsoft Corporationの米国およびその他の国における商標です。UNIXはThe Open Groupの米国およびその他の国における登録商標です。JavaおよびすべてのJava関連の商標およびロゴは Oracleやその関連会社の米国およびその他の国における商標または登録商標です。

Page 3: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 3

Agenda

�zMFF 8.0 アプリケーション開発 新機能と非推奨化、削除された機能

�zMFF 8.0 アプリケーション開発の準備

�zMFF 8.0 アプリケーション開発

�zMFF 8.0 アプリケーション & アダプター開発の基本的な手順

�zCordova アプリケーション for iOS with CLI on Mac

�zCordova アプリケーション for Android with Eclipse on Windows PC

�zWeb アプリケーション with CLI on Windows PC

�z参考情報

Page 4: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 5

アプリケーションのビルドとデプロイ

�„ プロジェクト WAR ファイルが不要になった。

�„ .wlapp ファイルが廃止された。

• MFF CLI または Operations Console から、アプリケーションを MobileFirst サーバーに登録する。

�„ MobileFirst プロジェクトが廃止された。

• ハイブリッド・アプリケーションは Cordova プロジェクトとして開発する。

�‹ Cordova プラグインを容易に利用することが可能に。

• 既存の MobileFirst プロジェクト用にはマイグレーション・アシスト・ツールが提供される。

�„ Eclipse 用の MobileFirst Studio が廃止された。

• MobileFirst Studio プラグインが提供される。

�‹ MFF CLI のラッパー

• ハイブリッド・アプリケーション開発には Apache THyM を使用することができる。

�‹ THyM は MFF サポート対象外

MobileFirst Platform 固有の従来のしくみを廃止し、世の中に広く普及しているフレームワークに準拠しています。

Page 5: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 6

アダプターのビルドとデプロイ

�„ Apple watchOS 2 がサポートされた。

�„ Windows 10 Universal Application がサポートされた。

�„ MobileFirst アダプターは Apache Maven プロジェクトとして開発する。

• Maven CLI (mvn) と任意のエディタ または

• Eclipse や Intellij など、Maven をサポートするエディタでの開発が可能。

�„ Java アダプターで JAX-RS 2.0 がサポートされた。

• JavaScript アダプターは HTTP および SQL のみのサポートになった。

Page 6: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 7

MFF CLI

�„ コマンド名が mfp から mfpdev になった。

Page 7: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 8

MFF 8.0 アプリケーション開発の準備

Page 8: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 9

MFF 8.0 アプリケーション開発の準備- ハードウェア

�„ 開発機 + ネイティブ開発ツール

• ターゲットが iOS: Mac + Xcodeが必須

�‹ 今回の検証では OS X 10.11.6 + Xcode 7.3.1 を使用。

• ターゲットが iOS 以外: Mac でも PC でも可

�‹ 今回の検証では Android をターゲットとし、Windows 7 SP1 + Android Studio 2.2 を使用。

Page 9: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 10

MFF 8.0 アプリケーション開発の準備- 外部ソフトウェア

�„ Node.js – MFF や Cordova のプラグインが npm で取得される

• https://nodejs.org

• node: 今回の検証では 4.5.0 LTS を使用

• npm: 2.15.9 を使用 (Node.js 4.5.0 にパッケージされている)

�„ Apache Cordova (Cordova アプリケーションを開発する場合)

• https://cordova.apache.org

• 今回の検証では 6.3.1 を使用

�„ Apache Maven (アダプターを開発する場合)

• https://maven.apache.org

• 今回の検証では 3.3.9 を使用

�„ Java SDK (開発サーバーや Eclipse に必要)

• https://www.ibm.com/developerworks/java/jdk/ など

• 今回の検証では Oracle Java for Mac OS X 8.0 Update 102 (Mac) / IBM SDK for Java 1.8.0 (Windows) を使用

Page 10: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 11

MFF 8.0 アプリケーション開発の準備- Eclipse を使用する場合

�„ Eclipse

• http://www.eclipse.org

• 今回の検証では MARS.2 (4.5.2) を使用

�„ MobileFirst Studio プラグイン

• MFF CLI のラッパー

• Eclipse Marketplace で検索して導入

�„ Eclipse THyM

• Eclipse 用のハイブリッド・アプリケーション開発環境

• Eclipse Marketplace で検索して導入

Page 11: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 12

MFF 8.0 アプリケーション開発の準備- MFF 8.0 開発者キット�„ MFF 8.0 開発者キット (開発サーバー) の入手方法

• 製品版 (ライセンスをお持ちの方)

�‹ パスポート・アドバンテージ・オンライン

�9 http://www-01.ibm.com/software/jp/passportadvantage/pao.html

�‹ フィックス・セントラル

�9 https://www.ibm.com/support/fixcentral/

• 評価版

�‹ MobileFirst Foundation {dev}

�9 https://mobilefirstplatform.ibmcloud.com/downloads/

�„ MFF 8.0 CLI の入手方法

• 開発サーバーの Operations Console からダウンロードして npm でインストール。

• npm install –g mfpdev-cli

�„ クライアント SDK の入手方法

• 開発サーバーの Operations Console からダウンロードして npm でインストール。

• https://mobilefirstplatform.ibmcloud.com/downloads/ で Client SDKs を参照。

Page 12: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 13

MFF 8.0 でのアプリケーション

Page 13: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 14

MFF 8.0 アプリケーション開発の基本的な手順

�„ いくつか方法がありますが、お勧めの一例をご紹介します。

�„ 必要なハードウェアとソフトウェアを準備、構成する。

• 「MFF 8.0 アプリケーション開発の準備」を参考に

�„ 開発サーバーを起動する。

�„ Operations Console のダウンロード・センターからからスターター・コードをダウンロードする。

�„ スターター・コードを変更しながらコーディングを実施。

• MFF や Cordova プラグインの導入、構成もここで

�„ ビルド

�„ デプロイ

�„ 稼働確認

Page 14: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 15

MFF 8.0 ダウンロード・センター

�„ MFF 8.0 Operations Console 内にある

�„ 以下のコンポーネントをダウンロード可能

• ツール

�‹ MFF CLI などの開発用ツール

• SDK

�‹ 各ターゲット・プラットフォーム用のクライアント SDK

• サンプル

�‹ 各ネイティブ・プラットフォームや Cordova 用アプリケーションのスターター・コード

�‹ Java / JavaScript アダプターのスターター・コード

�‹ セキュリティ検査のサンプル・コード

Page 15: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 16

MFF 8.0 アダプター開発

Page 16: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 17

MFF 8.0 でのアプリケーション

�„ クライアント・アプリケーション

• ハイブリッド・アプリケーション - Cordova

• ネイティブ・アプリケーション

�‹ iOS

�9 watchOS 2

�‹ Android

�‹ Windows 10 Universal

• Web アプリケーション

�„ サーバーサイド・アプリケーション

• アダプター

�‹ Java アダプター

�‹ JavaScript アダプター

�9 HTTP アダプター

�9 SQL アダプター

Page 17: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 18

Java アダプター・プロジェクトの構造

← Java ソース・コード (JAX-RS)・ディレクトリ

← Java アダプター・ディスクリプター・ファイル

← ビルドされた Java アダプター

← Maven プロジェクト構成ファイル (Project Object Model)

Page 18: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 19

Java アダプターディスクリプター・ファイル�„ adapter.xml の例

<?xml version="1.0" encoding="UTF-8"?>

<mfp:adapter name="JavaAdapter1"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:mfp="http://www.ibm.com/mfp/integration">

<displayName>JavaAdapter1</displayName>

<description>JavaAdapter1</description>

<JAXRSApplicationClass>com.acme.JavaAdapter1Application</JAXRSApplicationClass>

<securityCheckDefinition

name="UserAuthenticationSC"

class="com.my_company.package.MyUserAuthenticationSecurityCheck">

<property

name="maxAttempts"

displayName="Maximum attempts"

defaultValue="3"

description="Maximum allowed user-authentication attempts"/>

</securityCheckDefinition>

<property name="path" description="The path after the host name" defaultValue="/feed">

</mfp:adapter>

Page 19: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 20

JavaScript アダプター・プロジェクトの構造

← JavaScript ソース・コード・ディレクトリ

← JavaScript アダプター・ディスクリプター・ファイル

← Maven プロジェクト構成ファイル (Project Object Model)

Page 20: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 21

JavaScript アダプターディスクリプター・ファイル

�„ adapter.xml の例 (HTTP アダプター)

<?xml version="1.0" encoding="UTF-8"?>

<mfp:adapter name="httpAdapter”

xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

xmlns:mfp=http://www.ibm.com/mfp/integration

xmlns:http="http://www.ibm.com/mfp/integration/http">

<displayName>httpAdapter</displayName>

<description>httpAdapter</description>

<connectivity>

<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">

<protocol>https</protocol>

<domain>mobilefirstplatform.ibmcloud.com</domain>

<port>443</port>

<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>

<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>

<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>

</connectionPolicy>

</connectivity>

<procedure name="getFeed"/>

<procedure name="unprotected" secured="false"/>

</mfp:adapter>

Page 21: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 22

Swagger UI を使用したアダプターのテスト

�„ MFF 開発サーバーに組み込みの Swagger UI を使用して、アダプターのテストを実施することが可能。

Page 22: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 23

操作のリストと拡張表示

Page 23: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 24

アダプターのテスト実行

Page 24: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 25

MFF 8.0 アプリケーション開発Cordova アプリケーション for iOS

with CLI on Mac

Page 25: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 26

開発サーバーの起動

�„ run.sh

• -bg オプションでバックグラウンド起動が可能。

�‹ バックグラウンド起動した場合は stop.sh で停止する。

• -bg を付けずにフォアグラウンド起動した場合は、Ctrl-C で停止する。

MobileFirst-8.0.0.0 babatch$ ./run.sh -bgRunning MobileFirst server in the background.objc[1903]: Class JavaLaunchHelper is implemented in both /Users/babatch/Applications/IBM/Java80/jre/bin/java and /Users/babatch/Applications/IBM/Java80/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.サーバー mfp を始動中です。サーバー mfp がプロセス ID 1902 で始動しました

Page 26: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 27

MFF Operations Console の起動

�„ console.sh または

�„ Web ブラウザで http://<hostname>:9080/mfpconsole へアクセスする。

• ユーザーとパスワードは admin / admin

Page 27: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 28

Java アダプタースターター・コードの入手

�„ Operations Console からスターター・コードをダウンロードする。

�„ ダウンロードしたアーカイブを展開しておく。

左列: 開発サーバー内の安定版へのリンク

右列: 外部サイトの最新版へのリンク

Page 28: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 29

Java アダプターのビルド

�„ Java アダプター Maven プロジェクトのルート・ディレクトリに移動

• cd javaAdapter

�„ mfpdev adapter build

javaAdapter babatch$ mfpdev adapter build

Building adapter...

Successfully built adapter

javaAdapter babatch$ ls

total 16

-rw-r--r--@ 1 babatch staff 1574 8 8 18:57 pom.xml

-rw-r--r--@ 1 babatch staff 2154 8 8 18:57 readme.md

drwxr-xr-x@ 3 babatch staff 102 8 8 18:57 src/

drwxr-xr-x 6 babatch staff 204 9 21 17:17 target/

javaAdapter babatch$ ls target/

total 24

drwxr-xr-x 5 babatch staff 170 9 21 17:17 adapter/

drwxr-xr-x 3 babatch staff 102 9 21 17:17 classes/

-rw-r--r-- 1 babatch staff 10123 9 21 17:17 javaAdapter.adapter

drwxr-xr-x 3 babatch staff 102 9 21 17:17 maven-status/

ビルドされたアダプター

Page 29: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 30

アダプターのデプロイ

�„ Operations Console を使用

Page 30: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 31

Cordova アプリケーションスターター・コードの入手

�„ Operations Console からスターター・コードをダウンロードする。

�„ ダウンロードしたアーカイブを展開しておく。

Page 31: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 32

iOS プラットフォームの追加

�„ Cordova プロジェクトのルート・ディレクトリに移動

• cd MFPStarterCordova

�„ cordova platform add ios

MFPStarterCordova babatch$ cordova platform add ios

Adding ios project...

Creating Cordova project for the iOS platform:

Path: platforms/ios

Package: com.ibm.mfpstartercordova

Name: MFPStarterCordova

iOS project created with [email protected]

Installing "cordova-plugin-mfp" for ios

Fetching plugin "cordova-plugin-device" via npm

Installing "cordova-plugin-device" for ios

Fetching plugin "cordova-plugin-dialogs" via npm

Installing "cordova-plugin-dialogs" for ios

Fetching plugin "cordova-plugin-globalization" via npm

Installing "cordova-plugin-globalization" for ios

If you made changes to your main.m file, manually merge main.m.bak with the main.m file that is provided

with IBM MobileFirst Platform Foundation.

Discovered plugin "cordova-plugin-splashscreen" in config.xml. Adding it to the project

Fetching plugin "cordova-plugin-splashscreen@~3" via npm

Installing "cordova-plugin-splashscreen" for ios

Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project

Fetching plugin "cordova-plugin-whitelist@~1" via npm

Installing "cordova-plugin-whitelist" for ios

Page 32: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 33

アプリケーションのコーディング

�„ Cordova プロジェクトのコンテンツを編集して、アプリケーションをコーディングする。

• 今回の検証では以下リンク先の編集を実施した。

�‹ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/quick-start/cordova/

�9 3. Editing Application Logic

• index.js の WLAuthorizationManager.obtainAccessToken() を置き換え

WLAuthorizationManager.obtainAccessToken()

.then(

function(accessToken) {

titleText.innerHTML = "Yay!";

statusText.innerHTML = "Connected to MobileFirst Server";

var resourceRequest = new WLResourceRequest(

"/adapters/javaAdapter/resource/greet/",

WLResourceRequest.GET

);

resourceRequest.setQueryParameter("name", "world");

resourceRequest.send().then(

function(response) {

// Will display "Hello world" in an alert dialog.

alert("Success: " + response.responseText);

},

function(response) {

alert("Failure: " + JSON.stringify(response));

}

);

},

function(error) {

titleText.innerHTML = "Bummer...";

statusText.innerHTML = "Failed to connect to MobileFirst Server";

}

);

Page 33: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 34

開発サーバーへのアプリケーションの登録

�„ mfpdev app register

�„ cordova prepare

MFPStarterCordova babatch$ mfpdev app register

Multiple IP addresses found

? Select the IP address of the local server x.y.z.a (en4)

Verifying server configuration...

Registering to server:'http://x.y.z.a:9080' runtime:'mfp’

Updated config.xml file located at: /Users/babatch/dev/MFPStarterCordova/config.xml

Run 'cordova prepare' to propagate changes.

Registered app for platform: ios

MFPStarterCordova babatch$ cordova prepare

Page 34: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 35

アプリケーションのテスト

�„ cordova run

Page 35: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 36

MFF 8.0 アプリケーション開発Cordova アプリケーション for Android

with Eclipse on Windows PC

Page 36: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 37

開発サーバーの起動

�„ run.cmd

• -bg オプションでバックグラウンド起動が可能。

�‹ バックグラウンド起動した場合は stop.cmd で停止する。

• -bg を付けずにフォアグラウンド起動した場合は、Ctrl-C で停止する。

C:¥Users¥babatch¥MobileFirst-8.0.0.0>run.cmd –bg

Running MobileFirst server in the background.

サーバー mfp を始動中です。サーバー mfp が始動しました。

Page 37: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 38

Operations Console の起動

�„ console.bat または

�„ Web ブラウザで http://<hostname>:9080/mfpconsole へアクセスする。

• ユーザーとパスワードは admin / admin

Page 38: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 39

Java アダプタースターター・コードの入手 (再掲)

�„ Operations Console からスターター・コードをダウンロードする。

�„ ダウンロードしたアーカイブを展開しておく。

Page 39: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 40

Java アダプター・プロジェクトのEclipse へのインポート

�„ File → Import...

�„ Maven → Existing Maven Projects → (展開したアーカイブ内の) javaAdapter フォルダ

Page 40: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 41

Java アダプターのビルド

�„ javaAdapter プロジェクトを右クリック → Maven → Maven install

Page 41: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 42

Java アダプターのデプロイ

�„ javaAdapter プロジェクトを右クリック → Run As → Run configurations...

Page 42: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 43

(参考) Java アダプターのデプロイ

�„ Java アダプターのデプロイ構成は pom.xml に記述されている。

• 必要に応じて修正できる。

<project xmlns=http://maven.apache.org/POM/4.0.0

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.ibm.mfp.sample</groupId>

<artifactId>javaAdapter</artifactId>

<version>1.0-SNAPSHOT</version>

<packaging>adapter</packaging>

<name>javaAdapter</name>

<properties>

<!-- Use UTF-8 as the encoding of the adapter -->

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- MobileFirst adapter deployment properties -->

<mfpfUrl>http://localhost:9080/mfpadmin</mfpfUrl>

<mfpfUser>admin</mfpfUser>

<mfpfPassword>admin</mfpfPassword>

<mfpfRuntime>mfp</mfpfRuntime>

</properties>

...

Page 43: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 44

Cordova アプリケーションスターター・コードの入手 (再掲)

�„ Operations Console からスターター・コードをダウンロードする。

�„ ダウンロードしたアーカイブを展開しておく。

Page 44: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 45

Cordova アプリケーションのEclipse へのインポート

�„ File → Import...

Page 45: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 46

Android プラットフォームの追加

�„ Cordova プロジェクトのルート・ディレクトリに移動

• cd MFPStarterCordova

�„ cordova platform add android

C:¥Users¥babatch¥workspace2¥MFPStarterCordova>cordova platform add android

Adding android project...

Creating Cordova project for the Android platform:

Path: platforms¥android

Package: com.ibm.mfpstartercordova

Name: MFPStarterCordova

Activity: MainActivity

Android target: android-23

Android project created with [email protected]

Installing "cordova-plugin-mfp" for android

Fetching plugin "cordova-plugin-device" via npm

Installing "cordova-plugin-device" for android

Fetching plugin "cordova-plugin-dialogs" via npm

Installing "cordova-plugin-dialogs" for android

Fetching plugin "cordova-plugin-globalization" via npm

Installing "cordova-plugin-globalization" for android

Fetching plugin "cordova-plugin-okhttp" via npm

Installing "cordova-plugin-okhttp" for android

MainActivity.java was backed up as MainActivity.original. A MobileFirst Platform Foundation version of MainActivity.java was added. If

you have made changes in the original MainActivity.java, you need to merge them with the current MainActivity.java in the C:¥Users¥baba

tch¥workspace2¥MFPStarterCordova¥platforms¥android¥src¥com¥ibm¥mfpstartercordova directory.

Discovered plugin "cordova-plugin-splashscreen" in config.xml. Adding it to the project

Fetching plugin "cordova-plugin-splashscreen@~3" via npm

Installing "cordova-plugin-splashscreen" for android

Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project

Fetching plugin "cordova-plugin-whitelist@~1" via npm

Installing "cordova-plugin-whitelist" for android

This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version

, you do *not* need this plugin since the whitelist will be built in.

Page 46: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 47

アプリケーションのコーディング (再掲)

�„ Cordova プロジェクトのコンテンツを編集して、アプリケーションをコーディングする。

• 今回の検証では以下リンク先の編集を実施した。

�‹ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/quick-start/cordova/

�9 3. Editing Application Logic

• index.js の WLAuthorizationManager.obtainAccessToken() を置き換え

WLAuthorizationManager.obtainAccessToken()

.then(

function(accessToken) {

titleText.innerHTML = "Yay!";

statusText.innerHTML = "Connected to MobileFirst Server";

var resourceRequest = new WLResourceRequest(

"/adapters/javaAdapter/resource/greet/",

WLResourceRequest.GET

);

resourceRequest.setQueryParameter("name", "world");

resourceRequest.send().then(

function(response) {

// Will display "Hello world" in an alert dialog.

alert("Success: " + response.responseText);

},

function(response) {

alert("Failure: " + JSON.stringify(response));

}

);

},

function(error) {

titleText.innerHTML = "Bummer...";

statusText.innerHTML = "Failed to connect to MobileFirst Server";

}

);

Page 47: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 48

開発サーバーへのアプリケーションの登録

�„ MFPStarterCordova プロジェクトを右クリック → IBM MobileFirst Platform Foundation → Register App

Page 48: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 49

アプリケーションのテスト

�„ MFPStarterCordova プロジェクトのルート・ディレクトリへ移動

�„ cordova run

Page 49: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 50

MFF 8.0 アプリケーション開発Web アプリケーション

with CLI on Windows PC

Page 50: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 51

開発サーバーと Operations Console の起動

�„ 37. 開発サーバーの起動 と 38. Operations Console の起動 と同様

Page 51: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 52

Web アプリケーションスターター・コードの入手

�„ Operations Console からスターター・コードをダウンロードする。

�„ ダウンロードしたアーカイブを展開しておく。

Page 52: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 53

開発サーバーへのアプリケーションの登録

�„ 「アプリケーションの登録」画面で必要事項を記入

�„ 「アプリケーションの登録」ボタンを押す

Page 53: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 54

アプリケーションのコーディング

�„ Web アプリケーション・プロジェクトのコンテンツを編集して、アプリケーションをコーディングする。

• 今回の検証では以下リンク先の編集を実施した。

�‹ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/quick-start/web/

�9 3. Editing Application Logic

• index.js の WLAuthorizationManager.obtainAccessToken() を置き換え

WLAuthorizationManager.obtainAccessToken()

.then(

function(accessToken) {

titleText.innerHTML = "Yay!";

statusText.innerHTML = "Connected to MobileFirst Server";

var resourceRequest = new WLResourceRequest(

"/adapters/javaAdapter/resource/greet/",

WLResourceRequest.GET

);

resourceRequest.setQueryParameter("name", "world");

resourceRequest.send().then(

function(response) {

// Will display "Hello world" in an alert dialog.

alert("Success: " + response.responseText);

},

function(response) {

alert("Failure: " + JSON.stringify(response));

}

);

},

function(error) {

titleText.innerHTML = "Bummer...";

statusText.innerHTML = "Failed to connect to MobileFirst Server";

}

);

Page 54: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 55

Java アダプターのビルドとデプロイ

�„ 41. Java アダプターのビルド と 42. Java アダプターのデプロイ と同様

Page 55: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 56

Node.js の起動

�„ クライアント Web アプリケーションを提供する Node.js を起動する

• MFPStarterWeb¥node_server へ移動

• npm startC:¥Users¥babatch¥dev¥MFPStarterWeb¥node_server>npm start

> [email protected] prestart C:¥Users¥babatch¥dev¥MFPStarterWeb¥node_server

> npm run proxy

> [email protected] proxy C:¥Users¥babatch¥dev¥MFPStarterWeb¥node_server

> npm install

npm WARN package.json [email protected] No repository field.

npm WARN package.json [email protected] No README data

[email protected] node_modules¥express

├──[email protected]

(中略)

└──[email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules¥request

├──[email protected]

(中略)

└──[email protected] ([email protected], [email protected], [email protected])

> [email protected] start C:¥Users¥babatch¥dev¥MFPStarterWeb¥node_server

> node server.js

::: Node.js server - Listening on port 9081 :::

::: All MobileFirst requests will be forwarded to http://localhost:9080 :::

::: Visit http://localhost:9081/home :::

Page 56: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 57

アプリケーションのテスト

�„ Web ブラウザーで http://localhost:9081/home へアクセスする。

Page 57: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 58

参考情報

Page 58: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 59

参考情報

�„ MobileFirst Foundation {dev}

�‹ https://mobilefirstplatform.ibmcloud.com/

• Quick Start

�‹ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/quick-start/

• Using the MobileFirst CLI in Eclipse

�‹ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/using-the-mfpf-sdk/using-mobilefirst-cli-in-eclipse/

�„ MobileFirst Foundation 8.0 Knowledge Center

• Cordova アプリケーションの開発

�‹ https://www.ibm.com/support/knowledgecenter/ja/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/dev/c_dev_cord_intro.html

• Web アプリケーションの開発

�‹ https://www.ibm.com/support/knowledgecenter/ja/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/dev/c_developing_web_apps.html

• MobileFirst コマンド・ライン・インターフェース (CLI)

�‹ https://www.ibm.com/support/knowledgecenter/ja/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/dev/c_wl_cli_description.html

Page 59: MFF 8.0 アプリケーション開発

© 2016 IBM Corporation 60

© Copyright IBM Corporation 2012. All rights reserved. The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, these materials. Nothing contained in these materials is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in these materials to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in these materials may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. IBM, the IBM logo, Rational, the Rational logo, Telelogic, the Telelogic logo, and other IBM products and services are trademarks of the International Business Machines Corporation, in the United States, other countries or both. Other company, product, or service names may be trademarks or service marks of others.