Search in sources :

Example 21 with Client

use of io.apiman.gateway.engine.beans.Client in project apiman by apiman.

the class SharedGlobalDataRegistry method unregisterClient.

@Override
public void unregisterClient(Client client, IAsyncResultHandler<Void> resultHandler) {
    String clientIndex = getClientIndex(client);
    objectMap.get(clientIndex, handleSuccessfulResult(resultHandler, oldClientRaw -> {
        Client oldClient = (Client) oldClientRaw;
        if (oldClient == null) {
            Exception ex = new ClientNotFoundException(Messages.i18n.format("InMemoryRegistry.ClientNotFound"));
            resultHandler.handle(AsyncResultImpl.create(ex));
        } else {
            Future<Object> future1 = Future.future();
            Future<Object> future2 = Future.future();
            objectMap.remove(clientIndex, future1.completer());
            objectMap.remove(oldClient.getApiKey(), future2.completer());
            CompositeFuture.all(future1, future2).setHandler(handleCompositeResult(resultHandler));
        }
    }));
}
Also used : ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) AsyncResultImpl(io.apiman.gateway.engine.async.AsyncResultImpl) LoggerFactory(io.vertx.core.logging.LoggerFactory) ArrayList(java.util.ArrayList) Client(io.apiman.gateway.engine.beans.Client) CompositeFuture(io.vertx.core.CompositeFuture) AsyncMap(io.vertx.core.shareddata.AsyncMap) IAsyncResultHandler(io.apiman.gateway.engine.async.IAsyncResultHandler) Map(java.util.Map) AsyncResult(io.vertx.core.AsyncResult) Logger(io.vertx.core.logging.Logger) Contract(io.apiman.gateway.engine.beans.Contract) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) Vertx(io.vertx.core.Vertx) Future(io.vertx.core.Future) Api(io.apiman.gateway.engine.beans.Api) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) IEngineConfig(io.apiman.gateway.engine.IEngineConfig) List(java.util.List) Messages(io.apiman.gateway.engine.i18n.Messages) IRegistry(io.apiman.gateway.engine.IRegistry) ApiContract(io.apiman.gateway.engine.beans.ApiContract) Optional(java.util.Optional) Handler(io.vertx.core.Handler) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) Client(io.apiman.gateway.engine.beans.Client) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)

Example 22 with Client

use of io.apiman.gateway.engine.beans.Client in project apiman by apiman.

the class RateLimitingPolicyTest method createTestContract.

/**
 * @return a test contract
 */
private ApiContract createTestContract() {
    Api api = new Api();
    api.setOrganizationId("ApiOrg");
    api.setApiId("Api");
    api.setVersion("1.0");
    Client app = new Client();
    app.setApiKey("12345");
    app.setOrganizationId("AppOrg");
    app.setClientId("App");
    app.setVersion("1.0");
    return new ApiContract(api, app, "Gold", null);
}
Also used : Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) ApiContract(io.apiman.gateway.engine.beans.ApiContract)

Example 23 with Client

use of io.apiman.gateway.engine.beans.Client in project apiman by apiman.

the class EBRegistryProxyHandler method listenProxyHandler.

@SuppressWarnings("nls")
default void listenProxyHandler(IAsyncResultHandler<Void> startupHandler) {
    log().info("Setting up a listener on: {0}", address());
    MessageConsumer<JsonObject> consumer = vertx().eventBus().consumer(address(), (Message<JsonObject> message) -> {
        String inboundUuid = message.body().getString("uuid");
        log().debug("[{0}] Handling command from inbound UUID: {1} {2}", uuid(), inboundUuid, message);
        if (shouldIgnore(inboundUuid))
            return;
        String type = message.body().getString("type");
        String action = message.body().getString("action");
        String body = message.body().getString("body");
        switch(type) {
            case "client":
                Client app = Json.decodeValue(body, Client.class);
                if (action.equals("register")) {
                    registerClient(app);
                } else if (action.equals("unregister")) {
                    unregisterClient(app);
                }
                break;
            case "api":
                Api api = Json.decodeValue(body, Api.class);
                if (action.equals("publish")) {
                    publishApi(api);
                } else if (action.equals("retire")) {
                    retireApi(api);
                }
                break;
            default:
                throw new IllegalStateException("Unknown type: " + type);
        }
    });
    consumer.completionHandler(complete -> {
        if (complete.succeeded()) {
            startupHandler.handle(AsyncResultImpl.create((Void) null));
        } else {
            startupHandler.handle(AsyncResultImpl.create(complete.cause()));
        }
    });
    consumer.exceptionHandler(ex -> {
        log().error("[{0}] An exception occurred: {1}", uuid(), ex);
        ex.printStackTrace();
    });
}
Also used : Message(io.vertx.core.eventbus.Message) JsonObject(io.vertx.core.json.JsonObject) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client)

Example 24 with Client

use of io.apiman.gateway.engine.beans.Client in project apiman by apiman.

the class CachingEsRegistry method getClient.

/**
 * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void getClient(String apiKey, IAsyncResultHandler<Client> handler) {
    try {
        Client client = getClient(apiKey);
        handler.handle(AsyncResultImpl.create(client));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e, Client.class));
    }
}
Also used : IOException(java.io.IOException) Client(io.apiman.gateway.engine.beans.Client)

Example 25 with Client

use of io.apiman.gateway.engine.beans.Client in project apiman by apiman.

the class EsRegistry method getClient.

/**
 * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void getClient(String apiKey, IAsyncResultHandler<Client> handler) {
    String id = apiKey;
    try {
        Client client = getClient(id);
        handler.handle(AsyncResultImpl.create(client));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e, Client.class));
    }
}
Also used : IOException(java.io.IOException) Client(io.apiman.gateway.engine.beans.Client)

Aggregations

Client (io.apiman.gateway.engine.beans.Client)33 Api (io.apiman.gateway.engine.beans.Api)17 Contract (io.apiman.gateway.engine.beans.Contract)14 ApiContract (io.apiman.gateway.engine.beans.ApiContract)10 ClientNotFoundException (io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException)9 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)9 ApiRetiredException (io.apiman.gateway.engine.beans.exceptions.ApiRetiredException)8 NoContractFoundException (io.apiman.gateway.engine.beans.exceptions.NoContractFoundException)8 ApiNotFoundException (io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)7 HashMap (java.util.HashMap)7 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)6 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)6 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)6 StorageException (io.apiman.manager.api.core.exceptions.StorageException)6 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)6 HashSet (java.util.HashSet)6 Policy (io.apiman.gateway.engine.beans.Policy)5 ContractSummaryBean (io.apiman.manager.api.beans.summary.ContractSummaryBean)5 ActionException (io.apiman.manager.api.rest.exceptions.ActionException)5 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)5