Flex Gateway新着情報
Governance新着情報
Monitoring API ManagerStudio または XML を使用して次の例を試してください。
この例では、フォルダーの作成、取得、および削除方法について説明します。
Anypoint Studio で新しい Mule プロジェクトを作成します。
次のプロパティを mule-artifact.properties
ファイルに追加し、このファイルをプロジェクトの src/main/resources
ディレクトリに置きます。
config.clientId=<Client ID> config.clientSecret=<Client Secret>
text
新しい HTTP グローバル要素を追加して、HTTP リスナーを設定します。[Connector configuration (コネクタ設定)] 項目の横にある [+] をクリックします。
次の表に従ってグローバル要素を設定します。
パラメーター | 値 |
---|---|
Name (名前) |
HTTP_Listener_config |
Protocol (プロトコル) |
HTTP |
Host (ホスト) |
localhost |
Port (ポート) |
8081 |
[HTTP Listener (HTTP リスナー)] をキャンバスにドラッグし、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
HTTP Listener (HTTP リスナー) |
Connector configuration (コネクタ設定) |
新しく作成した HTTP リスナー設定を選択します。 |
Path (パス) |
|
DataWeave コンポーネントを使用して作成するフォルダーのフォルダープロパティを設定します。 [DataWeave] コンポーネントを HTTP リスナーの横にドラッグし、次のスクリプトを使用します。
%dw 2.0
output application/json
---
{
parent: {
id: 0
},
"type": "folder",
name: "SampleFolder"
}
dataweave
Box Connector の [Create folder] 操作を、フォルダーを作成する [DataWeave] コンポーネントの横にドラッグします。
新しい Box グローバル要素を追加して、Box Connector を設定します。[Connector configuration (コネクタ設定)] 項目の横にある [+] をクリックします。
次の表に従ってグローバル要素を設定します。
パラメーター | 値 | コメント |
---|---|---|
clientId |
|
クライアントアプリケーションの登録時に認証サーバーにより割り当てられたクライアント識別子。 |
clientSecret |
|
クライアントアプリケーションのクライアントシークレット。 |
host (ホスト) |
|
デフォルト値。そのままにしてください。 |
port (ポート) |
|
デフォルト値。変更しないでください。 |
basePath |
|
デフォルト値。変更しないでください。 |
protocol (プロトコル) |
|
デフォルト値。変更しないでください。 |
localCallbackPath |
|
デフォルト値。変更しないでください。 |
localCallbackConfig |
|
以前作成した HTTP リスナー設定を選択します。 |
externalCallbackUrl |
|
クライアントアプリケーション内で設定されるリダイレクト URL を使用します。 |
localAuthorizationUrl |
|
|
authorizationUrl |
|
認証コードを要求するための認証 URL。 |
accessTokenUrl |
|
アクセストークンを要求するためのアクセストークン URL。 |
対応する XML 設定は次のようになります。
<mule-box-connector:config name="Mule_box_connector_Config"
doc:name="Mule-box-connector Config"
property_clientId="#{config.clientId}"
property_clientSecret="#{config.clientSecret}"
property_localCallbackConfig="HTTP_Listener_config"
property_externalCallbackUrl="http://localhost:8081/callback" />
xml
Box Connector のプロパティエディターで、Create folder 操作に必要な次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Create folder |
Basic Settings (基本設定) |
|
Connector configuration (コネクタ設定) |
作成したグローバル Box Connector 要素を選択します。 |
General (一般) |
|
Create folder request data (Create folder 要求データ) |
|
新しく作成したフォルダー ID を記録する [Logger] コンポーネントをドラッグし、次のプロパティを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
作成したフォルダー ID を記録するために使用するロガーを指定します。 |
Generic |
|
Message (メッセージ) |
ID |
Box Connector の [Get folder] 操作を [Logger] コンポーネントの横にドラッグします。これにより、フォルダー情報が取得され、次のプロパティが設定されます。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Get folder (フォルダーの取得) |
Basic Settings (基本設定) |
|
Connector configuration (コネクタ設定) |
作成したグローバル Box Connector 要素を選択します。 |
General (一般) |
|
Folder id (フォルダー ID) |
|
取得したフォルダー情報を記録する [Logger] コンポーネントをドラッグし、次のプロパティを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
取得したフォルダー情報を記録するロガーを指定します。 |
Generic |
|
Message (メッセージ) |
|
作成したフォルダーを削除する Box Connector の [Delete folder] 操作をドラッグし、次のプロパティを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Delete folder |
Basic Settings (基本設定) |
|
Connector configuration (コネクタ設定) |
作成したグローバル Box Connector 要素を選択します。 |
General (一般) |
|
Folder id (フォルダー ID) |
|
ユーザーにフローの結果を表示するためのペイロードを設定する [DataWeave] コンポーネントをドラッグし、次のスクリプトを使用します。
%dw 2.0
output application/json
---
{
result : "Folder was created, retrieved and deleted successfully."
}
dataweave
プロジェクトを保存し、Mule アプリケーションとして実行します。
OAUTH2
ダンスを開始するためのグローバル Box 設定要素の localAuthorizationUrl
に設定した URL http://localhost:8081/authorize
をブラウザーから使用します。
これにより表示されるページで、Box ユーザーは、Box に保存されたすべてのファイルとフォルダーの読み取りおよび書き込みアクセス権をクライアントアプリケーションに付与するか却下するかを求められます。
[Grant access to Box (Box へのアクセス権を付与)] をクリックして、読み取りおよび書き込み権限を付与します。
Web ブラウザーを開いて、http://localhost:8081/boxdemo
にアクセスします。
次のコンテンツの JSON 応答を取得します。
結果: "Folder created, retrieved and deleted successfully."
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:mule-box-connector="http://www.mulesoft.org/schema/mule/mule-box-connector"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/mule-box-connector
http://www.mulesoft.org/schema/mule/mule-box-connector/current/mule-mule-box-connector.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="HTTP_Listener_config"
doc:name="HTTP Listener config">
<http:listener-connection host="localhost"
port="8081" />
</http:listener-config>
<mule-box-connector:config name="Mule_box_connector_Config"
doc:name="Mule-box-connector Config"
property_clientId="#{config.clientId}"
property_clientSecret="#{config.clientSecret}"
property_localCallbackConfig="HTTP_Listener_config"
property_externalCallbackUrl="http://localhost:8081/callback" />
<flow name="Create-Get-Delete-Folder-Flow">
<http:listener doc:name="HTTP Listener"
path="/boxdemo"
config-ref="HTTP_Listener_config"
/>
<ee:transform doc:name="DataWeave to set folder properties">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
parent: {
id: 0
},
"type": "folder",
name: "SampleFolder"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<box-connector:create-folder
doc:name="Create folder" config-ref="Mule_box_connector_Config" />
<logger level="INFO" doc:name="Logger to log the created Folder ID"
message="Folder created with ID : #[payload.id]" />
<box-connector:get-folder doc:name="Get folder"
config-ref="Mule_box_connector_Config" folder-id="#[payload.id]" />
<logger level="INFO" doc:name="Logger to log the retrieved folder info"
message="#[payload]" />
<box-connector:delete-folder
doc:name="Delete folder" config-ref="Mule_box_connector_Config"
folder-id="#[payload.id]" />
<ee:transform doc:name="DataWeave to show the result">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
result : "Folder got created, retrieved and deleted successfully"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
xml
この例では、作成した他の Box 操作で使用するファイルをアップロードする方法について説明します。
Anypoint Studio で新しい Mule プロジェクトを作成します。
src/main/resources directory
に input
というフォルダーを作成します。
input directory
にアップロードするファイルをコピーします。
新しい HTTP グローバル要素を追加して、HTTP リスナーを設定します。
キャンバスの下部にある [Global Elements (グローバル要素)] タブをクリックします。
[Global Configuration Elements (グローバル設定要素)] 画面で、[Create (作成)] をクリックします。
[Choose Global Type (グローバル種別の選択)] ウィザードで、[Connector Configuration (コネクタ設定)] を展開します。
[HTTP Listener (HTTP リスナー)] を選択して [OK] をクリックします。
[HTTP Listener (HTTP リスナー)] 画面で、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Name (名前) |
HTTP_Listener_config |
Protocol (プロトコル) |
HTTP |
Host (ホスト) |
localhost |
Port (ポート) |
8081 |
[HTTP Listener (HTTP リスナー)] をキャンバスにドラッグし、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
HTTP Listener (HTTP リスナー) |
Connector configuration (コネクタ設定) |
以前作成した HTTP リスナー設定を選択します。 |
Path (パス) |
|
Box にログインし、60 分間アクティブな Box 開発者トークンを生成します。
DataWeave コンポーネントを使用して、開発者トークンを設定します。
DataWeave コンポーネントを HTTP リスナーの横にドラッグし、次のように設定します。
%dw 2.0
output application/java
//Set the generated developer token here
var developerToken = "{developer Token}"
---
"Bearer " ++ developerToken
dataweave
[Set Variable] コンポーネントをキャンバスにドラッグし、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Save developer token (開発者トークンの保存) |
Name (名前) |
developerToken |
Value (値) |
|
新しいファイルグローバル要素を追加して、File Connector を設定します。
キャンバスの下部にある [Global Elements (グローバル要素)] タブをクリックします。
[Global Configuration Elements (グローバル設定要素)] 画面で、[Create (作成)] をクリックします。
[Choose Global Type (グローバル種別の選択)] ウィザードで、[Connector Configuration (コネクタ設定)] を展開します。
[File Config (ファイル設定)] を選択して [OK] をクリックします。
[File Config (ファイル設定)] 画面で、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Working Directory (作業ディレクトリ) |
|
[Read File] 操作をキャンバスにドラッグし、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Read File (ファイルの読み取り) |
Connector configuration (コネクタ設定) |
グローバル要素で以前作成したファイル設定を選択します。 |
File Path (ファイルパス) |
|
このペイロードを multipart/form-data
型の要求に変換します。
親フォルダーの ID を設定し、アップロードするフォルダーを指定します。
[DataWeave] コンポーネントを [Read File] コンポーネントの横にドラッグし、次のスクリプトを使用します。
%dw 2.0
output multipart/form-data
---
{
parts : {
attributes : {
headers : {
"Content-Type": "application/json"},
content : {
"name": message.attributes.fileName ,
// Set the ID of the parent folder. Use "0" for the root folder.
"parent": {
"id":"0"
}
}
},
file : {
headers : {
"Content-Disposition" : {
"name": "file",
"filename": message.attributes.fileName
}
},
content : payload
}
}
}
dataweave
新しい HTTP 要求グローバル要素を追加して、HTTP 要求を設定します。
キャンバスの下部にある [Global Elements (グローバル要素)] タブをクリックします。
[Global Configuration Elements (グローバル設定要素)] 画面で、[Create (作成)] をクリックします。
[Choose Global Type (グローバル種別の選択)] ウィザードで、[Connector Configuration (コネクタ設定)] を展開し、[HTTP Request Configuration (HTTP 要求設定)] を選択して [OK] をクリックします。
[HTTP Request Configuration (HTTP 要求設定)] 画面で、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Name (名前) |
HTTP_Request_configuration |
Base Path (ベースパス) |
/ |
Protocol (プロトコル) |
HTTP (デフォルト) |
Host (ホスト) |
80 |
Port (ポート) |
|
Use persistent connections (永続接続を使用) |
✓ |
Max Connections (最大接続数) |
-1 |
Connection idle timeout (接続アイドルタイムアウト) |
30000 |
Response buffer size (応答バッファサイズ) |
1024 |
TLS configuration (TLS 設定) |
なし |
Proxy (プロキシ) |
なし |
Authentication (認証) |
なし |
Client socket properties (クライアントソケットのプロパティ) |
なし |
Use reconnection (再接続を使用) |
unchecked (未チェック) |
[HTTP Request (HTTP 要求)] をキャンバスにドラッグし、次のパラメーターを設定します。
パラメーター | 値 |
---|---|
Display Name (表示名) |
Request - Box Upload File (要求 - Box アップロードファイル) |
Configuration (設定) |
グローバル要素で作成した HTTP 要求設定を選択します。 |
Method (メソッド) |
POST |
Path (パス) |
|
URL |
|
Body (本文) |
payload (ペイロード) |
HTTP 要求の認証ヘッダーを作成します。
HTTP 要求の [Body (本文)] の横にある [Headers (ヘッダー)] タブをクリックし、[+] をクリックして次のパラメーターを設定します。
名前 | 値 |
---|---|
"Authorization (認証)" |
|
ユーザーにフローの結果を表示するためのペイロードを設定する DataWeave コンポーネントをドラッグし、次のように設定します。
%dw 2.0
output application/json
---
{
result : "File has been successfully created"
}
dataweave
プロジェクトを保存し、Mule アプリケーションとして実行します。
ブラウザーに URL http://localhost:8081/boxUploadFile
を入力します。次のコンテンツの JSON 応答を取得します。
result : "File has been successfully created"
ファイルをアップロードする XML の例を次に示します。
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mule-box-connector="http://www.mulesoft.org/schema/mule/mule-box-connector" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/mule-box-connector http://www.mulesoft.org/schema/mule/mule-box-connector/current/mule-mule-box-connector.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<file:config name="File_Config" doc:name="File Config">
<file:connection workingDir="${mule.home}/apps/${app.name}/" />
</file:config>
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" >
<http:request-connection host="80" />
</http:request-config>
<flow name="UploadFileToBox" >
<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/boxUploadFile" />
<ee:transform doc:name="Set Developer Token Variable">
<ee:message>
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
//Set the generated developer token here
var developerToken = "{developer Token}"
---
"Bearer " ++ developerToken]]></ee:set-payload>
</ee:message>
<ee:variables>
</ee:variables>
</ee:transform>
<set-variable value="#[payload]" doc:name="Save developer token" variableName="developerToken"/>
<file:read doc:name="Read File" config-ref="File_Config" path="input/yourFileName"/>
<ee:transform doc:name="Transform to multipart/form-data">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output multipart/form-data
---
{
parts : {
attributes : {
headers : {
"Content-Type": "application/json"},
content : {
"name": message.attributes.fileName ,
// Set the ID of the parent folder. Use "0" for the root folder.
"parent": {
"id":"0"
}
}
},
file : {
headers : {
"Content-Disposition" : {
"name": "file",
"filename": message.attributes.fileName
}
},
content : payload
}
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<http:request method="POST" doc:name="Request - Box Upload File" url="https://upload.box.com/api/2.0/files/content" config-ref="HTTP_Request_configuration">
<http:headers ><![CDATA[#[output application/java
---
{
"Authorization" : vars.developerToken,
"Key" : "Value"
}]]]></http:headers>
</http:request>
<ee:transform doc:name="Transform Response">
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
result : "File has been successfully created"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
xml