---
schema_version: "1"
id: f3032ea98bc643d2b954468ed24f4af8b726758d3dc8a929efb2605114fedb84
title: 静的リソースの読み込みの例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/http-connector/1.10/http-load-static-res-task.md
canonical_url: https://docs.mulesoft.com/jp/http-connector/1.10/http-load-static-res-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 31ebe1a157cbf901058a6f29736234390b111dd99c45d057dc0340c5fd1c8367
description: MuleSoft Documentation Site
release: "1.10"
latest: true
---
# 静的リソースの読み込みの例

HTTP 用 Anypoint Connector (HTTP Connector) の ​**Load static resource**​ 操作を使用すると、ホームページやスクリプトなどの静的リソースを読み込むことができます。読み込むリソースのパスとファイル名を指定して操作を設定できます。必要に応じて、同じディレクトリ内の別のファイルの名前を、失敗時に使用するリソースとして設定することもできます。

次の例は、リソースをルックアップするための要求パスを使用して HTTP で使用する静的コンテンツを提供するように、HTTP ​**Listener**​ ソースと ​**Load static resource**​ 操作を設定する方法を示しています。この例を実行するには、Mule アプリケーションを作成し、HTTP グローバル要素を設定し、アプリケーションを実行し、curl コマンドでアプリケーションをテストする必要があります。

次のスクリーンショットは、この例の Anypoint Studio アプリケーションフローを示しています。

![静的リソースの読み込みのフロー](/mulesoft/current/ja-jp/http-connector/1.10/_images/http-loadresource-flow.png)

## [](#mule-アプリケーションの作成)Mule アプリケーションの作成

Mule フローを作成する手順は、次のとおりです。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、\[HTTP\] の ​**\[Listener\]**​ ソースを選択してキャンバスにドラッグします。  
    このソースは受信 HTTP メッセージ属性をリスンすることでフローを開始します。
2. Web ブラウザーからアプリケーションを開始するように ​**\[Path (パス)\]**​ 項目を ​`/trigger`​ に設定します。
3. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内の HTTP ​**Listener**​ のすべてのインスタンスで使用できるグローバル要素を設定します。
4. **\[General (一般)\]**​ タブで、次の項目を設定します。
    
    - **Host (ホスト)**​: `All Interfaces [0.0.0.0] (default)`
    - **Port (ポート)**​: `8081`
5. **\[OK\]**​ をクリックします。
    
    ![HTTP リスナーのグローバル設定](/mulesoft/current/ja-jp/http-connector/1.10/_images/http-startapp-example-1.png)
6. **\[Load static resource\]**​ 操作を \[HTTP\] の ​**\[Listener\]**​ ソースの右にドラッグします。
7. **\[Resource base path (リソースベースパス)\]**​ 項目を ​`/Users/max/Sites/index.html`​ に設定します。
8. **\[Default file (デフォルトファイル)\]**​ 項目をリソースと同じディレクトリにあるバックアップファイルの名前 (​`index.html`​ など) に設定します。  
    Mule プロジェクトへの相対パスを使用する必要がある場合は、変数 ​`${app.workDir}`​ を使用します。例: `resourceBasePath="${app.workDir}/images/"`​。失敗した場合、アプリケーションはバックアップファイルを読み込みます。
    
    ![HTTP の Load static resource の設定](/mulesoft/current/ja-jp/http-connector/1.10/_images/http-loadresource-example-1.png)
9. Mule アプリケーションを保存します。
10. **Package Explorer**​ でプロジェクト名をクリックし、​**\[Run (実行)\]**​ > ​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
11. ブラウザーウィンドウで URL ​`http://0.0.0.0:8081/trigger`​ を入力します。  
    リソースのコンテンツがブラウザーに表示されます。

## [](#静的リソースを読み込むための-xml)静的リソースを読み込むための XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

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


<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:core="http://www.mulesoft.org/schema/mule/core" 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:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<core:flow name="Flow" >
		<http:listener doc:name="Listener"  config-ref="HTTP_Listener_config"/>
		<http:load-static-resource doc:name="Load static resource" resourceBasePath="/Users/max/Sites/index.html" attributes="attributes"/>
	</core:flow>
</mule>
```

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)