public Object[] parseParameterFor(String resource, T request, Predicate<GatewayFlowRule> rulePredicate) {
        if (StringUtil.isEmpty(resource) || request == null || rulePredicate == null) {
            return new Object[0];
        }
        Set<GatewayFlowRule> gatewayRules = new HashSet<>();
        Set<Boolean> predSet = new HashSet<>();
        boolean hasNonParamRule = false;
        for (GatewayFlowRule rule : GatewayRuleManager.getRulesForResource(resource)) {
            if (rule.getParamItem() != null) {
                gatewayRules.add(rule);
                predSet.add(rulePredicate.test(rule));
            } else {
                hasNonParamRule = true;
            }
        }
        if (!hasNonParamRule && gatewayRules.isEmpty()) {
            return new Object[0];
        }
        if (predSet.size() > 1 || predSet.contains(false)) {
            return new Object[0];
        }
        int size = hasNonParamRule ? gatewayRules.size() + 1 : gatewayRules.size();
        Object[] arr = new Object[size];
        for (GatewayFlowRule rule : gatewayRules) {
            GatewayParamFlowItem paramItem = rule.getParamItem();
            int idx = paramItem.getIndex();
            String param = parseInternal(paramItem, request);
            arr[idx] = param;
        }
        if (hasNonParamRule) {
            arr[size - 1] = SentinelGatewayConstants.GATEWAY_DEFAULT_PARAM;
        }
        return arr;
    }
@Test
    public void testParseParametersWithItems() {
        RequestItemParser<Object> itemParser = mock(RequestItemParser.class);
        GatewayParamParser<Object> paramParser = new GatewayParamParser<>(itemParser);
        // Create a fake request.
        Object request = new Object();

        // Prepare gateway rules.
        Set<GatewayFlowRule> rules = new HashSet<>();
        final String routeId1 = "my_test_route_A";
        final String api1 = "my_test_route_B";
        final String headerName = "X-Sentinel-Flag";
        final String paramName = "p";
        final String cookieName = "myCookie";
        GatewayFlowRule routeRuleNoParam = new GatewayFlowRule(routeId1)
            .setCount(10)
            .setIntervalSec(10);
        GatewayFlowRule routeRule1 = new GatewayFlowRule(routeId1)
            .setCount(2)
            .setIntervalSec(2)
            .setBurst(2)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_CLIENT_IP)
            );
        GatewayFlowRule routeRule2 = new GatewayFlowRule(routeId1)
            .setCount(10)
            .setIntervalSec(1)
            .setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER)
            .setMaxQueueingTimeoutMs(600)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
                .setFieldName(headerName)
            );
        GatewayFlowRule routeRule3 = new GatewayFlowRule(routeId1)
            .setCount(20)
            .setIntervalSec(1)
            .setBurst(5)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_URL_PARAM)
                .setFieldName(paramName)
            );
        GatewayFlowRule routeRule4 = new GatewayFlowRule(routeId1)
            .setCount(120)
            .setIntervalSec(10)
            .setBurst(30)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HOST)
            );
        GatewayFlowRule routeRule5 = new GatewayFlowRule(routeId1)
            .setCount(50)
            .setIntervalSec(30)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_COOKIE)
                .setFieldName(cookieName)
            );
        GatewayFlowRule apiRule1 = new GatewayFlowRule(api1)
            .setResourceMode(SentinelGatewayConstants.RESOURCE_MODE_CUSTOM_API_NAME)
            .setCount(5)
            .setIntervalSec(1)
            .setParamItem(new GatewayParamFlowItem()
                .setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_URL_PARAM)
                .setFieldName(paramName)
            );
        rules.add(routeRule1);
        rules.add(routeRule2);
        rules.add(routeRule3);
        rules.add(routeRule4);
        rules.add(routeRule5);
        rules.add(routeRuleNoParam);
        rules.add(apiRule1);
        GatewayRuleManager.loadRules(rules);

        final String expectedHost = "hello.test.sentinel";
        final String expectedAddress = "66.77.88.99";
        final String expectedHeaderValue1 = "Sentinel";
        final String expectedUrlParamValue1 = "17";
        final String expectedCookieValue1 = "Sentinel-Foo";

        mockClientHostAddress(itemParser, expectedAddress);
        Map<String, String> expectedHeaders = new HashMap<String, String>() {{
            put(headerName, expectedHeaderValue1); put("Host", expectedHost);
        }};
        mockHeaders(itemParser, expectedHeaders);
        mockSingleUrlParam(itemParser, paramName, expectedUrlParamValue1);
        mockSingleCookie(itemParser, cookieName, expectedCookieValue1);

        Object[] params = paramParser.parseParameterFor(routeId1, request, routeIdPredicate);
        // Param length should be 6 (5 with parameters, 1 normal flow with generated constant)
        assertThat(params.length).isEqualTo(6);
        assertThat(params[routeRule1.getParamItem().getIndex()]).isEqualTo(expectedAddress);
        assertThat(params[routeRule2.getParamItem().getIndex()]).isEqualTo(expectedHeaderValue1);
        assertThat(params[routeRule3.getParamItem().getIndex()]).isEqualTo(expectedUrlParamValue1);
        assertThat(params[routeRule4.getParamItem().getIndex()]).isEqualTo(expectedHost);
        assertThat(params[routeRule5.getParamItem().getIndex()]).isEqualTo(expectedCookieValue1);
        assertThat(params[params.length - 1]).isEqualTo(SentinelGatewayConstants.GATEWAY_DEFAULT_PARAM);

        assertThat(paramParser.parseParameterFor(api1, request, routeIdPredicate).length).isZero();

        String expectedUrlParamValue2 = "fs";
        mockSingleUrlParam(itemParser, paramName, expectedUrlParamValue2);
        params = paramParser.parseParameterFor(api1, request, apiNamePredicate);
        assertThat(params.length).isEqualTo(1);
        assertThat(params[apiRule1.getParamItem().getIndex()]).isEqualTo(expectedUrlParamValue2);
    }