public ProxyDetails()

in hawtio-system/src/main/java/io/hawt/web/proxy/ProxyDetails.java [65:138]


    public ProxyDetails(String pathInfo) {
        hostAndPort = pathInfo.replace(" ", "%20");

        while (hostAndPort.startsWith("/")) {
            hostAndPort = hostAndPort.substring(1);
        }

        if (hostAndPort.startsWith("http/")) {
            scheme = "http";
            hostAndPort = hostAndPort.substring(5);
        } else if (hostAndPort.startsWith("https/")) {
            scheme = "https";
            hostAndPort = hostAndPort.substring(6);
        }

        // remove user/pwd
        int idx = hostAndPort.indexOf("@");
        if (idx > 0) {
            userName = hostAndPort.substring(0, idx);
            hostAndPort = hostAndPort.substring(idx + 1);

            idx = indexOf(userName, ":", "/");
            if (idx > 0) {
                password = userName.substring(idx + 1);
                userName = userName.substring(0, idx);
            }
        }
        host = hostAndPort;
        int schemeIdx = indexOf(hostAndPort, "://");
        if (schemeIdx > 0) {
            scheme = hostAndPort.substring(0, schemeIdx);
            hostAndPort = hostAndPort.substring(schemeIdx + 3);
        } else {
            // hawtio may report scheme without a double slash so lets handle that 'bug' also
            schemeIdx = indexOf(hostAndPort, ":/");
            if (schemeIdx > 0) {
                scheme = hostAndPort.substring(0, schemeIdx);
                hostAndPort = hostAndPort.substring(schemeIdx + 2);
            }
        }
        idx = indexOf(hostAndPort, ":", "/");
        if (idx > 0) {
            host = hostAndPort.substring(0, idx);
            String portText = hostAndPort.substring(idx + 1);
            idx = portText.indexOf("/");
            if (idx >= 0) {
                path = portText.substring(idx);
                portText = portText.substring(0, idx);
            }

            if (Strings.isNotBlank(portText)) {
                // portText may be a port unless its default
                try {
                    port = Integer.parseInt(portText);
                    hostAndPort = host + ":" + port;
                } catch (NumberFormatException e) {
                    port = "http".equals(scheme) ? 80 : 443;
                    // we do not have a port, so path is the portText
                    path = "/" + portText + path;
                    hostAndPort = host;
                }
            } else {
                hostAndPort = host;
            }
        }

        stringProxyURL = scheme + "://" + hostAndPort + path;

        // we do not support query parameters

        if (LOG.isDebugEnabled()) {
            LOG.debug("Proxying to " + stringProxyURL + " as user: " + userName);
        }
    }