HTTP Connector XML リファレンス

HTTP Connector は、イベントのリスンや、HTTP または HTTPS プロトコルに基づいた操作の実行を行います。HTTPS プロトコルを使用するには、設定に TLS コンテキスト子要素が必要です (次のセクションで説明)。Mule 4.0 以降では、リスナーおよび要求属性にアクセスするための DataWeave 構文がサポートされます。Mule では引き続き Mule Expression Language (MEL) がサポートされます。このドキュメントの各表では両方の構文がマップされています。

リスナー

listener-config 親要素では、リスンポートや tls:context などの接続要素が、子 listener-connection 要素内に整理されています。接続要素は、http:listener-config の子要素です (次のコードを参照)。

<http:listener-config name="lisConfig" basePath="api">
  <http:listener-connection protocol="https" port="${serverPort}" host="localhost" usePersistentConnections="true">
    <tls:context>
      <tls:key-store path="keystore.jks" keyPassword="key" password="pass"/>
    </tls:context>
  </http:listener-connection>
</http:listener-config>

次のコードは、HTTP リスナーをフローに配置します。

<flow name="server">
  <http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
  <logger message="HEY"/>
</flow>

HTTP リスナー属性にアクセスするには、次の表に示す DataWeave 構文を使用します。

HTTP オブジェクト 3.x 4.x

メソッド

#[inboundProperties.’http.method’]

#[attributes.method]

Path (パス)

#[inboundProperties.’http.listener.path’]

#[attributes.listenerPath]

相対パス

#[inboundProperties.’http.relative.path’]

#[attributes.relativePath]

要求 URI

#[inboundProperties.’http.request.uri’]

#[attributes.requestUri]

クエリ文字列

#[inboundProperties.’http.query.string’]

#[attributes.queryString]

クエリパラメーター

#[inboundProperties.’http.query.params’]

#[attributes.queryParams]

URI パラメーター

#[inboundProperties.’http.uri.params’]

#[attributes.uriParams]

バージョン

#[inboundProperties.’http.version’]

#[attributes.version]

スキーマ

#[inboundProperties.’http.scheme’]

#[attributes.scheme]

ヘッダー

#[inboundProperties]

#[attributes.headers]

リモートアドレス

#[inboundProperties.’http.remote.address’]

#[attributes.remoteAddress]

クライアント証明書

#[inboundProperties.’http.client.cert’]

#[attributes.clientCertificate]

HTTP 要求

リスナーと同様に、request-config 親要素では、要求の接続要素が子 request-connection 要素内に整理されています (次のコードを参照)。

<http:request-config name="reqConfig" basePath="api/v2">
  <http:request-connection protocol="HTTP" port="${clientPort}" host="localhost">
    <tls:context>
      <tls:trust-store path="ssltest-cacerts.jks" password="changeit"/>
    </tls:context>
    <http:authentication>
      <http:basic-authentication username="#[user]" password="#[password]" preemptive="#[preemptive]" />
    </http:authentication>
  </http:request-connection>
</http:requester-config>

次のコードは、HTTP 要求をフローに配置します。HTTP 要求は HttpResponseAttributes を返します。

<flow name="client">
   <http:request path="/" config-ref="reqConfig"/>
</flow>

HTTP 要求属性にアクセスするには、次の表に示す DataWeave 構文を使用します。

HTTP オブジェクト 3.x 4.x

状況コード

#[inboundProperties.’http.status]

#[attributes.statusCode]

理由を示す語句

#[inboundProperties.’http.reason’]

#[attributes.reasonPhrase]

ヘッダー

#[inboundProperties]

#[attributes.headers]

HTTP 要求、応答、およびエラー応答の本文

HTTP 要求、応答、およびエラー応答の本文は、必要に応じて定義します。本文要素を明示的に定義しない場合、要求または応答はデフォルトのペイロードを返します。

次の例の要求では、Custom body (カスタム本文)、キー=値クエリパラメーター、値が ​custom​ の X-Custom ヘッダーが定義されます。​uriParamsMap​ 変数によって URI パラメーター ​uriParam​ が入力されます。

<http:request path="/{uriParam}/test"  config-ref="reqConfig">
   <http:body>
       #['Custom body']
   </http:body>
   <http:headers>
       #[{'X-Custom' : 'custom'}]
   </http:headers>
   <http:uri-params>
       #[uriParamsMap]
   </http:uri-params>
   <http:query-params>
       #[{'key’' : 'value’'}]
   </http:query-params>
</http:request>

次のコードには、明示的に定義された本文要素がありません。返される値は、デフォルトのペイロードです。このペイロードには成功した実行の応答が定義されており、状況コード 200、理由を示す語句 ​Ok​、ヘッダーとして ​Name​ とその値 ​content​ および ​Something​ とその値 ​someValue​ が含まれます。

<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
   <http:response statusCode="200" reasonPhrase="Ok">
       <http:headers>
           #[{"Name" : "content", "Something" : someValue}]
       </http:headers>
   </http:response>
</http:listener>

次のコードには失敗した実行の応答が定義されており、状況コード 502、理由を示す語句 ​Failure​、ヘッダーとして ​Error​ とその値 ​FIRE​、本文として ​Oops, something went terribly wrong​ が含まれます。

<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
   <http:error-response statusCode="502" reasonPhrase="Failure">
       <http:body>
           #[‘Oops, something went terribly wrong.’]
       </http:body>
       <http:headers>
           #[{"Error" : "FIRE"}]
       </http:headers>
   </http:error-response>
</http:listener>

HTTP 操作リファレンス

次のコードは、静的リソースの読み込み操作の構文を示します。

<flow name="server">
   <http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
   <http:load-static-resource resourceBasePath="root" defaultFile="index.html"/>
</flow>

次の例は、基本セキュリティ条件操作の構文を示します。

<flow name="listenerBasicAuth">
   <http:listener config-ref="listenerConfigBasicAuth" path="/basic"/>
   <http:basic-security-filter realm="mule-realm"/>
   <logger message="TestBasicAuthOk"/>
</flow>