Search in sources :

Example 16 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class CorsTest method before.

@Override
public void before(Api api) {
    super.before(api);
    try {
        Endpoint edpt = api.getProxy().getEndpoints().iterator().next();
        URL target = new URL(edpt.getTarget());
        URL newTarget = new URL(target.getProtocol(), target.getHost(), wireMockRule.port(), target.getFile());
        edpt.setTarget(newTarget.toString());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) URL(java.net.URL)

Example 17 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointDiscoveryConsulVerticle method handleRegisterService.

private void handleRegisterService(Api api, Service service) {
    Endpoint createdEndpoint = createEndpoint(service);
    Set<Endpoint> managedEndpoints = api.getProxy().getEndpoints();
    // Get previous endpoint reference
    Endpoint preEndpoint = managedEndpoints.stream().filter(createdEndpoint::equals).findAny().orElse(null);
    // Endpoint does not exist (according to its name)
    if (preEndpoint == null) {
        LOGGER.info("Register a new endpoint from Consul.io: id[{}] name[{}]", service.getId(), service.getName());
        managedEndpoints.add(createdEndpoint);
    } else if (preEndpoint instanceof DiscoveredEndpoint) {
        // Update it only if target has been changed
        DiscoveredEndpoint dynamicEndpoint = (DiscoveredEndpoint) preEndpoint;
        if (!createdEndpoint.getTarget().equals(dynamicEndpoint.getTarget())) {
            LOGGER.info("Update an existing endpoint from Consul.io: id[{}] name[{}] target[{}]", service.getId(), service.getName(), createdEndpoint.getTarget());
            managedEndpoints.remove(preEndpoint);
            managedEndpoints.add(createdEndpoint);
        }
    }
}
Also used : DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint) Endpoint(io.gravitee.definition.model.Endpoint) DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)

Aggregations

Endpoint (io.gravitee.definition.model.Endpoint)17 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)12 Test (org.junit.Test)10 DiscoveredEndpoint (io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)3 URL (java.net.URL)3 Api (io.gravitee.gateway.handlers.api.definition.Api)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Event (io.gravitee.common.event.Event)1 EventListener (io.gravitee.common.event.EventListener)1 EventManager (io.gravitee.common.event.EventManager)1 GraviteeMapper (io.gravitee.definition.jackson.datatype.GraviteeMapper)1 Api (io.gravitee.definition.model.Api)1 EndpointType (io.gravitee.definition.model.EndpointType)1 HttpClientOptions (io.gravitee.definition.model.HttpClientOptions)1 EndpointDiscoveryProvider (io.gravitee.definition.model.services.discovery.EndpointDiscoveryProvider)1 EndpointDiscoveryService (io.gravitee.definition.model.services.discovery.EndpointDiscoveryService)1 ConsulEndpointDiscoveryConfiguration (io.gravitee.definition.model.services.discovery.consul.ConsulEndpointDiscoveryConfiguration)1 HealthCheckService (io.gravitee.definition.model.services.healthcheck.HealthCheckService)1 Request (io.gravitee.definition.model.services.healthcheck.Request)1