cz.mmsparams.api.http.ServerAddressProvider Maven / Gradle / Ivy
package cz.mmsparams.api.http;
import cz.mmsparams.api.utils.Preconditions;
import cz.mmsparams.api.utils.StringUtil;
import cz.mmsparams.api.utils.UrlUtils;
/**
* Provider of Server address and Server WebSocket address
*/
public class ServerAddressProvider
{
private final String address;
private final String port;
/**
* Initialize ServerAddressProvider
*
* @param address server address in simple format (eg. 192.168.1.10; test.com)
*/
public ServerAddressProvider(String address)
{
Preconditions.checkNotNullOrEmpty(address, "address");
this.address = address;
this.port = null;
}
/**
* Initialize ServerAddressProvider
*
* @param address server address in simple format (eg. 192.168.1.10; test.com)
* @param port server port
*/
public ServerAddressProvider(String address, String port)
{
Preconditions.checkNotNullOrEmpty(address, "address");
Preconditions.checkNotNullOrEmpty(port, "port");
this.address = address;
this.port = port;
}
/**
* Returns Server address
*
* @return server address
*/
public String getServerAddress()
{
if (StringUtil.isEmptyOrNull(port))
return address;
else
return address + ":" + port;
}
/**
* Returns Server WebSocket address
*
* @return server WebSocket address
*/
public String getWSAddress()
{
if (StringUtil.isEmptyOrNull(port))
return UrlUtils.getServerSocketUrl(address);
else
return UrlUtils.getServerSocketUrl(address, port);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy