Search in sources :

Example 1 with ApiEndpoint

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();
        }
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) HashMap(java.util.HashMap) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 2 with ApiEndpoint

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);
    }
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) URI(java.net.URI) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) GatewayEndpoint(io.apiman.gateway.engine.beans.GatewayEndpoint) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) RegistrationException(io.apiman.gateway.engine.beans.exceptions.RegistrationException)

Example 3 with ApiEndpoint

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());
}
Also used : ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint)

Example 4 with ApiEndpoint

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;
}
Also used : ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint)

Example 5 with ApiEndpoint

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;
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ApiVersionEndpointSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionEndpointSummaryBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink)

Aggregations

ApiEndpoint (io.apiman.gateway.engine.beans.ApiEndpoint)10 GatewayBean (io.apiman.manager.api.beans.gateways.GatewayBean)4 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)4 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)4 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)3 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)3 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)2 ApiEntryBean (io.apiman.manager.api.beans.summary.ApiEntryBean)2 ApiRegistryBean (io.apiman.manager.api.beans.summary.ApiRegistryBean)2 ApiVersionEndpointSummaryBean (io.apiman.manager.api.beans.summary.ApiVersionEndpointSummaryBean)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)2 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)2 HashMap (java.util.HashMap)2 GatewayEndpoint (io.apiman.gateway.engine.beans.GatewayEndpoint)1 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)1 RegistrationException (io.apiman.gateway.engine.beans.exceptions.RegistrationException)1 EndpointHelper (io.apiman.gateway.platforms.vertx3.helpers.EndpointHelper)1 NewClientVersionBean (io.apiman.manager.api.beans.clients.NewClientVersionBean)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1