Search in sources :

Example 1 with ApiNotFoundException

use of io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException in project apiman by apiman.

the class EsRegistry method unregisterClient.

/**
 * @see io.apiman.gateway.engine.IRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void unregisterClient(final Client client, final IAsyncResultHandler<Void> handler) {
    try {
        final Client lclient = lookupClient(client.getOrganizationId(), client.getClientId(), client.getVersion());
        final String id = getClientId(lclient);
        DeleteRequest deleteRequest = new DeleteRequest(getIndexPrefixWithJoiner() + EsConstants.INDEX_CLIENTS).id(id).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
        DeleteResponse response = getClient().delete(deleteRequest, RequestOptions.DEFAULT);
        if (response.status().equals(RestStatus.OK)) {
            handler.handle(AsyncResultImpl.create((Void) null));
        } else {
            // $NON-NLS-1$
            handler.handle(AsyncResultImpl.create(new ApiNotFoundException(Messages.i18n.format("EsRegistry.ClientNotFound"))));
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        handler.handle(AsyncResultImpl.create(new PublishingException(Messages.i18n.format("EsRegistry.ErrorUnregisteringClient"), e), Void.class));
    } catch (RuntimeException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) IOException(java.io.IOException) Client(io.apiman.gateway.engine.beans.Client) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 2 with ApiNotFoundException

use of io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException in project apiman by apiman.

the class EsRegistry method retireApi.

/**
 * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void retireApi(Api api, final IAsyncResultHandler<Void> handler) {
    final String id = getApiId(api);
    try {
        DeleteRequest deleteRequest = new DeleteRequest(getIndexPrefixWithJoiner() + EsConstants.INDEX_APIS).id(id).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
        DeleteResponse response = getClient().delete(deleteRequest, RequestOptions.DEFAULT);
        if (response.status().equals(RestStatus.OK)) {
            handler.handle(AsyncResultImpl.create((Void) null));
        } else {
            // $NON-NLS-1$
            handler.handle(AsyncResultImpl.create(new ApiNotFoundException(Messages.i18n.format("EsRegistry.ApiNotFound"))));
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        handler.handle(AsyncResultImpl.create(new PublishingException(Messages.i18n.format("EsRegistry.ErrorRetiringApi"), e)));
    }
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) IOException(java.io.IOException) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 3 with ApiNotFoundException

use of io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException in project apiman by apiman.

the class JdbcRegistry method validateContract.

/**
 * Ensures that the api referenced by the Contract actually exists (is published).
 * @param contract
 * @param connection
 * @throws RegistrationException
 */
private void validateContract(final Contract contract, Connection connection) throws RegistrationException {
    QueryRunner run = new QueryRunner();
    try {
        Api api = // $NON-NLS-1$
        run.query(// $NON-NLS-1$
        connection, // $NON-NLS-1$
        "SELECT bean FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", Handlers.API_HANDLER, contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
        if (api == null) {
            String apiId = contract.getApiId();
            String orgId = contract.getApiOrgId();
            // $NON-NLS-1$
            throw new ApiNotFoundException(Messages.i18n.format("JdbcRegistry.ApiNotFoundInOrg", apiId, orgId));
        }
    } catch (SQLException e) {
        // $NON-NLS-1$
        throw new RegistrationException(Messages.i18n.format("JdbcRegistry.ErrorValidatingApp"), e);
    }
}
Also used : RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException) SQLException(java.sql.SQLException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) Api(io.apiman.gateway.engine.beans.Api) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 4 with ApiNotFoundException

use of io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException in project apiman by apiman.

the class InMemoryRegistry method retireApi.

/**
 * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void retireApi(Api api, IAsyncResultHandler<Void> handler) {
    String apiIdx = getApiIndex(api);
    Exception error = null;
    synchronized (mutex) {
        Api removedApi = (Api) getMap().remove(apiIdx);
        if (removedApi == null) {
            // $NON-NLS-1$
            error = new ApiNotFoundException(Messages.i18n.format("InMemoryRegistry.ApiNotFound"));
        }
    }
    if (error == null) {
        handler.handle(AsyncResultImpl.create((Void) null));
    } else {
        handler.handle(AsyncResultImpl.create(error, Void.class));
    }
}
Also used : ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) Api(io.apiman.gateway.engine.beans.Api) RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)

Example 5 with ApiNotFoundException

use of io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException in project apiman by apiman.

the class InMemoryRegistry method registerClient.

/**
 * @see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void registerClient(Client client, IAsyncResultHandler<Void> handler) {
    Exception error = null;
    synchronized (mutex) {
        // Validate the client first - we need to be able to resolve all the contracts.
        for (Contract contract : client.getContracts()) {
            String apiIdx = getApiIndex(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
            if (!getMap().containsKey(apiIdx)) {
                error = new ApiNotFoundException(// $NON-NLS-1$
                Messages.i18n.format(// $NON-NLS-1$
                "InMemoryRegistry.ApiNotFoundInOrg", contract.getApiId(), contract.getApiOrgId()));
                break;
            }
        }
        if (error == null) {
            // Unregister the client (if it exists)
            unregisterClientInternal(client, true);
            // Now, register the client.
            String clientIdx = getClientIndex(client);
            getMap().put(clientIdx, client);
            getMap().put(client.getApiKey(), client);
            handler.handle(AsyncResultImpl.create((Void) null));
        } else {
            handler.handle(AsyncResultImpl.create(error, Void.class));
        }
    }
}
Also used : ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException) Contract(io.apiman.gateway.engine.beans.Contract) ApiContract(io.apiman.gateway.engine.beans.ApiContract) RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException) ClientNotFoundException(io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException) ApiRetiredException(io.apiman.gateway.engine.beans.exceptions.ApiRetiredException) NoContractFoundException(io.apiman.gateway.engine.beans.exceptions.NoContractFoundException) ApiNotFoundException(io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)

Aggregations

ApiNotFoundException (io.apiman.gateway.engine.beans.exceptions.ApiNotFoundException)8 RegistrationException (io.apiman.gateway.engine.beans.exceptions.RegistrationException)4 Api (io.apiman.gateway.engine.beans.Api)3 ApiContract (io.apiman.gateway.engine.beans.ApiContract)3 ApiRetiredException (io.apiman.gateway.engine.beans.exceptions.ApiRetiredException)3 ClientNotFoundException (io.apiman.gateway.engine.beans.exceptions.ClientNotFoundException)3 NoContractFoundException (io.apiman.gateway.engine.beans.exceptions.NoContractFoundException)3 IOException (java.io.IOException)3 IAsyncResultHandler (io.apiman.gateway.engine.async.IAsyncResultHandler)2 Client (io.apiman.gateway.engine.beans.Client)2 Contract (io.apiman.gateway.engine.beans.Contract)2 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)2 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)2 IApiConnector (io.apiman.gateway.engine.IApiConnector)1 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)1 IEngineConfig (io.apiman.gateway.engine.IEngineConfig)1 IEngineResult (io.apiman.gateway.engine.IEngineResult)1