Java Code Examples for org.wso2.carbon.utils.NetworkUtils#getMgtHostName()

The following examples show how to use org.wso2.carbon.utils.NetworkUtils#getMgtHostName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceManagerUtil.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: DeviceManagerUtil.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: URLPrinterStartupHandler.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
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";
}
 
Example 4
Source File: CarbonUIUtil.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: CarbonUIUtil.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns url to admin console. eg: https://192.168.1.201:9443/wso2/carbon
 *
 * @param request The HTTPServletRequest
 * @return The URL of the Admin Console
 */
public static String getAdminConsoleURL(HttpServletRequest request) {

    // 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
    String context = request.getContextPath();
    if ("/".equals(context)) {
        context = "";
    }

    String proxyContextPath = CarbonUIUtil.getProxyContextPath(false);

    if (httpsPort == -1) {
        return null;
    }
    
    String adminConsoleURL = null;
    String enableHTTPAdminConsole = CarbonUIServiceComponent.getServerConfiguration()
            .getFirstProperty(CarbonConstants.ENABLE_HTTP_ADMIN_CONSOLE);

    if (enableHTTPAdminConsole != null
            && "true".equalsIgnoreCase(enableHTTPAdminConsole.trim())) {
        int httpPort = CarbonUtils.getTransportPort(
                CarbonUIServiceComponent.getConfigurationContextService(), "http");
        adminConsoleURL = "http://" + hostName + ":" + httpPort + proxyContextPath + context + "/carbon/";
    } else {
        adminConsoleURL = "https://" + hostName + ":"
                + (httpsProxyPort != -1 ? httpsProxyPort : httpsPort) + proxyContextPath + context + "/carbon/";
    }

    if(log.isDebugEnabled()){
        log.debug("Generated admin console URL: " + adminConsoleURL);
    }
    return adminConsoleURL;
}