古いインターフェイスのように見える新しいバックエンドにプロキシを実装するためにラクダを使用しています。古い API にはリクエスト本文にユーザー名とパスワードの資格情報があり、新しいバックエンド サービスは基本認証を使用します。un/pw を抽出し、XML データベースに対して単純なルックアップを行い (資格情報が正確にマップされない可能性があります)、base64 でエンコードされた文字列として正しい資格情報を返す XSL があります。これを http 認証ヘッダー値として設定する方法がわかりません (たとえば、.setHeader() 呼び出しで XSL 変換を式として処理する方法)。
次のような SOAP リクエストがあります。
<soapenv:Envelope>
<soapenv:Body>
<XService>
<_Header username="demo" password="demo"/>
<_Body>
<_RequestParameters xsi:type="RequestServiceReport">
...
</_RequestParameters>
</_Body>
</XService>
</soapenv:Body>
私のルート(Java DSLを使用)は次のようになります。
from("jetty:http://161.228.88.168:8080/sap2rjm")
.choice()
.when().simple("${header.channel}")
...
.when().simple("${in.header.emx} == 'authenticate'")
...
.endChoice()
// If the request is for a report, route it to the new service
.when().xpath("//_RequestParameters[@type='RequestServiceReport']")
// TODO: How to get header from the body of the message and set as the header value?
// Stylesheet transform_credentials will extract username/password from body, transform
// for the new service (dev.reportjam) and will base4 encode to produce a string like this one...
.setHeader("Authorization", constant("Basic ZGVtbzpkZW1v"))
.to("xslt:transform_request.xsl")
.to("http://dev.reportjam.com/services/ReportMix?bridgeEndpoint=true")
.to("xslt:transform_response.xsl")
.removeHeaders("*")
.endChoice()
.otherwise()
...
.endChoice()
.end();
SOAP リクエストを処理し、un/pw を抽出し、ロジックを適用して変換し、base64 でエンコードする別のスタイルシートがありますが、上記の setHeader() 呼び出しでこれを呼び出す方法がわかりません。
ありがとう