public List<IPolicyProbeResponse> probePolicy(Long contractId, long policyId, String rawPayload)
            throws ClientNotFoundException, ContractNotFoundException {
        ContractBean contract = getContract(contractId);
        ApiVersionBean avb = contract.getApi();
        OrganizationBean apiOrg = avb.getApi().getOrganization();
        String apiKey = contract.getClient().getApikey();
        Set<String> gatewayIds = contract.getApi()
                .getGateways()
                .stream()
                .map(ApiGatewayBean::getGatewayId)
                .collect(Collectors.toSet());
        if (gatewayIds.size() == 0) {
            return List.of();
        }

        List<PolicyBean> policyChain = aggregateContractPolicies(contract);

        int idxFound = -1;
        for (int i = 0, policyChainSize = policyChain.size(); i < policyChainSize; i++) {
            PolicyBean policy = policyChain.get(i);
            if (policy.getId().equals(policyId)) {
                idxFound = i;
            }
        }
        if (idxFound == -1) {
            throw new IllegalArgumentException("Provided policy ID not found in contract " + policyId);
        }

        List<GatewayBean> gateways = tryAction(() -> storage.getGateways(gatewayIds));
        LOGGER.debug("Gateways for contract {0}: {1}", contractId, gateways);

        List<IPolicyProbeResponse> probeResponses = new ArrayList<>(gateways.size());
        for (GatewayBean gateway : gateways) {
            IGatewayLink link = gatewayLinkFactory.create(gateway);
            try {
                probeResponses.add(link.probe(apiOrg.getId(), avb.getApi().getId(), avb.getVersion(), idxFound, apiKey, rawPayload));
            } catch (GatewayAuthenticationException e) {
                throw new SystemErrorException(e);
            }
        }
        LOGGER.debug("Probe responses for contract {0}: {1}", contractId, probeResponses);
        return probeResponses;
    }
Check to see if the contract already exists, by getting a list of all the
client's contracts and comparing with the one being created.
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ContractService.java