---
schema_version: "1"
id: 005ace8ff9184ee68b3bda1a625beaaa0c461fcd48dc7c0c9ad39664e474976a
title: 異なるパスへの HTTP 要求の転送の例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/http-connector/1.5/http-conn-route-diff-paths-task.md
canonical_url: https://docs.mulesoft.com/jp/http-connector/1.5/http-conn-route-diff-paths-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e778b8f41ac83e4b78f2dea5d3d856c9141d7e25480e670427023f58daeb2e63
description: MuleSoft Documentation Site
release: "1.5"
latest: false
---
# 異なるパスへの HTTP 要求の転送の例

次の例には複数のフローがあり、各フローに、異なるサブパスへの要求をリスンする HTTP 用 Anypoint Connector (HTTP Connector) の Listener ソースがあります。

- `http://localhost:8081/account`​ 宛ての HTTP 要求は最初のフローに転送されます。
- `http://localhost:8081/employee`​ 宛ての HTTP 要求は 2 つ目のフローに転送されます。
- HTTP リスナーで定義されたパスに HTTP 要求が一致しない場合、コネクタは HTTP ​`404 Resource Not Found`​ エラーを返します。

この例を実行するには、Mule アプリケーションを作成し、HTTP グローバル要素を設定し、アプリケーションを実行し、curl コマンドでアプリケーションをテストする必要があります。

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

![パスへの HTTP 要求のフロー](/mulesoft/current/ja-jp/http-connector/1.5/_images/request-mule-msg-map.png)

Figure 1. パスへの HTTP 要求のフロー

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

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

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、\[HTTP\] の ​**\[Listener\]**​ ソースを選択してキャンバスにドラッグします。  
    このソースは受信 HTTP メッセージ属性をリスンすることでフローを開始します。
2. Web ブラウザーからアプリケーションを開始するように ​**\[Path (パス)\]**​ 項目を ​`account`​ に設定します。
3. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内の HTTP の ​**Listener**​ のすべてのインスタンスで使用できるグローバル要素を設定します。
4. **\[General (一般)\]**​ タブで、次の項目を設定します。
    
    - **Host (ホスト)**​: `localhost`
    - **Port (ポート)**​: `8081`
5. **\[OK\]**​ をクリックします。
    
    ![HTTP リスナーのグローバル設定](/mulesoft/current/ja-jp/http-connector/1.5/_images/http-route-example-1.png)
    
    Figure 2. HTTP リスナーのグローバル設定
    
    ![HTTP リスナーの設定](/mulesoft/current/ja-jp/http-connector/1.5/_images/http-route-example-2.png)
    
    Figure 3. HTTP リスナーの設定
6. **\[Logger\]**​ コンポーネントを \[HTTP\] の ​**\[Listener\]**​ ソースの右にドラッグします。
7. 2 番目のフローを作成するには、\[HTTP\] の別の ​**\[Listener\]**​ を最初のフローの下にドラッグします。
8. **\[Connector configuration (コネクタ設定)\]**​ 項目では、\[HTTP\] の最初の ​**\[Listener\]**​ ソースで作成したものと同じ ​`HTTP_Listener_config`​ 設定を選択します。
9. **\[Path (パス)\]**​ 項目を ​`employee`​ に設定します。
    
    ![HTTP リスナーの設定](/mulesoft/current/ja-jp/http-connector/1.5/_images/http-route-example-2.png)
    
    Figure 4. HTTP リスナーの設定
10. **\[Logger\]**​ コンポーネントを \[HTTP\] の 2 番目の ​**\[Listener\]**​ ソースの右にドラッグします。
11. Mule アプリケーションを保存します。
12. **Package Explorer**​ でプロジェクト名をクリックし、​**\[Run (実行)\]**​ > ​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
13. ブラウザーウィンドウを開き、最初の URL (​`http://localhost:8081/account`​) を入力します。
14. 別のブラウザーウィンドウを開き、2 番目の URL (​`http://localhost:8081/employee`​) を入力します。
15. ログに、最初のフローに転送された要求と、2 番目のフローに転送された要求がそれぞれ表示されることを確認します。

## [](#http-要求を転送するための-xml)HTTP 要求を転送するための XML

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

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

<mule 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:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<flow name="Flow1" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="path"/>
		<logger level="INFO" doc:name="Logger" />
	</flow>
	<flow name="Flow2" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="employee"/>
		<logger level="INFO" doc:name="Logger" />
	</flow>
</mule>
```

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

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