use of io.apiman.gateway.engine.beans.ApiContract in project apiman by apiman.
the class CachingEsRegistry method getContract.
/**
* @see io.apiman.gateway.engine.jdbc.EsRegistry#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 ClientNotFoundException(Messages.i18n.format("EsRegistry.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$
"EsRegistry.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$
"EsRegistry.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));
}
}
use of io.apiman.gateway.engine.beans.ApiContract in project apiman by apiman.
the class EsRegistry 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 = getClient(apiKey);
Api api = getApi(getApiId(apiOrganizationId, apiId, apiVersion));
if (client == null) {
// $NON-NLS-1$
Exception error = new ClientNotFoundException(Messages.i18n.format("EsRegistry.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$
"EsRegistry.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$
"EsRegistry.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));
}
}
use of io.apiman.gateway.engine.beans.ApiContract 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()));
}
});
}
use of io.apiman.gateway.engine.beans.ApiContract 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));
}
}
use of io.apiman.gateway.engine.beans.ApiContract 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));
}
}
Aggregations