Class HTTPServer

java.lang.Object
org.languagetool.server.HTTPServer

public class HTTPServer extends Object
A small embedded HTTP server that checks text. Returns XML, prints debugging to stdout/stderr. Note that by default the server only accepts connections from localhost for security reasons.
Author:
Daniel Naber, Ankit
  • Field Details

    • DEFAULT_ALLOWED_IPS

      protected static final Set<String> DEFAULT_ALLOWED_IPS
    • port

      protected int port
    • host

      protected String host
    • server

      protected com.sun.net.httpserver.HttpServer server
    • httpHandler

      protected org.languagetool.server.LanguageToolHttpHandler httpHandler
  • Constructor Details

    • HTTPServer

      public HTTPServer()
      Prepare a server on the given port - use run() to start it. Accepts connections from localhost only.
    • HTTPServer

      public HTTPServer(HTTPServerConfig config)
      Prepare a server on localhost on the given port - use run() to start it. Accepts connections from localhost only.
      Throws:
      PortBindingException - if we cannot bind to the given port, e.g. because something else is running there
    • HTTPServer

      public HTTPServer(HTTPServerConfig config, boolean runInternally)
      Prepare a server on localhost on the given port - use run() to start it. Accepts connections from localhost only.
      Parameters:
      runInternally - if true, then the server was started from the GUI.
      Throws:
      PortBindingException - if we cannot bind to the given port, e.g. because something else is running there
    • HTTPServer

      public HTTPServer(HTTPServerConfig config, boolean runInternally, Set<String> allowedIps)
      Prepare a server on localhost on the given port - use run() to start it. The server will bind to localhost.
      Parameters:
      runInternally - if true, then the server was started from the GUI.
      allowedIps - the IP addresses from which connections are allowed or null to allow any host
      Throws:
      PortBindingException - if we cannot bind to the given port, e.g. because something else is running there
    • HTTPServer

      public HTTPServer(HTTPServerConfig config, boolean runInternally, String host, Set<String> allowedIps)
      Prepare a server on the given host and port - use run() to start it.
      Parameters:
      runInternally - if true, then the server was started from the GUI.
      host - the host to bind to, e.g. "localhost" or null to bind to any host
      allowedIps - the IP addresses from which connections are allowed or null to allow any host
      Throws:
      PortBindingException - if we cannot bind to the given port, e.g. because something else is running there
      Since:
      1.7
  • Method Details

    • stop

      public void stop()
      Stop the server. Once stopped, a server cannot be used again.
    • main

      public static void main(String[] args)
    • getProtocol

      protected String getProtocol()
    • run

      public void run()
      Start the server.
    • isRunning

      public boolean isRunning()
      Returns:
      whether the server is running
      Since:
      2.0
    • getRequestLimiterOrNull

      @Nullable protected @Nullable org.languagetool.server.RequestLimiter getRequestLimiterOrNull(HTTPServerConfig config)
    • getErrorRequestLimiterOrNull

      @Nullable protected @Nullable org.languagetool.server.ErrorRequestLimiter getErrorRequestLimiterOrNull(HTTPServerConfig config)
    • usageRequested

      protected static boolean usageRequested(String[] args)
    • printCommonConfigFileOptions

      protected static void printCommonConfigFileOptions()
    • printCommonOptions

      protected static void printCommonOptions()
    • checkForNonRootUser

      protected static void checkForNonRootUser()
    • getExecutorService

      protected ThreadPoolExecutor getExecutorService(LinkedBlockingQueue<Runnable> workQueue, HTTPServerConfig config)