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));
}
}
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)));
}
}
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);
}
}
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));
}
}
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));
}
}
}
Aggregations