Class ServerUtils

java.lang.Object
org.glassfish.tests.utils.ServerUtils

public class ServerUtils extends Object
Author:
David Matejcek
  • Constructor Details

    • ServerUtils

      public ServerUtils()
  • Method Details

    • getFreePorts

      public static Queue<Integer> getFreePorts(int count) throws IllegalStateException
      Tries to allocate a free local ports, avoids duplicates.
      Parameters:
      count - count of free ports to find.
      Returns:
      a modifiable queue of free local port numbers.
      Throws:
      IllegalStateException - if it fails for 20 times
    • getFreePort

      public static int getFreePort() throws IllegalStateException
      Tries to allocate a free local port.
      Returns:
      a free local port number.
      Throws:
      IllegalStateException - if it fails for 20 times
    • getFreePort

      public static int getFreePort(Set<Integer> excluded) throws IllegalStateException
      Tries to allocate a free local port.
      Parameters:
      excluded - ports to avoid
      Returns:
      a free local port number.
      Throws:
      IllegalStateException - if it fails for 20 times
    • getLocalIP4Address

      public static String getLocalIP4Address()
      Returns:
      the IP address of the localhost.
    • createWar

      public static File createWar(File warFile, Class<?>... classes)
      Creates a simple war file made of provided classes.
      Parameters:
      warFile - the WAR file
      classes - a classes to be included to the WAR file
      Returns:
      file usable for deployment.
    • download

      public static String download(URL url) throws IOException
      Downloads content from the url. Expects there is a service listening and returning textual response. Therefore this is usable just for simple servlets.
      Parameters:
      url - target URL
      Returns:
      content from the url.
      Throws:
      IOException - if an error occurred
    • runCommand

      public static org.glassfish.embeddable.CommandResult runCommand(org.glassfish.embeddable.GlassFish glassfish, String cmd, String params) throws org.glassfish.embeddable.GlassFishException
      Executes a command on embedded GlassFish instance.
      Parameters:
      glassfish - an embedded GlassFish instance
      cmd - a command to run
      params - command parameters
      Returns:
      result of command execution
      Throws:
      org.glassfish.embeddable.GlassFishException - if an error occurred