Class ClientProxySelector

  • All Implemented Interfaces:
    AutoCloseable

    public class ClientProxySelector
    extends ProxySelector
    implements AutoCloseable
    An instance of ClientProxySelector initializes a custom proxy selector, that prepares proxy settings for webPDF calls. It shall fall back to the default proxy selector, when a processed URI is not pointing to a webPDF endpoint. It will restore the previously set proxy selector, when closed. The default proxy selector shall also be used as a fallback, when a resource path shall be routed, that is not based on one of the given routedResources.
    • Constructor Detail

      • ClientProxySelector

        public ClientProxySelector​(@NotNull
                                   @NotNull URI[] routedResources,
                                   @NotNull
                                   @NotNull org.apache.hc.core5.http.HttpHost... proxies)
        Initializes a custom proxy selector, that prepares proxy settings for webPDF calls. It shall fall back to the default proxy selector, when a processed URI is not pointing to a webPDF endpoint. It will restore the previously set proxy selector, when closed. The default proxy selector shall also be used as a fallback, when a resource path shall be routed, that is not based on one of the given routedResources.
        Parameters:
        proxies - The proxy server hosts, that shall be used.
        routedResources - A list of all base URIs, that shall be routed via this selector. All URIs a proxy is requested for, shall start with one of the hereby given URIs.
    • Method Detail

      • addProxy

        public void addProxy​(@NotNull
                             @NotNull org.apache.hc.core5.http.HttpHost proxy)
        Adds the given proxy to the list of usable proxy servers.
        Parameters:
        proxy - A proxy server, that shall be used.
      • addRoutedResource

        public void addRoutedResource​(URI routedResource)
        Adds the given URI to the list of URIs, that must be resolved using a proxy route from this selector. All URIs a proxy shall be requested for, will be routed, if they start with one of the hereby configured URIs. (otherwise a default selector shall be used instead.)
        Parameters:
        routedResource - The URI, that shall be routed via this selector.
      • select

        @NotNull
        public @NotNull List<Proxy> select​(@Nullable
                                           @Nullable URI uri)
        Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at. The format of the URI is defined as follows:
        • http URI for http connections
        • https URI for https connections
        • socket://host:port
          for tcp client sockets connections

        If the URI does not point to a routed resource, the previously known default proxy selector shall be used, to select the proxies.

        Specified by:
        select in class ProxySelector
        Parameters:
        uri - The URI that a connection is required to.
        Returns:
        A List of Proxies. Each element in the List is of type Proxy; when no proxy is available, the list will contain one element of type Proxy that represents a direct connection.
        Throws:
        IllegalArgumentException - if the argument is null.
      • connectFailed

        public void connectFailed​(@Nullable
                                  @Nullable URI uri,
                                  @Nullable
                                  @Nullable SocketAddress socketAddress,
                                  @Nullable
                                  @Nullable IOException exception)
        Called to indicate that a connection could not be established to a proxy/socks server. An implementation of this method can temporarily remove the proxies or reorder the sequence of proxies returned by select(URI), using the address and the IOException caught when trying to connect.
        Specified by:
        connectFailed in class ProxySelector
        Parameters:
        uri - The URI that a connection could not be established to.
        socketAddress - The SocketAddress of the proxy/SOCKS server
        exception - The IOException, that shall be thrown when a connection attempt fails.
        Throws:
        IllegalArgumentException - Shall be thrown, when either argument is null.
      • close

        public void close()
        Restores the previously found proxy selector as the VM's default.
        Specified by:
        close in interface AutoCloseable