public void unregisterClient(String orgId, String clientId, String clientVersion) throws ActionException, NotAuthorizedException {
        ClientVersionBean versionBean;
        List<ContractSummaryBean> contractBeans;
        try {
            versionBean = clientAppService.getClientVersion(orgId, clientId, clientVersion);
        } catch (ClientVersionNotFoundException e) {
            throw ExceptionFactory.actionException(Messages.i18n.format("ClientNotFound")); //$NON-NLS-1$
        }
        try {
            contractBeans = query.getClientContracts(orgId, clientId, clientVersion)
                    .stream()
                    .peek(c -> {
                        if (c.getStatus() != ContractStatus.Created) {
                            LOGGER.debug("Will not try to delete contract {0} from gateway(s) as it is not in 'Created' state", c);
                        }
                    })
                    .filter(c -> c.getStatus() == ContractStatus.Created)
                    .collect(Collectors.toList());

        } catch (StorageException e) {
            throw ExceptionFactory.actionException(Messages.i18n.format("ClientNotFound"), e); //$NON-NLS-1$
        }

        // Validate that it's ok to perform this action - client must be either registered or awaiting approval (or there's nothing to unregister)
        if (versionBean.getStatus() != ClientStatus.Registered && versionBean.getStatus() != ClientStatus.AwaitingApproval) {
            throw ExceptionFactory.actionException(Messages.i18n.format("InvalidClientStatus")); //$NON-NLS-1$
        }

        Client client = new Client();
        client.setOrganizationId(versionBean.getClient().getOrganization().getId());
        client.setClientId(versionBean.getClient().getId());
        client.setVersion(versionBean.getVersion());

        // Next, unregister the client from *all* relevant gateways.  This is done by
        // looking up all referenced APIs and getting the gateway information for them.
        // Each of those gateways must be told about the client.
        try {
            Map<String, IGatewayLink> links = new HashMap<>();
            for (ContractSummaryBean contractBean : contractBeans) {
                ApiVersionBean svb = storage.getApiVersion(contractBean.getApiOrganizationId(), contractBean.getApiId(), contractBean.getApiVersion());
                Set<ApiGatewayBean> gateways = svb.getGateways();
                if (gateways == null) {
                    throw new PublishingException("No gateways specified for API: " + svb.getApi().getName()); //$NON-NLS-1$
                }
                for (ApiGatewayBean apiGatewayBean : gateways) {
                    if (!links.containsKey(apiGatewayBean.getGatewayId())) {
                        IGatewayLink gatewayLink = createGatewayLink(apiGatewayBean.getGatewayId());
                        links.put(apiGatewayBean.getGatewayId(), gatewayLink);
                    }
                }
            }
            for (IGatewayLink gatewayLink : links.values()) {
                gatewayLink.unregisterClient(client);
                gatewayLink.close();
            }
        } catch (Exception e) {
            throw ExceptionFactory.actionException(Messages.i18n.format("UnregisterError"), e); //$NON-NLS-1$
        }

        ClientStatus oldStatus = versionBean.getStatus();
        versionBean.setStatus(ClientStatus.Retired);
        versionBean.setRetiredOn(new Date());
        clientAppService.fireClientStatusChangeEvent(versionBean, oldStatus);

        try {
            storage.updateClientVersion(versionBean);
            storage.createAuditEntry(AuditUtils.clientUnregistered(versionBean, securityContext));
        } catch (Exception e) {
            throw ExceptionFactory.actionException(Messages.i18n.format("UnregisterError"), e); //$NON-NLS-1$
        }

        LOGGER.debug(String.format("Successfully registered Client %s on specified gateways: %s", //$NON-NLS-1$
             versionBean.getClient().getName(), versionBean.getClient()));
    }
De-registers an client that is currently registered with the gateway.
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ActionService.java