Package play.libs

Class WS

  • All Implemented Interfaces:
    java.lang.Comparable<PlayPlugin>

    public class WS
    extends PlayPlugin
    Simple HTTP client to make webservices requests.

    Get latest BBC World news as a RSS content

     HttpResponse response = WS.url("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml").get();
     Document xmldoc = response.getXml();
     // the real pain begins here...
     

    Search what Yahoo! thinks of google (starting from the 30th result).

     HttpResponse response = WS.url("http://search.yahoo.com/search?p=%s&pstart=1&b=%s", "Google killed me", "30").get();
     if (response.getStatus() == 200) {
         html = response.getString();
     }
     
    • Constructor Detail

      • WS

        public WS()
    • Method Detail

      • withEncoding

        public static WS.WSWithEncoding withEncoding​(java.lang.String encoding)
        Use thos method to get an instance to WS with diferent encoding
        Parameters:
        encoding - the encoding to use in the communication
        Returns:
        a new instance of WS with specified encoding
      • onApplicationStop

        public void onApplicationStop()
        Description copied from class: PlayPlugin
        Called at application stop (and before each reloading) Time to shutdown stateful things.
        Overrides:
        onApplicationStop in class PlayPlugin
      • onApplicationStart

        public void onApplicationStart()
        Description copied from class: PlayPlugin
        Called at application start (and at each reloading) Time to start stateful things.
        Overrides:
        onApplicationStart in class PlayPlugin
      • encode

        public static java.lang.String encode​(java.lang.String part)
        URL-encode a string to be used as a query string parameter.
        Parameters:
        part - string to encode
        Returns:
        url-encoded string
      • url

        public static WS.WSRequest url​(java.lang.String url)
        Build a WebService Request with the given URL. This object support chaining style programming for adding params, file, headers to requests.
        Parameters:
        url - of the request
        Returns:
        a WSRequest on which you can add params, file headers using a chaining style programming.
      • url

        public static WS.WSRequest url​(java.lang.String url,
                                       java.lang.String... params)
        Build a WebService Request with the given URL. This constructor will format url using params passed in arguments. This object support chaining style programming for adding params, file, headers to requests.
        Parameters:
        url - to format using the given params.
        params - the params passed to format the URL.
        Returns:
        a WSRequest on which you can add params, file headers using a chaining style programming.