本文整理汇总了Java中org.wso2.carbon.utils.NetworkUtils.getLocalHostname方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkUtils.getLocalHostname方法的具体用法?Java NetworkUtils.getLocalHostname怎么用?Java NetworkUtils.getLocalHostname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.utils.NetworkUtils
的用法示例。
在下文中一共展示了NetworkUtils.getLocalHostname方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findServerHost
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
/**
* Find hostname of this server instance.
*
* @return
* @throws RegistryException
*/
private static String findServerHost() throws RegistryException {
String host;
try {
host = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
host = null;
log.warn("An error occured while determining server host", e);
}
if (host == null) {
host = System.getProperty("carbon.local.ip");
log.warn("Unable to obtain server host, using the carbon.local.ip system "
+ "property to determine the ip address");
}
if (host == null) {
throw new RegistryException("Unable to find server host");
}
log.debug("Found server host: " + host);
return host;
}
示例2: getWsdlInformation
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
public static String getWsdlInformation(String serviceName,
AxisConfiguration axisConfig) throws AxisFault {
String ip;
try {
ip = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
throw new AxisFault("Cannot get local host name", e);
}
TransportInDescription transportInDescription = axisConfig.getTransportIn("http");
if (transportInDescription == null) {
transportInDescription = axisConfig.getTransportIn("https");
}
if (transportInDescription != null) {
EndpointReference[] epr =
transportInDescription.getReceiver().getEPRsForService(serviceName, ip);
String wsdlUrlPrefix = epr[0].getAddress();
if (wsdlUrlPrefix.endsWith("/")) {
wsdlUrlPrefix = wsdlUrlPrefix.substring(0, wsdlUrlPrefix.length() - 1);
}
return wsdlUrlPrefix + "?wsdl";
}
return null;
}
示例3: getWsdlInformation
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
private String getWsdlInformation(String serviceName, AxisConfiguration axisConfig)
throws AxisFault {
String ip;
try {
ip = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
throw new AxisFault("Cannot get local host name", e);
}
TransportInDescription http = axisConfig.getTransportIn("http");
if (http != null) {
EndpointReference epr =
((HttpTransportListener) http.getReceiver()).
getEPRForService(serviceName, ip);
String wsdlUrlPrefix = epr.getAddress();
if (wsdlUrlPrefix.endsWith("/")) {
wsdlUrlPrefix = wsdlUrlPrefix.substring(0, wsdlUrlPrefix.length() - 1);
}
return wsdlUrlPrefix + "?wsdl";
}
return null;
}
示例4: connect
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
/**
* connect to org.wso2.carbon for JMX monitoring
*
* @param userName user name to connect to org.wso2.carbon
* @param password password to connect to org.wso2.carbon
* @throws Exception
*/
public void connect(String userName, String password) throws Exception {
try {
JMXServiceURL url =
new JMXServiceURL("service:jmx:rmi://" +
NetworkUtils.getLocalHostname() + ":" +
RMIServerPort + "/jndi/rmi://" +
NetworkUtils.getLocalHostname() + ":" +
RMIRegistryPort + "/jmxrmi");
Hashtable<String, String[]> hashT = new Hashtable<>();
String[] credentials = new String[]{userName, password};
hashT.put("jmx.remote.credentials", credentials);
jmxc = JMXConnectorFactory.connect(url, hashT);
mbsc = jmxc.getMBeanServerConnection();
nodeAgent = new ObjectName(CONNECTION_NAME);
} catch (Exception ex) {
log.error("infoAdminServiceStub Initialization fail ");
throw new Exception("infoAdminServiceStub Initialization fail " + ex.getMessage());
}
}
示例5: readThriftHostName
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
/**
* Read the thrift hostname from identity.xml which overrides the hostName from carbon.xml on facilitating
* identifying the host for thrift server .
*/
private String readThriftHostName() throws SocketException {
String thriftHostName = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_HOST_NAME);
//if the thrift host name doesn't exist in config, load from carbon.xml
if (thriftHostName != null) {
return thriftHostName;
} else {
return NetworkUtils.getLocalHostname();
}
}
示例6: getHostName
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
/**
* Get the host name of the server.
*
* @return Hostname
*/
public static String getHostName() {
String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME);
if (hostName == null) {
try {
hostName = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
throw IdentityRuntimeException.error("Error while trying to read hostname.", e);
}
}
return hostName;
}
示例7: getHostName
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
/**
* Get the host name of the server.
* @return Hostname
*/
public static String getHostName() {
String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME);
if (hostName == null) {
try {
hostName = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
throw IdentityRuntimeException.error("Error while trying to read hostname.", e);
}
}
return hostName;
}
示例8: generateServiceURLUpToWebContext
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
private String generateServiceURLUpToWebContext() throws B4PCoordinationException, FaultException {
String baseURL = "";
if (CoordinationConfiguration.getInstance().isClusteredTaskEngines()) {
baseURL = CoordinationConfiguration.getInstance().getLoadBalancerURL();
} else {
ConfigurationContext serverConfigurationContext = getConfigurationContext();
String scheme = CarbonConstants.HTTPS_TRANSPORT;
String host;
try {
host = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
log.error(e.getMessage(), e);
throw new B4PCoordinationException(e.getLocalizedMessage(), e);
}
int port = 9443;
port = CarbonUtils.getTransportProxyPort(serverConfigurationContext, scheme);
if (port == -1) {
port = CarbonUtils.getTransportPort(serverConfigurationContext, scheme);
}
baseURL = scheme + "://" + host + ":" + port;
}
String webContext = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
if (webContext == null || webContext.equals("/")) {
webContext = "";
}
return baseURL + webContext;
}
示例9: getServerURL
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
public static String getServerURL(String endpoint, boolean addProxyContextPath, boolean addWebContextRoot)
throws IdentityRuntimeException {
String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME);
try {
if (hostName == null) {
hostName = NetworkUtils.getLocalHostname();
}
} catch (SocketException e) {
throw IdentityRuntimeException.error("Error while trying to read hostname.", e);
}
String mgtTransport = CarbonUtils.getManagementTransport();
AxisConfiguration axisConfiguration = IdentityCoreServiceComponent.getConfigurationContextService().
getServerConfigContext().getAxisConfiguration();
int mgtTransportPort = CarbonUtils.getTransportProxyPort(axisConfiguration, mgtTransport);
if (mgtTransportPort <= 0) {
mgtTransportPort = CarbonUtils.getTransportPort(axisConfiguration, mgtTransport);
}
if (hostName.endsWith("/")) {
hostName = hostName.substring(0, hostName.length() - 1);
}
StringBuilder serverUrl = new StringBuilder(mgtTransport).append("://").append(hostName.toLowerCase());
// If it's well known HTTPS port, skip adding port
if (mgtTransportPort != IdentityCoreConstants.DEFAULT_HTTPS_PORT) {
serverUrl.append(":").append(mgtTransportPort);
}
// If ProxyContextPath is defined then append it
if (addProxyContextPath) {
// If ProxyContextPath is defined then append it
String proxyContextPath = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants
.PROXY_CONTEXT_PATH);
if (StringUtils.isNotBlank(proxyContextPath)) {
if (proxyContextPath.trim().charAt(0) != '/') {
serverUrl.append("/").append(proxyContextPath.trim());
} else {
serverUrl.append(proxyContextPath.trim());
}
}
}
// If webContextRoot is defined then append it
if (addWebContextRoot) {
String webContextRoot = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants
.WEB_CONTEXT_ROOT);
if (StringUtils.isNotBlank(webContextRoot)) {
if (webContextRoot.trim().charAt(0) != '/') {
serverUrl.append("/").append(webContextRoot.trim());
} else {
serverUrl.append(webContextRoot.trim());
}
}
}
if (StringUtils.isNotBlank(endpoint)) {
if (!serverUrl.toString().endsWith("/") && endpoint.trim().charAt(0) != '/') {
serverUrl.append("/").append(endpoint.trim());
} else if (serverUrl.toString().endsWith("/") && endpoint.trim().charAt(0) == '/') {
serverUrl.append(endpoint.trim().substring(1));
} else {
serverUrl.append(endpoint.trim());
}
}
if (serverUrl.toString().endsWith("/")) {
serverUrl.setLength(serverUrl.length() - 1);
}
return serverUrl.toString();
}
示例10: getServerURL
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
public static String getServerURL(String endpoint, boolean addProxyContextPath, boolean addWebContextRoot)
throws IdentityRuntimeException {
String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME);
try {
if (hostName == null) {
hostName = NetworkUtils.getLocalHostname();
}
} catch (SocketException e) {
throw IdentityRuntimeException.error("Error while trying to read hostname.", e);
}
String mgtTransport = CarbonUtils.getManagementTransport();
AxisConfiguration axisConfiguration = IdentityCoreServiceComponent.getConfigurationContextService().
getServerConfigContext().getAxisConfiguration();
int mgtTransportPort = CarbonUtils.getTransportProxyPort(axisConfiguration, mgtTransport);
if (mgtTransportPort <= 0) {
mgtTransportPort = CarbonUtils.getTransportPort(axisConfiguration, mgtTransport);
}
StringBuilder serverUrl = new StringBuilder(mgtTransport).append("://").append(hostName.toLowerCase());
// If it's well known HTTPS port, skip adding port
if (mgtTransportPort != IdentityCoreConstants.DEFAULT_HTTPS_PORT) {
serverUrl.append(":").append(mgtTransportPort);
}
// If ProxyContextPath is defined then append it
if(addProxyContextPath) {
// If ProxyContextPath is defined then append it
String proxyContextPath = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants
.PROXY_CONTEXT_PATH);
if (StringUtils.isNotBlank(proxyContextPath)) {
if (!serverUrl.toString().endsWith("/") && proxyContextPath.trim().charAt(0) != '/') {
serverUrl.append("/").append(proxyContextPath.trim());
} else if (serverUrl.toString().endsWith("/") && proxyContextPath.trim().charAt(0) == '/') {
serverUrl.append(proxyContextPath.trim().substring(1));
} else {
serverUrl.append(proxyContextPath.trim());
}
}
}
// If webContextRoot is defined then append it
if (addWebContextRoot) {
String webContextRoot = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants
.WEB_CONTEXT_ROOT);
if (StringUtils.isNotBlank(webContextRoot)) {
if (!serverUrl.toString().endsWith("/") && webContextRoot.trim().charAt(0) != '/') {
serverUrl.append("/").append(webContextRoot.trim());
} else if (serverUrl.toString().endsWith("/") && webContextRoot.trim().charAt(0) == '/') {
serverUrl.append(webContextRoot.trim().substring(1));
} else {
serverUrl.append(webContextRoot.trim());
}
}
}
if (StringUtils.isNotBlank(endpoint)) {
if (!serverUrl.toString().endsWith("/") && endpoint.trim().charAt(0) != '/') {
serverUrl.append("/").append(endpoint.trim());
} else if (serverUrl.toString().endsWith("/") && endpoint.trim().charAt(0) == '/') {
serverUrl.append(endpoint.trim().substring(1));
} else {
serverUrl.append(endpoint.trim());
}
}
if (serverUrl.toString().endsWith("/")) {
serverUrl.deleteCharAt(serverUrl.length() - 1);
}
return serverUrl.toString();
}
示例11: getBackendServerURLHTTP
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
protected String getBackendServerURLHTTP() throws SocketException {
String contextRoot = ReportingTemplateComponent.getConfigurationContextService().getServerConfigContext().getContextRoot();
return "http://" + NetworkUtils.getLocalHostname() + ":" +
CarbonUtils.getTransportPort(ReportingTemplateComponent.getConfigurationContextService(), "http") + contextRoot;
}
示例12: getBackendServerURLHTTPS
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
protected String getBackendServerURLHTTPS() throws SocketException {
String contextRoot = ReportingTemplateComponent.getConfigurationContextService().getServerConfigContext().getContextRoot();
return "https://" + NetworkUtils.getLocalHostname() + ":" +
CarbonUtils.getTransportPort(ReportingTemplateComponent.getConfigurationContextService(), "https") + contextRoot;
}
示例13: update
import org.wso2.carbon.utils.NetworkUtils; //导入方法依赖的package包/类
public void update(AxisConfiguration axisConfig) throws AxisFault {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Parameter systemStartTime =
axisConfig.getParameter(CarbonConstants.SERVER_START_TIME);
long startTime = 0;
if (systemStartTime != null) {
startTime = Long.parseLong((String) systemStartTime.getValue());
}
Date stTime = new Date(startTime);
// only super admin can view serverStartTime and systemUpTime
if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
serverStartTime = dateFormatter.format(stTime);
systemUpTime = (getTime((System.currentTimeMillis() - startTime) / 1000));
}
try {
totalRequestCount = statService.getTotalSystemRequestCount(axisConfig);
totalResponseCount = statService.getSystemResponseCount(axisConfig);
totalFaultCount = statService.getSystemFaultCount(axisConfig);
avgResponseTime = statService.getAvgSystemResponseTime(axisConfig);
maxResponseTime = statService.getMaxSystemResponseTime(axisConfig);
minResponseTime = statService.getMinSystemResponseTime(axisConfig);
} catch (Exception e) {
throw AxisFault.makeFault(e);
}
Runtime runtime = Runtime.getRuntime();
// only super admin can view usedMemory and totalMemory
if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
usedMemory = formatMemoryValue(runtime.totalMemory() - runtime.freeMemory());
totalMemory = formatMemoryValue(runtime.totalMemory());
}
wso2wsasVersion = ServerConfiguration.getInstance().getFirstProperty("Version");
int activeServices = 0;
for (Iterator services = axisConfig.getServices().values().iterator();
services.hasNext(); ) {
AxisService axisService = (AxisService) services.next();
AxisServiceGroup asGroup = (AxisServiceGroup) axisService.getParent();
if (axisService.isActive() &&
!axisService.isClientSide() &&
!SystemFilter.isFilteredOutService(asGroup)) {
activeServices++;
}
}
this.services = activeServices;
try {
// only susper admin is allow to view serverName.
if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
serverName = NetworkUtils.getLocalHostname();
}
} catch (SocketException ignored) {
}
}