@Override
    public void registerClient(final Client client, final IAsyncResultHandler<Void> handler) {
        try {
            // Validate the client and populate the api map with apis found during validation.
            validateClient(client);

            String id = getClientId(client);
            IndexRequest indexRequest = new IndexRequest(getIndexPrefixWithJoiner() + EsConstants.INDEX_CLIENTS)
                    .source(JSON_MAPPER.writeValueAsBytes(client), XContentType.JSON)
                    .id(id)
                    .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

            IndexResponse response = getClient().index(indexRequest, RequestOptions.DEFAULT);

            if(!response.status().equals(RestStatus.CREATED) && !response.status().equals(RestStatus.OK)) {
                throw new IOException("Response status was " + response.status() + " instead of " + RestStatus.CREATED + " or " + RestStatus.OK);
            } else {
                handler.handle(AsyncResultImpl.create((Void) null));
            }
        } catch (IOException e) {
            handler.handle(AsyncResultImpl.create(
                    new RegistrationException(Messages.i18n.format("EsRegistry.ErrorRegisteringClient"), e),  //$NON-NLS-1$
                    Void.class));
        } catch (RuntimeException re) {
            handler.handle(AsyncResultImpl.create(re, Void.class));
        }
    }
@see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsRegistry.java