Class AhcWSClient

java.lang.Object
play.libs.ws.ahc.AhcWSClient
All Implemented Interfaces:
Closeable, AutoCloseable, WSClient

public class AhcWSClient extends Object implements WSClient
A WS client backed by AsyncHttpClient implementation.

See https://www.playframework.com/documentation/latest/JavaWS for documentation.

  • Constructor Summary

    Constructors
    Constructor
    Description
    AhcWSClient(play.libs.ws.ahc.StandaloneAhcWSClient client, Materializer materializer)
     
    AhcWSClient(play.shaded.ahc.org.asynchttpclient.AsyncHttpClient client, Materializer materializer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    play.api.libs.ws.WSClient
     
    void
    Closes this client, and releases underlying resources.
    create(play.api.libs.ws.ahc.AhcWSClientConfig config, play.api.libs.ws.ahc.cache.AhcHttpCache cache, Materializer materializer)
    Creates WS client manually from configuration, internally creating a new instance of AsyncHttpClient and managing its own thread pool.
    play.libs.ws.StandaloneWSClient
    Return the implementation interface of StandaloneAhcWSClient.
    The underlying implementation of the client, if any.
    url(String url)
    Returns a WSRequest object representing the URL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AhcWSClient

      public AhcWSClient(play.shaded.ahc.org.asynchttpclient.AsyncHttpClient client, Materializer materializer)
    • AhcWSClient

      @Inject public AhcWSClient(play.libs.ws.ahc.StandaloneAhcWSClient client, Materializer materializer)
  • Method Details

    • create

      public static AhcWSClient create(play.api.libs.ws.ahc.AhcWSClientConfig config, play.api.libs.ws.ahc.cache.AhcHttpCache cache, Materializer materializer)
      Creates WS client manually from configuration, internally creating a new instance of AsyncHttpClient and managing its own thread pool.

      This client is not managed as part of Play's lifecycle, and must be closed by calling ws.close(), otherwise you will run into memory leaks.

      Parameters:
      config - a config object, usually from AhcWSClientConfigFactory
      cache - if not null, provides HTTP caching.
      materializer - an Pekko materializer
      Returns:
      a new instance of AhcWSClient.
    • getUnderlying

      public Object getUnderlying()
      Description copied from interface: WSClient
      The underlying implementation of the client, if any. You must cast the returned value to the type you want.
      Specified by:
      getUnderlying in interface WSClient
      Returns:
      the backing object.
    • asScala

      public play.api.libs.ws.WSClient asScala()
      Specified by:
      asScala in interface WSClient
      Returns:
      the Scala version for this WSClient.
    • url

      public WSRequest url(String url)
      Description copied from interface: WSClient
      Returns a WSRequest object representing the URL. You can append additional properties on the WSRequest by chaining calls, and execute the request to return an asynchronous Promise<WSResponse>.
      Specified by:
      url in interface WSClient
      Parameters:
      url - the URL to request
      Returns:
      the request
    • close

      public void close() throws IOException
      Description copied from interface: WSClient
      Closes this client, and releases underlying resources.

      Use this for manually instantiated clients.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface WSClient
      Throws:
      IOException
    • getStandaloneWSClient

      public play.libs.ws.StandaloneWSClient getStandaloneWSClient()
      Return the implementation interface of StandaloneAhcWSClient.
      Returns:
      StandaloneWSClient