DEV Community

Query Filter
Query Filter

Posted on

gradle3

package bootstrap;

import java.lang.reflect.Field;
import java.net.InetAddress;

public class BootstrapServer {
    public static void main(String[] args) throws Exception {
        // --- Read forced hostname from JVM property ---
        String forcedHost = System.getProperty("forced.hostname", "egtpsga56.nam.nsroot.net");

        // --- Force InetAddress to return the desired hostname ---
        ForceHostname.setHostname(forcedHost);

        // --- Delegate to the real external main class ---
        com.citigroup.get.quantum.server.Server.main(args);
    }

    // --- Helper class inside same file ---
    static class ForceHostname {
        public static void setHostname(String forcedHost) throws Exception {
            // Get the default local InetAddress
            InetAddress local = InetAddress.getLocalHost();

            // Access the private 'holder' field inside InetAddress
            Field holderField = InetAddress.class.getDeclaredField("holder");
            holderField.setAccessible(true);
            Object holder = holderField.get(local);

            // Overwrite the hostName inside the holder
            Field hostNameField = holder.getClass().getDeclaredField("hostName");
            hostNameField.setAccessible(true);
            hostNameField.set(holder, forcedHost);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)