Class ProxyRegistry

java.lang.Object
org.omegazero.proxy.core.ProxyRegistry

public final class ProxyRegistry extends Object
Used for configuring and registering proxy settings or extensions.
Since:
3.9.1
  • Method Details

    • registerServerInstance

      public void registerServerInstance(Class<? extends org.omegazero.net.server.NetServer> c)
      Registers a new NetServer instance of the given type.

      A new instance of the given type is created and registered using registerServerInstance(NetServer). This requires that the given type has a constructor with no parameters. If the type requires additional arguments in the constructor, use Proxy.registerServerInstance(NetServer) directly instead.

      Parameters:
      c - The server class
      Throws:
      IllegalStateException - If this method is called after the INIT phase
    • registerServerInstance

      public void registerServerInstance(org.omegazero.net.server.NetServer server)
      Registers a new NetServer instance. The instance is added to the list of registered instances and will be initialized at the end of the main initialization phase, meaning server instances must be registered during the ProxyEvents.PREINIT or ProxyEvents.INIT event.
      Parameters:
      server - The server instance
      Throws:
      IllegalStateException - If this method is called after the INIT phase
    • registerClientManager

      public void registerClientManager(String id, org.omegazero.net.client.NetClientManager mgr)
      Registers a new NetClientManager for outgoing connections.
      Parameters:
      id - The identifier for the client manager
      mgr - The client manager
      Throws:
      IllegalArgumentException - If a client manager with the given id already exists
    • addHTTPEngineSelector

      public void addHTTPEngineSelector(Function<org.omegazero.net.socket.SocketConnection,Class<? extends HTTPEngine>> selector)
      Registers a new HTTPEngine selector.

      For incoming connections, an appropriate HTTPEngine must be selected. For this, every registered selector is called until one returns a non-null value, which will be the HTTPEngine used for the connection. If all selectors return null, an UnsupportedOperationException is thrown and the connection will be closed.

      Parameters:
      selector - The selector
    • registerHTTPClientImplementation

      public void registerHTTPClientImplementation(String name, ProxyRegistry.HTTPClientConstructor constructor, String alpName)
      Registers a new HTTPClient implementation for outgoing HTTP requests.

      The constructor of a HTTPClient receives the SocketConnection of the client and the target UpstreamServer the client should connect to.

      Parameters:
      name - The protocol name
      constructor - The constructor
      alpName - The application layer protocol name
      Throws:
      IllegalArgumentException - If an HTTP client implementation with the given name already exists
    • getHTTPClientImplementation

      public ProxyRegistry.HTTPClientConstructor getHTTPClientImplementation(String name)
      Returns a constructor of a HTTPClient implementation for the given protocol name.
      Parameters:
      name - The protocol name
      Returns:
      The constructor, or null if no implementation for the given protocol name exists
      See Also:
    • getHTTPClientALPName

      public String getHTTPClientALPName(String name)
      Returns the application layer protocol name for the given protocol name.
      Parameters:
      name - The protocol name
      Returns:
      The name used in ALPN negotiation, or null if no implementation for the given protocol name exists
      See Also:
    • setErrdoc

      public void setErrdoc(String type, HTTPErrdoc errdoc)
      Sets an error document for the given MIME type (Content-Type header in HTTP).

      The error document is returned by getErrdoc(String) when given the MIME type. The HTTPEngine implementation may choose any way to determine the appropriate error document type for a request, but usually does so using the Accept HTTP request header.

      Parameters:
      type - The content type to set this error document for
      errdoc - The error document
    • getErrdoc

      public HTTPErrdoc getErrdoc(String type)
      Returns the error document set for the given type. If no error document for the given type was set using setErrdoc(String, HTTPErrdoc), the default error document is returned (getDefaultErrdoc()).
      Parameters:
      type - The MIME type of the error document
      Returns:
      An error document of the given MIME type or the default error document if none was found
      See Also:
    • getDefaultErrdoc

      public HTTPErrdoc getDefaultErrdoc()
      Returns the default error document. This is guaranteed to be non-null.
      Returns:
      The default error document
    • getErrdocForAccept

      public HTTPErrdoc getErrdocForAccept(String accept)
      Parses the given value of an Accept HTTP header and returns the HTTPErrdoc for the first content type in the header for which an error document is found. If no overlap is found, or the header does not exist (the given value is null), the default error document is returned.
      Parameters:
      accept - The value of an Accept HTTP header
      Returns:
      A suitable HTTPErrdoc, or the default errdoc if none was found
      See Also: