001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.components.gateway.discovery;
017
018import io.jboot.Jboot;
019import io.jboot.utils.NetUtil;
020import io.jboot.utils.StrUtil;
021
022public class GatewayInstanceConfig {
023
024    private String name;
025    private String uriScheme = "http";
026    private String uriHost;
027    private int uriPort;
028    private String uriPath;
029
030    public String getName() {
031        return name;
032    }
033
034    public void setName(String name) {
035        this.name = name;
036    }
037
038    public String getUriScheme() {
039        return uriScheme;
040    }
041
042    public void setUriScheme(String uriScheme) {
043        this.uriScheme = uriScheme;
044    }
045
046    public String getUriHost() {
047        return uriHost;
048    }
049
050    public void setUriHost(String uriHost) {
051        this.uriHost = uriHost;
052    }
053
054    public int getUriPort() {
055        return uriPort;
056    }
057
058    public void setUriPort(int uriPort) {
059        this.uriPort = uriPort;
060    }
061
062    public String getUriPath() {
063        return uriPath;
064    }
065
066    public void setUriPath(String uriPath) {
067        this.uriPath = uriPath;
068    }
069
070    public String toUri() {
071        StringBuilder sb = new StringBuilder(uriScheme).append("://");
072        if (StrUtil.isNotBlank(uriHost)) {
073            sb.append(uriHost);
074        } else {
075            sb.append(NetUtil.getLocalIpAddress());
076        }
077        if (uriPort == 0) {
078            uriPort = Integer.parseInt(Jboot.configValue("undertow.port", "8080"));
079        }
080        sb.append(":").append(uriPort);
081        if (StrUtil.isNotBlank(uriPath)) {
082            sb.append(uriPath);
083        }
084
085        return sb.toString();
086    }
087}