Skip to content

Commit

Permalink
Develop (#321)
Browse files Browse the repository at this point in the history
* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308
  • Loading branch information
paderlol authored May 15, 2023
1 parent 0e73a08 commit 02838da
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.alibaba.nacossync.extension.holder;

import com.alibaba.nacossync.extension.eureka.EurekaNamingService;
Expand All @@ -30,12 +31,27 @@
@Service
@Slf4j
public class EurekaServerHolder extends AbstractServerHolderImpl<EurekaNamingService> {

private static final String HTTP_PREFIX = "http://";

private static final String HTTPS_PREFIX = "https://";

@Override
EurekaNamingService createServer(String clusterId, Supplier<String> serverAddressSupplier) throws Exception {
RestTemplateTransportClientFactory restTemplateTransportClientFactory =
new RestTemplateTransportClientFactory();
EurekaEndpoint eurekaEndpoint = new DefaultEndpoint(serverAddressSupplier.get());
RestTemplateTransportClientFactory restTemplateTransportClientFactory = new RestTemplateTransportClientFactory();
EurekaEndpoint eurekaEndpoint = new DefaultEndpoint(addHttpPrefix(serverAddressSupplier.get()));
EurekaHttpClient eurekaHttpClient = restTemplateTransportClientFactory.newClient(eurekaEndpoint);
return new EurekaNamingService(eurekaHttpClient);
}

public String addHttpPrefix(String input) {
if (input == null || input.isEmpty()) {
return input;
}
if (!input.startsWith(HTTP_PREFIX) && !input.startsWith(HTTPS_PREFIX)) {
input = HTTP_PREFIX + input;
}

return input;
}
}

0 comments on commit 02838da

Please sign in to comment.