HTTP Connector XML リファレンス

HTTP 用 Anypoint Connector (HTTP Connector) は、イベントのリスンや、HTTP または HTTPS プロトコルに基づいた操作を実行します。HTTPS プロトコルを使用する場合、コネクタには TLS コンテキスト子要素の設定が必要です。次の例は、XML での HTTP Connector のソースと操作の設定を示しています。

HTTP Listener の XML 設定例

http:listener-config​ 親要素では、リスン ​port​ や ​tls:context​ などの接続要素が、子 ​http:listener-connection​ 要素内に整理されています。次の例は、XML 設定を示しています。

<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:listener​ ソースの XML 設定を示しています。

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

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

HTTP オブジェクト Mule Runtime Engine 3.x Mule Runtime Engine 4.x

Method (メソッド)

#[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]

Version (バージョン)

#[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 の XML 設定例

http:request-config​ 親要素では、要求の接続要素が、子 ​http:request-connection​ 要素内に整理されています。次の例は、XML 設定を示しています。

<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:request​ 操作の XML 設定を示しています。

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

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

HTTP オブジェクト Mule Runtime Engine 3.x Mule Runtime Engine 4.x

状況コード

#[inboundProperties.’http.status]

#[attributes.statusCode]

理由を示す語句

#[inboundProperties.’http.reason’]

#[attributes.reasonPhrase]

ヘッダー

#[inboundProperties]

#[attributes.headers]

HTTP Load Static Resource の XML 設定例

次の例は、フロー内の ​http:load-static-resource​ 操作の XML 設定を示しています。

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

HTTP Basic Security Filter の XML 設定例

次の例は、フロー内の ​http:basic-security-filter​ 操作の XML 設定を示しています。

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

HTTP 要求、応答、エラー応答の本文の XML の例

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

次の例は、カスタム ​body​、キー/値 ​query-parameter​、X-Custom ​header​、URI パラメーター ​uriParam​ を入力する ​uriParamsMap​ 変数を含む ​uri-params​ を定義する、​http:request​ 操作の XML 設定を示しています。

<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>

次の例は、定義された ​body​ 要素が欠けている ​http:listener​ ソースの XML 設定を示しています。返される値は、デフォルトのペイロードです。このペイロードには実行に成功した場合の ​http:response​ が定義されており、​statusCode​ として ​200​、​reasonPhrase​ として ​Ok​、​headers​ の ​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>

次の例は、実行に失敗した場合の応答を定義する ​http:listener​ ソースの XML 設定を示しています。​statusCode​ として ​502​、​reasonPhrase​ として ​Failure​、​headers​ の ​Error​ に ​FIRE​、​body​ に ​Oops, something is wrong​ を返します。

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