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();
}
}
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);
}
}
}
Aggregations