/** * 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(); }
/** * Checks the API unique identifier against what this contract expects (org id, id, version). * Returns true if they match. * @param request the request * @return true if the given request matches this contract */ public boolean matches(ApiRequest request) { String apiOrgId = request.getApiOrgId(); String apiId = request.getApiId(); String apiVersion = request.getApiVersion(); return matches(apiOrgId, apiId, apiVersion); }
/** * 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())); } }
builder.append("PUBLIC||"); //$NON-NLS-1$ builder.append("||"); //$NON-NLS-1$ builder.append(request.getApiOrgId()); builder.append("||"); //$NON-NLS-1$ builder.append(request.getApiId());
requestMetric.setResource(request.getDestination()); requestMetric.setMethod(request.getType()); requestMetric.setApiOrgId(request.getApiOrgId()); requestMetric.setApiId(request.getApiId()); requestMetric.setApiVersion(request.getApiVersion()); registry.getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion(), (IAsyncResult<Api> apiResult) -> { if (apiResult.isSuccess()) { String apiOrgId = request.getApiOrgId(); String apiId = request.getApiId(); String apiVersion = request.getApiVersion(); policies = apiContract.getPolicies(); policyImpls = new ArrayList<>(policies.size()); if (request.getApiOrgId() != null) { try { validateRequest(request);
requestMetric.setResource(request.getDestination()); requestMetric.setMethod(request.getType()); requestMetric.setApiOrgId(request.getApiOrgId()); requestMetric.setApiId(request.getApiId()); requestMetric.setApiVersion(request.getApiVersion()); registry.getApi(request.getApiOrgId(), request.getApiId(), request.getApiVersion(), (IAsyncResult<Api> apiResult) -> { if (apiResult.isSuccess()) { String apiOrgId = request.getApiOrgId(); String apiId = request.getApiId(); String apiVersion = request.getApiVersion(); policies = apiContract.getPolicies(); policyImpls = new ArrayList<>(policies.size()); if (request.getApiOrgId() != null) { try { validateRequest(request);