UriMatcherResponse :スコープ指定

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:9分
  • URI が、スキーム、ホスト、パス、フラグメント、およびクエリパラメーターの存在に関して指定された基準と一致するかどうかに関する情報を返すメソッドを提供します。

    この API を UriMatcher API とともに使用します。この API にはコンストラクターがありません。代わりに、 UriMatcher - match() メソッドを使用して UriMatcherResponse オブジェクトをインスタンス化します。

    UriMatcherResponse API には、デフォルトでアクティブになっている REST API プロバイダー (com.glide.rest) プラグインが必要です。

    この API は、 sn_ws 名前空間内で提供されます。

    UriMatcherResponse:getErrorMessages()

    指定された基準で URI をテストしたときに発生したエラーに関するメッセージを返します。

    表 : 1. パラメーター
    名前 タイプ 説明
    なし
    表 : 2. 返される内容
    タイプ 説明
    文字列 発生したエラーの説明。エラーが発生しなかった場合は、空の文字列が返されます。

    この例では、ホストが一致基準で指定されなかったため、エラーが返されます。

    var uri = "https://example.com";
    var scheme = "https";    
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme);  
    
    gs.info("Error occurred: " + resp.isError());  
    gs.info("Error message: " + resp.getErrorMessages());

    出力:

    Error occurred: true
    Error message: Hosts rule is null or empty.

    UriMatcherResponse:isError()

    指定された基準に照らして URI をテストしたときにエラーが発生したかどうかを確認します。

    表 : 3. パラメーター
    名前 タイプ 説明
    なし
    表 : 4. 返される内容
    タイプ 説明
    ブーリアン

    エラーが発生したかどうかを示すフラグ。

    有効な値:
    • true:エラーが発生しました。
    • false:エラーは発生しませんでした。

    この例では、URI にクエリーパラメーターが含まれているため、エラーが返されます。このエラーは、disallowQueryParametersmatch() に渡された引数が true であるために発生します。

    var uri = "https://example.com/path1/more?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var allowedFragments = ["section1", "section2"];  
    var noQueryParams = true;
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments, noQueryParams);  
    
    gs.info("Error occurred: " + resp.isError());  
    gs.info("Error message: " + resp.getErrorMessages());

    出力:

    Error occurred: true
    Error message: Query parameters are not allowed for matching.

    UriMatcherResponse:isFragmentMatches()

    URI がフラグメントのクライテリアに一致するかどうかを確認します。

    表 : 5. パラメーター
    名前 タイプ 説明
    なし
    表 : 6. 返される内容
    タイプ 説明
    ブーリアン

    URI がフラグメントの基準と一致するかどうかを示すフラグ。

    有効な値:
    • true:URI はフラグメントの基準と一致します。
    • false:URI がフラグメントの基準と一致しません。

    この例は、許可されたフラグメントのリストにないフラグメントが含まれているため、URI が基準と一致しないことを示しています。

    var uri = "https://example.com/path1/more#section3";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var allowedFragments = ["section1", "section2"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments);  
    
    gs.info("Is URI a match: " + resp.isMatch());  
    gs.info("Is scheme a match: " + resp.isSchemeMatches());  
    gs.info("Is host a match: " + resp.isHostMatches());  
    gs.info("Is path a match: " + resp.isPathMatches());  
    gs.info("Is fragment a match: " + resp.isFragmentMatches());
    gs.info("Error occurred: " + resp.isError());

    出力:

    Is URI a match: false
    Is scheme a match: true
    Is host a match: true
    Is path a match: true
    Is fragment a match: false
    Error occurred: false

    UriMatcherResponse:isHostMatches()

    URI がホストの基準と一致するかどうかを確認します。

    表 : 7. パラメーター
    名前 タイプ 説明
    なし
    表 : 8. 返される内容
    タイプ 説明
    ブーリアン

    URI がホストの基準と一致するかどうかを示すフラグ。

    有効な値:
    • true:URI はホストの基準と一致します。
    • false:URI がホストの基準と一致しません。

    この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());
    gs.info("Is host a match: " + resp.isHostMatches());

    出力:

    Is URI a match: true
    Is host a match: true

    UriMatcherResponse:isMatch()

    URI が指定されたすべての基準に一致するかどうかを確認します。

    表 : 9. パラメーター
    名前 タイプ 説明
    なし
    表 : 10. 返される内容
    タイプ 説明
    ブーリアン

    URI が指定されたすべての基準に一致するかどうかを示すフラグ。

    有効な値:
    • true:URI はすべての条件に一致します。
    • false:URI はすべての基準と一致しません。

    この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());

    出力:

    Is URI a match: true

    UriMatcherResponse:isPathMatches()

    URI がパスの基準と一致するかどうかを確認します。

    表 : 11. パラメーター
    名前 タイプ 説明
    なし
    表 : 12. 返される内容
    タイプ 説明
    ブーリアン

    URI がパスの基準と一致するかどうかを示すフラグ。

    有効な値:
    • true:URI はパスの基準と一致します。
    • false:URI がパスの基準と一致しません。

    この例では、URI が指定されたスキーム、ホスト、およびパスと一致するかどうかを確認します。

    var uri = "https://example.com/path1/more";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths);  
    
    gs.info("Is URI a match: " + resp.isMatch());  
    gs.info("Is scheme a match: " + resp.isSchemeMatches());  
    gs.info("Is host a match: " + resp.isHostMatches());  
    gs.info("Is path a match: " + resp.isPathMatches());  
    gs.info("Is fragment a match: " + resp.isFragmentMatches());
    gs.info("Error occurred: " + resp.isError());

    出力:

    Is URI a match: true
    Is scheme a match: true
    Is host a match: true
    Is path a match: true
    Is fragment a match: true
    Error occurred: false

    UriMatcherResponse:isSchemeMatches()

    URI がスキームの基準と一致するかどうかを確認します。

    表 : 13. パラメーター
    名前 タイプ 説明
    なし
    表 : 14. 返される内容
    タイプ 説明
    ブーリアン

    URI がスキームの基準と一致するかどうかを示すフラグ。

    有効な値:
    • true:URI はスキームの基準と一致します。
    • false:URI がスキームの基準と一致しません。

    この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());
    gs.info("Is scheme a match: " + resp.isSchemeMatches());

    出力:

    Is URI a match: true
    Is scheme a match: true