Java Reference
In-Depth Information
Note also that this is a case where the parentheses (on the join method) are needed. In
Groovy,ifyouleaveofftheparentheseswhencallingamethodwithnoargumentsthecom-
piler assumes you are asking for the corresponding getter or setter method. Because I want
the join() method (and not getJoin() , which doesn't exist), I need the parentheses.
2.2.2. Transmitting the URL
The Groovy JDK adds the toURL() method to the String class. As you might imagine,
this method converts an instance of java.lang.String into an instance of
java.net.URL .
The Groovy JDK
Groovy adds many helpful methods to existing Java library classes. Many, many times I've
foundmethods added to, say, String , Date ,or Collection that Ialways wished were
in Java all along. The set of methods added by Groovy is known as the Groovy JDK and
has its own set of JavaDocs. The Groovy JDK documentation is available via a link from
the Groovy home page.
The Groovy JDK is discussed in more detail in chapter 3 .
To send an HTTP GET request to a URL and retrieve the results, convert the string
to a URL and invoke another Groovy JDK method, the getText() method, added to
java.net.URL . In other words, the data on a web page can be retrieved from this code:
url.toURL().text
Here I'm deliberately using the text property of the URL class, knowing that the effect
will be to invoke the getText() method . There's nothing wrong with actually calling
getText , but this is more idiomatic Groovy.
Normally this would be exactly the code I want, and I use this technique in some of the
examples in the chapters on web services, but in this particular case the result isn't text.
Search WWH ::




Custom Search