From 93dd426059988f151be8c65bfb951efb2805938e Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Thu, 17 Feb 2022 17:33:30 +0800 Subject: [PATCH] Support authorization in eureka.serviceUrl --- .../eureka/FizzEurekaServiceRegistration.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/fizz-core/src/main/java/we/service_registry/eureka/FizzEurekaServiceRegistration.java b/fizz-core/src/main/java/we/service_registry/eureka/FizzEurekaServiceRegistration.java index cfa4a81..d714a12 100644 --- a/fizz-core/src/main/java/we/service_registry/eureka/FizzEurekaServiceRegistration.java +++ b/fizz-core/src/main/java/we/service_registry/eureka/FizzEurekaServiceRegistration.java @@ -63,16 +63,30 @@ public class FizzEurekaServiceRegistration extends FizzServiceRegistration { for (String serviceUrl : eurekaServerServiceUrls) { String vip; int port; - int begin = serviceUrl.indexOf('p') + 4; - int colon = serviceUrl.indexOf(':', begin); - if (colon > -1) { - int end = serviceUrl.indexOf('/', colon); - vip = serviceUrl.substring(begin, colon); - port = Integer.parseInt(serviceUrl.substring(colon + 1, end)); + int at = serviceUrl.indexOf('@'); + if (at > -1) { + int colon = serviceUrl.indexOf(':', at); + if (colon > -1) { + int slash = serviceUrl.indexOf('/', colon); + vip = serviceUrl.substring(at + 1, colon); + port = Integer.parseInt(serviceUrl.substring(colon + 1, slash)); + } else { + int slash = serviceUrl.indexOf('/', at); + vip = serviceUrl.substring(at + 1, slash); + port = 80; + } } else { - int end = serviceUrl.indexOf('/', begin); - vip = serviceUrl.substring(begin, end); - port = 80; + int begin = serviceUrl.indexOf('/') + 2; + int colon = serviceUrl.indexOf(':', begin); + if (colon > -1) { + int slash = serviceUrl.indexOf('/', colon); + vip = serviceUrl.substring(begin, colon); + port = Integer.parseInt(serviceUrl.substring(colon + 1, slash)); + } else { + int slash = serviceUrl.indexOf('/', begin); + vip = serviceUrl.substring(begin, slash); + port = 80; + } } registryCenterVip2port.put(vip, port); }