Search in sources :

Example 1 with GraviteeMapper

use of io.gravitee.definition.jackson.datatype.GraviteeMapper in project gravitee-management-rest-api by gravitee-io.

the class ServiceConfiguration method objectMapper.

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper objectMapper = new GraviteeMapper();
    PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
    objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
    return objectMapper;
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) ApiPermissionFilter(io.gravitee.management.service.jackson.filter.ApiPermissionFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Example 2 with GraviteeMapper

use of io.gravitee.definition.jackson.datatype.GraviteeMapper in project gravitee-gateway by gravitee-io.

the class ApiDeployerStatement method loadApi.

private Api loadApi(String apiDescriptorPath) throws Exception {
    URL jsonFile = ApiDeployerStatement.class.getResource(apiDescriptorPath);
    Api api = new GraviteeMapper().readValue(jsonFile, Api.class);
    if (ApiLoaderInterceptor.class.isAssignableFrom(target.getClass())) {
        ApiLoaderInterceptor loader = (ApiLoaderInterceptor) target;
        loader.before(api);
    }
    boolean enhanceHttpPort = target.getClass().getAnnotation(ApiDescriptor.class).enhanceHttpPort();
    if (enhanceHttpPort) {
        List<Endpoint> endpoints = new ArrayList<>(api.getProxy().getEndpoints());
        List<Integer> bindPorts = SocketUtils.getBindPorts();
        for (int i = 0; i < bindPorts.size(); i++) {
            int port = SocketUtils.getBindPorts().get(i);
            if (i < endpoints.size()) {
                Endpoint edpt = endpoints.get(i);
                URL target = new URL(edpt.getTarget());
                URL newTarget = new URL(target.getProtocol(), target.getHost(), port, target.getFile());
                edpt.setTarget(newTarget.toString());
                edpt.setName(UUID.random().toString());
            } else {
                // Use the first defined endpoint as reference
                HttpEndpoint first = (HttpEndpoint) endpoints.get(0);
                URL target = new URL(first.getTarget());
                URL newTarget = new URL(target.getProtocol(), target.getHost(), port, target.getFile());
                HttpEndpoint edpt = new HttpEndpoint(UUID.random().toString(), newTarget.toString());
                edpt.setHttpClientOptions(first.getHttpClientOptions());
                api.getProxy().getEndpoints().add(edpt);
            }
        }
    }
    if (ApiLoaderInterceptor.class.isAssignableFrom(target.getClass())) {
        ApiLoaderInterceptor loader = (ApiLoaderInterceptor) target;
        loader.after(api);
    }
    return api;
}
Also used : ApiLoaderInterceptor(io.gravitee.gateway.standalone.ApiLoaderInterceptor) ApiDescriptor(io.gravitee.gateway.standalone.junit.annotation.ApiDescriptor) ArrayList(java.util.ArrayList) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) URL(java.net.URL) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) Api(io.gravitee.gateway.handlers.api.definition.Api)

Example 3 with GraviteeMapper

use of io.gravitee.definition.jackson.datatype.GraviteeMapper in project gravitee-gateway by gravitee-io.

the class LocalApiDefinitionRegistry method loadDefinition.

private Api loadDefinition(File apiDefinitionFile) throws IOException {
    Api api = new GraviteeMapper().readValue(apiDefinitionFile, Api.class);
    api.setId(IdGenerator.generate(api.getName()));
    return api;
}
Also used : GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) Api(io.gravitee.gateway.handlers.api.definition.Api)

Example 4 with GraviteeMapper

use of io.gravitee.definition.jackson.datatype.GraviteeMapper in project gravitee-gateway by gravitee-io.

the class StandaloneConfiguration method objectMapper.

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new GraviteeMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return mapper;
}
Also used : GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Aggregations

GraviteeMapper (io.gravitee.definition.jackson.datatype.GraviteeMapper)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Api (io.gravitee.gateway.handlers.api.definition.Api)2 Bean (org.springframework.context.annotation.Bean)2 PropertyFilter (com.fasterxml.jackson.databind.ser.PropertyFilter)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 Endpoint (io.gravitee.definition.model.Endpoint)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1 ApiLoaderInterceptor (io.gravitee.gateway.standalone.ApiLoaderInterceptor)1 ApiDescriptor (io.gravitee.gateway.standalone.junit.annotation.ApiDescriptor)1 ApiPermissionFilter (io.gravitee.management.service.jackson.filter.ApiPermissionFilter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1