Search in sources :

Example 1 with SystemStatus

use of io.apiman.gateway.engine.beans.SystemStatus in project apiman by apiman.

the class GatewayResourceImpl method test.

/**
 * @see IGatewayResource#test(io.apiman.manager.api.beans.gateways.NewGatewayBean)
 */
@Override
public GatewayTestResultBean test(NewGatewayBean gatewayToTest) throws NotAuthorizedException {
    securityContext.checkAdminPermissions();
    GatewayTestResultBean rval = new GatewayTestResultBean();
    try {
        GatewayBean testGateway = new GatewayBean();
        testGateway.setName(gatewayToTest.getName());
        testGateway.setType(gatewayToTest.getType());
        testGateway.setConfiguration(gatewayToTest.getConfiguration());
        IGatewayLink gatewayLink = gatewayLinkFactory.create(testGateway);
        SystemStatus status = gatewayLink.getStatus();
        String detail = MAPPER.writer().writeValueAsString(status);
        rval.setSuccess(true);
        rval.setDetail(detail);
    } catch (GatewayAuthenticationException e) {
        rval.setSuccess(false);
        // $NON-NLS-1$
        rval.setDetail(Messages.i18n.format("GatewayResourceImpl.AuthenticationFailed"));
    } catch (Exception e) {
        rval.setSuccess(false);
        rval.setDetail(e.getMessage());
    }
    return rval;
}
Also used : SystemStatus(io.apiman.gateway.engine.beans.SystemStatus) GatewayTestResultBean(io.apiman.manager.api.beans.summary.GatewayTestResultBean) NewGatewayBean(io.apiman.manager.api.beans.gateways.NewGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) UpdateGatewayBean(io.apiman.manager.api.beans.gateways.UpdateGatewayBean) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) GatewayAlreadyExistsException(io.apiman.manager.api.rest.exceptions.GatewayAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException)

Example 2 with SystemStatus

use of io.apiman.gateway.engine.beans.SystemStatus in project apiman by apiman.

the class SystemResourceImpl method getStatus.

@Override
public SystemStatus getStatus() {
    SystemStatus status = new SystemStatus();
    status.setUp(true);
    status.setVersion(engine.getVersion());
    return status;
}
Also used : SystemStatus(io.apiman.gateway.engine.beans.SystemStatus)

Example 3 with SystemStatus

use of io.apiman.gateway.engine.beans.SystemStatus in project apiman by apiman.

the class GatewayClient method getStatus.

/**
 * @see ISystemResource#getStatus()
 */
public SystemStatus getStatus() throws GatewayAuthenticationException {
    InputStream is = null;
    try {
        URI uri = new URI(this.endpoint + SYSTEM_STATUS);
        HttpGet get = new HttpGet(uri);
        HttpResponse response = httpClient.execute(get);
        int actualStatusCode = response.getStatusLine().getStatusCode();
        if (actualStatusCode == 401 || actualStatusCode == 403) {
            throw new GatewayAuthenticationException();
        } else if (actualStatusCode != 200) {
            // $NON-NLS-1$
            throw new RuntimeException("System status check failed: " + actualStatusCode);
        }
        is = response.getEntity().getContent();
        return mapper.reader(SystemStatus.class).readValue(is);
    } catch (GatewayAuthenticationException | RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : SystemStatus(io.apiman.gateway.engine.beans.SystemStatus) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) 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 4 with SystemStatus

use of io.apiman.gateway.engine.beans.SystemStatus in project apiman by apiman.

the class SystemResourceImpl method getStatus.

/**
 * @see ISystemResource#getStatus()
 */
@Override
public SystemStatus getStatus() {
    SystemStatus status = new SystemStatus();
    // $NON-NLS-1$
    status.setId("apiman-gateway-api");
    // $NON-NLS-1$
    status.setName("API Gateway REST API");
    // $NON-NLS-1$
    status.setDescription("The API Gateway REST API is used by the API Manager to publish APIs and register clients.  You can use it directly if you wish, but if you are utilizing the API Manager then it's probably best to avoid invoking this API directly.");
    status.setUp(true);
    status.setVersion(getEngine().getVersion());
    return status;
}
Also used : SystemStatus(io.apiman.gateway.engine.beans.SystemStatus)

Aggregations

SystemStatus (io.apiman.gateway.engine.beans.SystemStatus)4 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)2 ApiEndpoint (io.apiman.gateway.engine.beans.ApiEndpoint)1 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 GatewayBean (io.apiman.manager.api.beans.gateways.GatewayBean)1 NewGatewayBean (io.apiman.manager.api.beans.gateways.NewGatewayBean)1 UpdateGatewayBean (io.apiman.manager.api.beans.gateways.UpdateGatewayBean)1 GatewayTestResultBean (io.apiman.manager.api.beans.summary.GatewayTestResultBean)1 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 GatewayAlreadyExistsException (io.apiman.manager.api.rest.exceptions.GatewayAlreadyExistsException)1 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)1 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 HttpResponse (org.apache.http.HttpResponse)1