protected ProxyAddress parseProxyAddress()

in hawtio-system/src/main/java/io/hawt/web/kubernetes/ServiceServlet.java [36:76]


    protected ProxyAddress parseProxyAddress(HttpServletRequest servletRequest) {
        String reqQueryString = servletRequest.getQueryString();
        String queryPostfix = "";
        if (Strings.isNotBlank(reqQueryString)) {
            queryPostfix = "?" + reqQueryString;
        }
        String userName = null;
        String password = null;
        String serviceName = servletRequest.getPathInfo();
        if (serviceName == null) {
            serviceName = "";
        }
        if (serviceName.startsWith("/")) {
            serviceName = serviceName.substring(1);
        }
        int idx = serviceName.indexOf('/');
        String servicePath = "/";
        if (idx > 0) {
            servicePath = serviceName.substring(idx);
            serviceName = serviceName.substring(0, idx);
        }
        if (serviceName.length() == 0) {
            // lets list the services for /service
            serviceName = "kubernetes";
            servicePath = "/kubernetes/api/v1beta2/services";
        }

        String url = ServiceResolver.getSingleton().getServiceURL(serviceName);
        if (url == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No service for: " + serviceName + " path: " + servicePath);
            }
            return null;
        } else {
            url += servicePath + queryPostfix;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Invoking: " + url + " from service: " + serviceName + " path: " + servicePath);
            }
            return new DefaultProxyAddress(url, userName, password);
        }
    }