RESTMessageV2 MID サーバーの例

  • リリースバージョン: Yokohama
  • 更新日 2025年01月30日
  • 所要時間:2分
  • MID Server 経由で送信 REST メッセージを送信できます。

    MID Server 経由でメッセージを送信することで、ファイアウォールの背後またはプライベートネットワーク内にあるエンドポイントにアクセスできます。MID Server 経由で送信される REST メッセージはすべて非同期になります。

    var requestBody;
    var responseBody;
    var status;
    var sm;
    try{
    	sm = new sn_ws.RESTMessageV2("Yahoo Finance", "get");  // Might throw exception if message doesn't exist or not visible due to scope.
    	sm.setBasicAuth("admin","admin");
    	sm.setStringParameter("symbol", "NOW");
    	sm.setStringParameterNoEscape("xml_data","<data>test</data>");
    	sm.setMIDServer('mid_server_name');
    	response = sm.executeAsync(); // Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
    
    	response.waitForResponse(60); // In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue.
    
    	responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
    	status = response.getStatusCode();
    } catch(ex) {
    	responseBody = ex.getMessage();
    	status = '500';
    } finally {
    	requestBody = sm ? sm.getRequestBody():null;
    }
    gs.info("Request Body: " + requestBody);
    gs.info("Response: " + responseBody);
    gs.info("HTTP Status: " + status);
    注:
    この例では、waitForResponse を使用して応答を一時停止し、応答の処理方法を詳しく説明します。ただし、executeAsync を使用する場合は、waitForResponse を使用するのではなく、応答本文を別のビジネスルールで処理して非同期呼び出しを利用する方法を検討してください。