use of io.apiman.gateway.engine.beans.exceptions.RegistrationException in project apiman by apiman.
the class ClientResourceImpl method register.
/**
* @see IClientResource#register(io.apiman.gateway.engine.beans.Client)
*/
@Override
public void register(Client client) throws RegistrationException, NotAuthorizedException {
if (client.getApiKey() == null) {
// $NON-NLS-1$
throw new RegistrationException("Cannot Register Client: Missing API Key");
}
final Set<Throwable> errorHolder = new HashSet<>();
final CountDownLatch latch = new CountDownLatch(1);
// Register client; latch until result returned and evaluated
getEngine().getRegistry().registerClient(client, latchedResultHandler(latch, errorHolder));
awaitOnLatch(latch, errorHolder);
}
use of io.apiman.gateway.engine.beans.exceptions.RegistrationException in project apiman by apiman.
the class GatewayClient method register.
/**
* @see IClientResource#register(io.apiman.gateway.engine.beans.Client)
*/
public void register(Client client) throws RegistrationException, GatewayAuthenticationException {
try {
URI uri = new URI(this.endpoint + CLIENTS);
HttpPut put = new HttpPut(uri);
// $NON-NLS-1$ //$NON-NLS-2$
put.setHeader("Content-Type", "application/json; charset=utf-8");
String jsonPayload = mapper.writer().writeValueAsString(client);
HttpEntity entity = new StringEntity(jsonPayload);
put.setEntity(entity);
HttpResponse response = httpClient.execute(put);
int actualStatusCode = response.getStatusLine().getStatusCode();
if (actualStatusCode == 401 || actualStatusCode == 403) {
throw new GatewayAuthenticationException();
}
if (actualStatusCode == 500) {
// $NON-NLS-1$
Header[] headers = response.getHeaders("X-API-Gateway-Error");
if (headers != null && headers.length > 0) {
throw readRegistrationException(response);
}
}
if (actualStatusCode >= 300) {
// $NON-NLS-1$
throw new RuntimeException(Messages.i18n.format("GatewayClient.ClientRegistrationFailed", actualStatusCode));
}
} catch (GatewayAuthenticationException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.apiman.gateway.engine.beans.exceptions.RegistrationException in project apiman by apiman.
the class GatewayClient method retire.
/**
* @see IApiResource#retire(java.lang.String, java.lang.String, java.lang.String)
*/
public void retire(String organizationId, String apiId, String version) throws RegistrationException, GatewayAuthenticationException {
try {
@SuppressWarnings("nls") URI uri = new URI(this.endpoint + APIs + "/" + organizationId + "/" + apiId + "/" + version);
HttpDelete put = new HttpDelete(uri);
HttpResponse response = httpClient.execute(put);
int actualStatusCode = response.getStatusLine().getStatusCode();
if (actualStatusCode == 401 || actualStatusCode == 403) {
throw new GatewayAuthenticationException();
}
if (actualStatusCode == 500) {
// $NON-NLS-1$
Header[] headers = response.getHeaders("X-API-Gateway-Error");
if (headers != null && headers.length > 0) {
PublishingException pe = readPublishingException(response);
throw pe;
}
}
if (actualStatusCode >= 300) {
// $NON-NLS-1$
throw new Exception(Messages.i18n.format("GatewayClient.ApiRetiringFailed", actualStatusCode));
}
} catch (PublishingException | GatewayAuthenticationException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.apiman.gateway.engine.beans.exceptions.RegistrationException 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());
}
});
}
use of io.apiman.gateway.engine.beans.exceptions.RegistrationException 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);
}
}
Aggregations