/** * 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(); }
if (request.getContract() == null) { builder.append("PUBLIC||"); //$NON-NLS-1$ builder.append("||"); //$NON-NLS-1$ } 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); 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()); 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());
/** * Validates that the contract being used for the request is valid against the * api information included in the request. Basically the request includes * information indicating which specific api is being invoked. This method * ensures that the api information in the contract matches the requested * api. * @param request the request to validate */ protected void validateRequest(ApiRequest request) throws InvalidContractException { ApiContract contract = request.getContract(); boolean matches = true; if (!contract.getApi().getOrganizationId().equals(request.getApiOrgId())) { matches = false; } if (!contract.getApi().getApiId().equals(request.getApiId())) { matches = false; } if (!contract.getApi().getVersion().equals(request.getApiVersion())) { matches = false; } if (!matches) { throw new InvalidContractException(Messages.i18n.format("EngineImpl.InvalidContractForApi", //$NON-NLS-1$ request.getApiOrgId(), request.getApiId(), request.getApiVersion())); } }
/** * Validates that the contract being used for the request is valid against the * api information included in the request. Basically the request includes * information indicating which specific api is being invoked. This method * ensures that the api information in the contract matches the requested * api. * @param request the request to validate */ protected void validateRequest(ApiRequest request) throws InvalidContractException { ApiContract contract = request.getContract(); boolean matches = true; if (!contract.getApi().getOrganizationId().equals(request.getApiOrgId())) { matches = false; } if (!contract.getApi().getApiId().equals(request.getApiId())) { matches = false; } if (!contract.getApi().getVersion().equals(request.getApiVersion())) { matches = false; } if (!matches) { throw new InvalidContractException(Messages.i18n.format("EngineImpl.InvalidContractForApi", //$NON-NLS-1$ request.getApiOrgId(), request.getApiId(), request.getApiVersion())); } }