Search in sources :

Example 1 with NewGatewayBean

use of io.apiman.manager.api.beans.gateways.NewGatewayBean 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 NewGatewayBean

use of io.apiman.manager.api.beans.gateways.NewGatewayBean in project apiman by apiman.

the class GatewayResourceImpl method create.

/**
 * @see IGatewayResource#create(io.apiman.manager.api.beans.gateways.NewGatewayBean)
 */
@Override
public GatewayBean create(NewGatewayBean gatewayToInsert) throws GatewayAlreadyExistsException {
    securityContext.checkAdminPermissions();
    Date now = new Date();
    GatewayBean gateway = new GatewayBean();
    gateway.setId(BeanUtils.idFromName(gatewayToInsert.getName()));
    gateway.setName(gatewayToInsert.getName());
    gateway.setDescription(gatewayToInsert.getDescription());
    gateway.setType(gatewayToInsert.getType());
    gateway.setConfiguration(gatewayToInsert.getConfiguration());
    gateway.setCreatedBy(securityContext.getCurrentUser());
    gateway.setCreatedOn(now);
    gateway.setModifiedBy(securityContext.getCurrentUser());
    gateway.setModifiedOn(now);
    try {
        if (storage.getGateway(gateway.getId()) != null) {
            throw ExceptionFactory.gatewayAlreadyExistsException(gateway.getName());
        }
        // Store/persist the new gateway
        encryptPasswords(gateway);
        storage.createGateway(gateway);
    } catch (AbstractRestException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemErrorException(e);
    }
    decryptPasswords(gateway);
    // $NON-NLS-1$
    LOGGER.debug(String.format("Successfully created new gateway %s: %s", gateway.getName(), gateway));
    return gateway;
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewGatewayBean(io.apiman.manager.api.beans.gateways.NewGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) UpdateGatewayBean(io.apiman.manager.api.beans.gateways.UpdateGatewayBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) Date(java.util.Date) 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)

Aggregations

GatewayBean (io.apiman.manager.api.beans.gateways.GatewayBean)2 NewGatewayBean (io.apiman.manager.api.beans.gateways.NewGatewayBean)2 UpdateGatewayBean (io.apiman.manager.api.beans.gateways.UpdateGatewayBean)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)2 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)2 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)2 GatewayAlreadyExistsException (io.apiman.manager.api.rest.exceptions.GatewayAlreadyExistsException)2 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)2 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)2 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)2 SystemStatus (io.apiman.gateway.engine.beans.SystemStatus)1 GatewayTestResultBean (io.apiman.manager.api.beans.summary.GatewayTestResultBean)1 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)1 Date (java.util.Date)1