本文整理汇总了Java中org.wso2.carbon.utils.NetworkUtils类的典型用法代码示例。如果您正苦于以下问题:Java NetworkUtils类的具体用法?Java NetworkUtils怎么用?Java NetworkUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkUtils类属于org.wso2.carbon.utils包,在下文中一共展示了NetworkUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getServerBaseHttpsUrl
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
public static String getServerBaseHttpsUrl() {
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
mgtConsoleTransport);
if (httpsProxyPort > 0) {
port = httpsProxyPort;
}
return "https://" + hostName + ":" + port;
}
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:19,代码来源:DeviceManagerUtil.java
示例2: getServerBaseHttpUrl
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
public static String getServerBaseHttpUrl() {
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, "http");
int httpProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
"http");
if (httpProxyPort > 0) {
port = httpProxyPort;
}
return "http://" + hostName + ":" + port;
}
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:18,代码来源:DeviceManagerUtil.java
示例3: getServerUrl
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
private String getServerUrl() {
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
// HTTPS port
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService =
UrlPrinterDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), mgtConsoleTransport);
if (httpsProxyPort > 0) {
port = httpsProxyPort;
}
return "https://" + hostName + ":" + port + "/devicemgt";
}
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:20,代码来源:URLPrinterStartupHandler.java
示例4: 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;
}
开发者ID:wso2,项目名称:carbon-registry,代码行数:26,代码来源:ResourceUtil.java
示例5: 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;
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:27,代码来源:Util.java
示例6: authenticate
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
public boolean authenticate(String username, String password) throws AuthenticationExceptionException,
RemoteException {
try {
boolean isAuthenticated = stub.login(username,password,NetworkUtils.getLocalHostname());
if(isAuthenticated){
ServiceContext serviceContext;
serviceContext = stub._getServiceClient().getLastOperationContext().getServiceContext();
String sessionCookie;
sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
this.sessionCookie = sessionCookie;
}else{
throw new AuthenticationExceptionException("Authentication Failed");
}
return isAuthenticated;
} catch (SocketException e) {
throw new AuthenticationExceptionException(e);
}
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:20,代码来源:AuthenticationClient.java
示例7: 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;
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:22,代码来源:WSDL2Code.java
示例8: 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());
}
}
开发者ID:wso2,项目名称:product-es,代码行数:27,代码来源:JMXClient.java
示例9: 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();
}
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:16,代码来源:EntitlementServiceComponent.java
示例10: 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;
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:18,代码来源:IdentityUtil.java
示例11: setUp
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
mockStatic(CarbonUtils.class);
mockStatic(ServerConfiguration.class);
mockStatic(NetworkUtils.class);
mockStatic(IdentityCoreServiceComponent.class);
mockStatic(IdentityConfigParser.class);
mockStatic(CarbonUtils.class);
mockStatic(IdentityTenantUtil.class);
when(ServerConfiguration.getInstance()).thenReturn(mockServerConfiguration);
when(IdentityCoreServiceComponent.getConfigurationContextService()).thenReturn(mockConfigurationContextService);
when(mockConfigurationContextService.getServerConfigContext()).thenReturn(mockConfigurationContext);
when(mockConfigurationContext.getAxisConfiguration()).thenReturn(mockAxisConfiguration);
when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService);
when(mockRealmService.getTenantManager()).thenReturn(mockTenantManager);
when(CarbonUtils.getCarbonHome()).thenReturn("carbon.home");
when(mockRequest.getRemoteAddr()).thenReturn("127.0.0.1");
when(mockUserStoreManager.getRealmConfiguration()).thenReturn(mockRealmConfiguration);
when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockRealmConfiguration);
when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
try {
when(NetworkUtils.getLocalHostname()).thenReturn("localhost");
} catch (SocketException e) {
// Mock behaviour, hence ignored
}
System.setProperty(IdentityConstants.CarbonPlaceholders.CARBON_PORT_HTTP_PROPERTY, "9763");
System.setProperty(IdentityConstants.CarbonPlaceholders.CARBON_PORT_HTTPS_PROPERTY, "9443");
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:31,代码来源:IdentityUtilTest.java
示例12: 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;
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:17,代码来源:IdentityUtil.java
示例13: 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;
}
开发者ID:wso2,项目名称:carbon-business-process,代码行数:32,代码来源:PeopleActivity.java
示例14: setBasePath
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
public void setBasePath(String basePath)
{
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
super.setBasePath("https://" +
hostName + ":" + System.getProperty("mgt.transport.https.port") +
"/resource/1.0.0");
}
开发者ID:wso2,项目名称:carbon-registry,代码行数:14,代码来源:SwaggerJaxrsConfig.java
示例15: getAdminConsoleURL
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
/**
* Returns url to admin console.
*
* @param context Webapp context root of the Carbon webapp
* @return The URL of the Admin Console
*/
public static String getAdminConsoleURL(String context) {
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
// HTTPS port
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService = CarbonUIServiceComponent
.getConfigurationContextService();
int httpsPort = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
mgtConsoleTransport);
// Context
if ("/".equals(context)) {
context = "";
}
String proxyContextPath = CarbonUIUtil.getProxyContextPath(false);
String adminConsoleURL = "https://" + hostName + ":" + (httpsProxyPort != -1 ? httpsProxyPort : httpsPort) +
proxyContextPath + context + "/carbon/";
if(log.isDebugEnabled()){
log.debug("Generated admin console URL: " + adminConsoleURL);
}
return adminConsoleURL;
}
开发者ID:apache,项目名称:stratos,代码行数:39,代码来源:CarbonUIUtil.java
示例16: setBasePath
import org.wso2.carbon.utils.NetworkUtils; //导入依赖的package包/类
public void setBasePath(String basePath)
{
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
super.setBasePath("https://" +
hostName + ":" + System.getProperty("mgt.transport.https.port") + "/governance");
}
开发者ID:wso2,项目名称:carbon-governance,代码行数:13,代码来源:SwaggerJaxrsConfig.java
示例17: 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();
}
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:69,代码来源:IdentityUtil.java
示例18: 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();
}
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:70,代码来源:IdentityUtil.java
示例19: 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;
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:7,代码来源:AbstractClient.java
示例20: 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;
}
开发者ID:wso2,项目名称:carbon-commons,代码行数:7,代码来源:AbstractClient.java
注:本文中的org.wso2.carbon.utils.NetworkUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论