Search in sources :

Example 16 with Api

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

the class ApiResourceImpl method retire.

@Override
public void retire(String organizationId, String apiId, String version) throws RegistrationException, NotAuthorizedException {
    Api api = new Api();
    api.setOrganizationId(organizationId);
    api.setApiId(apiId);
    api.setVersion(version);
    registry.retireApi(api, (IAsyncResultHandler<Void>) result -> {
        if (result.isError()) {
            throwError(result.getError());
        }
    });
}
Also used : EndpointHelper(io.apiman.gateway.platforms.vertx3.helpers.EndpointHelper) IPolicy(io.apiman.gateway.engine.policy.IPolicy) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) VertxEngineConfig(io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig) NotAuthorizedException(io.apiman.gateway.api.rest.exceptions.NotAuthorizedException) Client(io.apiman.gateway.engine.beans.Client) IAsyncResultHandler(io.apiman.gateway.engine.async.IAsyncResultHandler) IPolicyProbe(io.apiman.gateway.engine.policy.IPolicyProbe) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) Status(javax.ws.rs.core.Response.Status) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) ProbeContext(io.apiman.gateway.engine.policy.ProbeContext) IPolicyProbeResponse(io.apiman.gateway.engine.beans.IPolicyProbeResponse) Policy(io.apiman.gateway.engine.beans.Policy) RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException) IApiResource(io.apiman.gateway.api.rest.IApiResource) AsyncResponse(javax.ws.rs.container.AsyncResponse) PolicyContextImpl(io.apiman.gateway.engine.policy.PolicyContextImpl) ProbeRegistry(io.apiman.gateway.engine.policies.probe.ProbeRegistry) Suspended(javax.ws.rs.container.Suspended) Api(io.apiman.gateway.engine.beans.Api) IApimanLogger(io.apiman.common.logging.IApimanLogger) IEngine(io.apiman.gateway.engine.IEngine) Response(javax.ws.rs.core.Response) IRegistry(io.apiman.gateway.engine.IRegistry) ApiContract(io.apiman.gateway.engine.beans.ApiContract) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) Api(io.apiman.gateway.engine.beans.Api)

Example 17 with Api

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

the class SharedGlobalDataRegistry method getContract.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey, IAsyncResultHandler<ApiContract> handler) {
    String apiIndex = getApiIndex(apiOrganizationId, apiId, apiVersion);
    Future apiFuture = Future.future();
    Future clientFuture = Future.future();
    objectMap.get(apiIndex, apiFuture.completer());
    objectMap.get(apiKey, clientFuture.completer());
    CompositeFuture.all(apiFuture, clientFuture).setHandler(compositeResult -> {
        if (compositeResult.succeeded()) {
            Api api = (Api) apiFuture.result();
            Client client = (Client) clientFuture.result();
            if (api == null) {
                Exception error = new ClientNotFoundException(Messages.i18n.format("InMemoryRegistry.NoClientForAPIKey", apiKey));
                handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            } else if (client == null) {
                Exception error = new ApiRetiredException(Messages.i18n.format("InMemoryRegistry.ApiWasRetired", apiId, apiOrganizationId));
                handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            } else {
                Optional<Contract> matchedOpt = client.getContracts().stream().filter(contract -> contract.matches(apiOrganizationId, apiId, apiVersion)).findFirst();
                if (matchedOpt.isPresent()) {
                    Contract contract = matchedOpt.get();
                    ApiContract apiContract = new ApiContract(api, client, contract.getPlan(), contract.getPolicies());
                    handler.handle(AsyncResultImpl.create(apiContract));
                } else {
                    Exception error = new NoContractFoundException(// $NON-NLS-1$
                    Messages.i18n.format(// $NON-NLS-1$
                    "InMemoryRegistry.NoContractFound", client.getClientId(), api.getApiId()));
                    handler.handle(AsyncResultImpl.create(error, ApiContract.class));
                }
            }
        } else {
            handler.handle(AsyncResultImpl.create(compositeResult.cause()));
        }
    });
}
Also used : NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) Optional(java.util.Optional) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) Contract(io.apiman.gateway.engine.beans.Contract) ApiContract(io.apiman.gateway.engine.beans.ApiContract) 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) ApiContract(io.apiman.gateway.engine.beans.ApiContract)

Example 18 with Api

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

the class CachingJdbcRegistry method getContract.

