Code example for URI

Methods: getHostgetPort

0
        if (host == null) {
            String referrer = request.getHeader("referer");
            if (referrer != null) {
                URI url;
                try { 
                    url = new URI(referrer);
                    int port = url.getPort();
                    host = url.getHost() + ((port > -1) ? ":" + url.getPort() : "");
                } catch (URISyntaxException e) {
                    throw new RuntimeException("referrer '" + referrer + "' can't be parsed as a URL");
                } 
            } else { 
                throw new RuntimeException("neither the 'host' nor 'referer' headers were present in the HTTP response, I can't determine what URL OpenRefine is listening to.");
            } 
        } 
        return "http://" + host + "/command/core/authorize/" + provider.getHost();
    } 
}