/** * Builds a cached request id composed by the API key followed by the HTTP * verb and the destination. In the case where there's no API key the ID * will contain ApiOrgId + ApiId + ApiVersion */ private static String buildCacheID(ApiRequest request) { StringBuilder req = new StringBuilder(); if (request.getContract() != null) { req.append(request.getApiKey()); } else { req.append(request.getApiOrgId()).append(KEY_SEPARATOR).append(request.getApiId()) .append(KEY_SEPARATOR).append(request.getApiVersion()); } req.append(KEY_SEPARATOR).append(request.getType()).append(KEY_SEPARATOR) .append(request.getDestination()); return req.toString(); }
builder.append(request.getApiKey()); if (config.getGranularity() == RateLimitingGranularity.User) { String header = config.getUserHeader(); builder.append(request.getApiKey()); builder.append("||APP||"); //$NON-NLS-1$ builder.append(request.getContract().getClient().getOrganizationId()); 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(request.getRemoteAddr()); } else { builder.append(request.getApiKey()); builder.append("||SERVICE||"); //$NON-NLS-1$ builder.append(request.getContract().getApi().getOrganizationId());
if (request.getApiKey() == null) { registry.getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion(), (IAsyncResult<Api> apiResult) -> { String apiId = request.getApiId(); String apiVersion = request.getApiVersion(); String apiKey = request.getApiKey(); registry.getContract(apiOrgId, apiId, apiVersion, apiKey, (IAsyncResult<ApiContract> contractResult) -> { if (contractResult.isSuccess()) { requestMetric.setClientVersion(apiContract.getClient().getVersion()); requestMetric.setPlanId(apiContract.getPlan()); requestMetric.setContractId(request.getApiKey());
if (request.getApiKey() == null) { registry.getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion(), (IAsyncResult<Api> apiResult) -> { String apiId = request.getApiId(); String apiVersion = request.getApiVersion(); String apiKey = request.getApiKey(); registry.getContract(apiOrgId, apiId, apiVersion, apiKey, (IAsyncResult<ApiContract> contractResult) -> { if (contractResult.isSuccess()) { requestMetric.setClientVersion(apiContract.getClient().getVersion()); requestMetric.setPlanId(apiContract.getPlan()); requestMetric.setContractId(request.getApiKey());