/**
 * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey, IAsyncResultHandler<ApiContract> handler) {
    Client client = null;
    Api api = null;
    try {
        synchronized (mutex) {
            client = getClient(apiKey);
            api = getApi(apiOrganizationId, apiId, apiVersion);
        }
        if (client == null) {
            // $NON-NLS-1$
            Exception error = new NoContractFoundException(Messages.i18n.format("JdbcRegistry.NoClientForAPIKey", apiKey));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }
        if (api == null) {
            throw new ApiRetiredException(// $NON-NLS-1$
            Messages.i18n.format(// $NON-NLS-1$
            "JdbcRegistry.ApiWasRetired", apiId, apiOrganizationId));
        }
        Contract matchedContract = null;
        for (Contract contract : client.getContracts()) {
            if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
                matchedContract = contract;
                break;
            }
        }
        if (matchedContract == null) {
            throw new NoContractFoundException(// $NON-NLS-1$
            Messages.i18n.format(// $NON-NLS-1$
            "JdbcRegistry.NoContractFound", client.getClientId(), api.getApiId()));
        }
        ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
        handler.handle(AsyncResultImpl.create(contract));
    } catch (Exception e) {
        handler.handle(AsyncResultImpl.create(e, ApiContract.class));
    }
}
Also used : NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) Contract(io.apiman.gateway.engine.beans.Contract) ApiContract(io.apiman.gateway.engine.beans.ApiContract) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) SQLException(java.sql.SQLException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) ApiContract(io.apiman.gateway.engine.beans.ApiContract)

Example 19 with Api

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

the class CachingJdbcRegistry method getApi.

/**
 * Gets the api either from the cache or from ES.
 * @param orgId
 * @param apiId
 * @param version
 */
protected Api getApi(String orgId, String apiId, String version) throws SQLException {
    String apiIdx = getApiId(orgId, apiId, version);
    Api api;
    synchronized (mutex) {
        api = apiCache.get(apiIdx);
    }
    if (api == null) {
        api = super.getApiInternal(orgId, apiId, version);
        synchronized (mutex) {
            if (api != null) {
                apiCache.put(apiIdx, api);
            }
        }
    }
    return api;
}
Also used : Api(io.apiman.gateway.engine.beans.Api)

Example 20 with Api

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

the class JdbcRegistry method getContract.

/**
 * @see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey, IAsyncResultHandler<ApiContract> handler) {
    try {
        Client client = getClientInternal(apiKey);
        Api api = getApiInternal(apiOrganizationId, apiId, apiVersion);
        if (client == null) {
            // $NON-NLS-1$
            Exception error = new ClientNotFoundException(Messages.i18n.format("JdbcRegistry.NoClientForAPIKey", apiKey));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }
        if (api == null) {
            Exception error = new ApiRetiredException(// $NON-NLS-1$
            Messages.i18n.format(// $NON-NLS-1$
            "JdbcRegistry.ApiWasRetired", apiId, apiOrganizationId));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }
        Contract matchedContract = null;
        for (Contract contract : client.getContracts()) {
            if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
                matchedContract = contract;
                break;
            }
        }
        if (matchedContract == null) {
            Exception error = new NoContractFoundException(// $NON-NLS-1$
            Messages.i18n.format(// $NON-NLS-1$
            "JdbcRegistry.NoContractFound", client.getClientId(), api.getApiId()));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }
        ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
        handler.handle(AsyncResultImpl.create(contract));
    } catch (Exception e) {
        handler.handle(AsyncResultImpl.create(e, ApiContract.class));
    }
}
Also used : NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) Contract(io.apiman.gateway.engine.beans.Contract) ApiContract(io.apiman.gateway.engine.beans.ApiContract) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) SQLException(java.sql.SQLException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) ApiContract(io.apiman.gateway.engine.beans.ApiContract)

Aggregations

Api (io.apiman.gateway.engine.beans.Api)41 Client (io.apiman.gateway.engine.beans.Client)16 ApiContract (io.apiman.gateway.engine.beans.ApiContract)11 Contract (io.apiman.gateway.engine.beans.Contract)10 Policy (io.apiman.gateway.engine.beans.Policy)10 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)10 ApiNotFoundException (io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)8 ApiRetiredException (io.apiman.gateway.engine.beans.exceptions.ApiRetiredException)8 NoContractFoundException (io.apiman.gateway.engine.beans.exceptions.NoContractFoundException)8 ClientNotFoundException (io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException)7 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)7 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)7 StorageException (io.apiman.manager.api.core.exceptions.StorageException)7 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)7 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 RegistrationException (io.apiman.gateway.engine.beans.exceptions.RegistrationException)6 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)6 ActionException (io.apiman.manager.api.rest.exceptions.ActionException)6 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)6