play.libs
Class WS

java.lang.Object
  extended by play.PlayPlugin
      extended by play.libs.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

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

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

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


Nested Class Summary
static class WS.FileParam
           
static class WS.HttpResponse
          An HTTP response wrapper
static interface WS.WSImpl
           
static class WS.WSRequest
           
 
Field Summary
 
Fields inherited from class play.PlayPlugin
index
 
Constructor Summary
WS()
           
 
Method Summary
static java.lang.String encode(java.lang.String part)
          URL-encode an UTF-8 string to be used as a query string parameter.
 void onApplicationStop()
          Called at application stop (and before each reloading) Time to shutdown statefull things.
static WS.WSRequest url(java.lang.String url)
          Build a WebService Request with the given URL.
static WS.WSRequest url(java.lang.String url, java.lang.String... params)
          Build a WebService Request with the given URL.
 
Methods inherited from class play.PlayPlugin
addTemplateExtensions, afterActionInvocation, afterApplicationStart, afterFixtureLoad, afterInvocation, beforeActionInvocation, beforeDetectingChanges, beforeInvocation, bind, bind, compareTo, compileAll, detectChange, enhance, getJsonStatus, getStatus, invocationFinally, loadTemplate, modelFactory, onActionInvocationResult, onApplicationReady, onApplicationStart, onClassesChange, onConfigurationRead, onEvent, onInvocationException, onInvocationSuccess, onLoad, onRequestRouting, onRoutesLoaded, onTemplateCompilation, postEvent, rawInvocation, routeRequest, runTest, serveStatic
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WS

public WS()
Method Detail

onApplicationStop

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

Overrides:
onApplicationStop in class PlayPlugin

encode

public static java.lang.String encode(java.lang.String part)
URL-encode an UTF-8 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.


Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly