use of io.apiman.gateway.engine.beans.ApiEndpoint in project apiman by apiman.
the class OrganizationResourceImpl method getApiRegistry.
/**
* Gets the API registry.
* @param organizationId
* @param clientId
* @param version
* @throws ClientVersionNotFoundException
*/
private ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws ClientVersionNotFoundException {
// Try to get the client first - will throw a ClientVersionNotFoundException if not found.
ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
Map<String, GatewayBean> gateways = new HashMap<>();
boolean txStarted = false;
try {
ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
apiRegistry.setApiKey(clientVersion.getApikey());
List<ApiEntryBean> apis = apiRegistry.getApis();
storage.beginTx();
txStarted = true;
for (ApiEntryBean api : apis) {
String gatewayId = api.getGatewayId();
// Don't return the gateway id.
api.setGatewayId(null);
GatewayBean gateway = gateways.get(gatewayId);
if (gateway == null) {
gateway = storage.getGateway(gatewayId);
gateways.put(gatewayId, gateway);
}
IGatewayLink link = gatewayLinks.get(gatewayId);
if (link == null) {
link = gatewayLinkFactory.create(gateway);
gatewayLinks.put(gatewayId, link);
}
ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
String apiEndpoint = se.getEndpoint();
api.setHttpEndpoint(apiEndpoint);
}
return apiRegistry;
} catch (StorageException | GatewayAuthenticationException e) {
throw new SystemErrorException(e);
} finally {
if (txStarted) {
storage.rollbackTx();
}
for (IGatewayLink link : gatewayLinks.values()) {
link.close();
}
}
}
use of io.apiman.gateway.engine.beans.ApiEndpoint in project apiman by apiman.
the class GatewayClient method getApiEndpoint.
/**
* @see IApiResource#getApiEndpoint(java.lang.String, java.lang.String, java.lang.String)
*/
public ApiEndpoint getApiEndpoint(String organizationId, String apiId, String version) throws GatewayAuthenticationException {
InputStream is = null;
try {
@SuppressWarnings("nls") URI uri = new URI(this.endpoint + APIs + "/" + organizationId + "/" + apiId + "/" + version + "/endpoint");
HttpGet get = new HttpGet(uri);
HttpResponse response = httpClient.execute(get);
int actualStatusCode = response.getStatusLine().getStatusCode();
if (actualStatusCode == 401 || actualStatusCode == 403) {
throw new GatewayAuthenticationException();
}
if (actualStatusCode != 200) {
// $NON-NLS-1$
throw new RuntimeException("Failed to get the API endpoint: " + actualStatusCode);
}
is = response.getEntity().getContent();
return mapper.reader(ApiEndpoint.class).readValue(is);
} catch (GatewayAuthenticationException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(is);
}
}
use of io.apiman.gateway.engine.beans.ApiEndpoint in project apiman by apiman.
the class ApiResourceImpl method getApiEndpoint.
@Override
public void getApiEndpoint(String organizationId, String apiId, String version, AsyncResponse response) throws NotAuthorizedException {
ApiEndpoint apiEndpoint = getApiEndpoint(organizationId, apiId, version);
response.resume(Response.ok(apiEndpoint).build());
}
use of io.apiman.gateway.engine.beans.ApiEndpoint in project apiman by apiman.
the class GatewayMicroServicePlatform method getApiEndpoint.
/**
* @see io.apiman.gateway.api.rest.impl.IPlatform#getApiEndpoint(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public ApiEndpoint getApiEndpoint(String organizationId, String apiId, String version) {
StringBuilder builder = getGatewayEndpoint();
builder.append(organizationId);
// $NON-NLS-1$
builder.append("/");
builder.append(apiId);
// $NON-NLS-1$
builder.append("/");
builder.append(version);
ApiEndpoint rval = new ApiEndpoint();
rval.setEndpoint(builder.toString());
return rval;
}
use of io.apiman.gateway.engine.beans.ApiEndpoint in project apiman by apiman.
the class ApiService method getApiVersionEndpointInfoFromStorage.
private ApiVersionEndpointSummaryBean getApiVersionEndpointInfoFromStorage(ApiVersionBean apiVersion, String organizationId, String apiId, String version) throws GatewayNotFoundException, GatewayAuthenticationException, StorageException {
Set<ApiGatewayBean> gateways = apiVersion.getGateways();
if (gateways.isEmpty()) {
// $NON-NLS-1$
throw new SystemErrorException("No Gateways for published API!");
}
GatewayBean gateway = storage.getGateway(gateways.iterator().next().getGatewayId());
if (gateway == null) {
throw new GatewayNotFoundException();
} else {
// $NON-NLS-1$
LOGGER.debug(String.format("Got endpoint summary: %s", gateway));
}
IGatewayLink link = gatewayLinkFactory.create(gateway);
ApiEndpoint endpoint = link.getApiEndpoint(organizationId, apiId, version);
ApiVersionEndpointSummaryBean rval = new ApiVersionEndpointSummaryBean();
rval.setManagedEndpoint(endpoint.getEndpoint());
return rval;
}
Aggregations