protected static String bucketId(ApiRequest request, RateLimitingConfig config) {
        StringBuilder builder = new StringBuilder();
        if (request.getContract() == null) {
            builder.append("PUBLIC||"); //$NON-NLS-1$
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiOrgId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiVersion());
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String header = config.getUserHeader();
                if (!request.getHeaders().containsKey(header)) {
                    return NO_USER_AVAILABLE;
                }
                String user = request.getHeaders().get(header);
                builder.append("||"); //$NON-NLS-1$
                builder.append(user);
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getRemoteAddr());
            } else if (config.getGranularity() == RateLimitingGranularity.Api) {
            } else {
                return NO_CLIENT_AVAILABLE;
            }
        } else {
            builder.append(request.getApiKey());
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String header = config.getUserHeader();
                String user = request.getHeaders().get(header);
                if (user == null) {
                    return NO_USER_AVAILABLE;
                } else {
                    builder.append("||USER||"); //$NON-NLS-1$
                    builder.append(request.getContract().getClient().getOrganizationId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(request.getContract().getClient().getClientId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(user);
                }
            } else if (config.getGranularity() == RateLimitingGranularity.Client) {
                builder.append(request.getApiKey());
                builder.append("||APP||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getClientId());
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append(request.getApiKey());
                builder.append("||IP||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getRemoteAddr());
            } else {
                builder.append(request.getApiKey());
                builder.append("||SERVICE||"); //$NON-NLS-1$
                builder.append(request.getContract().getApi().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getContract().getApi().getApiId());
            }
        }
        return builder.toString();
    }
protected static String bucketId ( ApiRequest request , RateLimitingConfig config ) { StringBuilder builder = new StringBuilder ( ) ; if ( request . getContract ( ) == null ) { builder . append ( "PUBLIC||" ) ; builder . append ( "||" ) ; builder . append ( request . getApiOrgId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getApiId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getApiVersion ( ) ) ; if ( config . getGranularity ( ) == RateLimitingGranularity . User ) { String header = config . getUserHeader ( ) ; if ( ! request . getHeaders ( ) . containsKey ( header ) ) { return NO_USER_AVAILABLE ; } String user = request . getHeaders ( ) . get ( header ) ; builder . append ( "||" ) ; builder . append ( user ) ; } else if ( config . getGranularity ( ) == RateLimitingGranularity . Ip ) { builder . append ( "||" ) ; builder . append ( request . getRemoteAddr ( ) ) ; } else if ( config . getGranularity ( ) == RateLimitingGranularity . Api ) { } else { return NO_CLIENT_AVAILABLE ; } } else { builder . append ( request . getApiKey ( ) ) ; if ( config . getGranularity ( ) == RateLimitingGranularity . User ) { String header = config . getUserHeader ( ) ; String user = request . getHeaders ( ) . get ( header ) ; if ( user == null ) { return NO_USER_AVAILABLE ; } else { builder . append ( "||USER||" ) ; builder . append ( request . getContract ( ) . getClient ( ) . getOrganizationId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getContract ( ) . getClient ( ) . getClientId ( ) ) ; builder . append ( "||" ) ; builder . append ( user ) ; } } else if ( config . getGranularity ( ) == RateLimitingGranularity . Client ) { builder . append ( request . getApiKey ( ) ) ; builder . append ( "||APP||" ) ; builder . append ( request . getContract ( ) . getClient ( ) . getOrganizationId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getContract ( ) . getClient ( ) . getClientId ( ) ) ; } else if ( config . getGranularity ( ) == RateLimitingGranularity . Ip ) { builder . append ( request . getApiKey ( ) ) ; builder . append ( "||IP||" ) ; builder . append ( request . getContract ( ) . getClient ( ) . getOrganizationId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getRemoteAddr ( ) ) ; } else { builder . append ( request . getApiKey ( ) ) ; builder . append ( "||SERVICE||" ) ; builder . append ( request . getContract ( ) . getApi ( ) . getOrganizationId ( ) ) ; builder . append ( "||" ) ; builder . append ( request . getContract ( ) . getApi ( ) . getApiId ( ) ) ; } } return builder . toString ( ) ; }
Creates the ID of the rate bucket to use.  The ID is composed differently
depending on the configuration of the policy.

@param request
@param config