All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.nav.sbl.dialogarena.common.jetty.ToUrl Maven / Gradle / Ivy

There is a newer version: 2.2020.04.22_16.44-8c304813febf
Show newest version
package no.nav.sbl.dialogarena.common.jetty;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.function.Function;

public class ToUrl implements Function {

    public static final String JETTY_PRINT_LOCALHOST = "jetty.print.localhost";

    private final String scheme;
    private final String path;

    public ToUrl(String scheme, String path) {
        this.scheme = scheme;
        this.path = (path.startsWith("/") ? "" : "/") + path;
    }

    @Override
    public URL apply(Integer port) {
        try {
            if(System.getProperty(JETTY_PRINT_LOCALHOST) != null) {
                return new URL(scheme + "://localhost:" + port + path);
            }
            return new URL(scheme + "://" + InetAddress.getLocalHost().getCanonicalHostName() + ":" + port + path);
        } catch (MalformedURLException | UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy