Groovy Documentation

org.linkedin.groovy.util.net
[Groovy] Class GroovyNetUtils

java.lang.Object
  org.linkedin.groovy.util.net.GroovyNetUtils

class GroovyNetUtils

Contains utilities for net

Authors:
ypujante@linkedin.com


Method Summary
static java.lang.String guessFilename(java.net.URI uri)

Method which tries to infer the filename from the uri.

static java.net.URI toURI(java.lang.Object s)

Converts the provided parameter into a URI... handle: File, strings, URI, URL, null

static java.net.URL toURL(java.lang.Object s)

Encapsulates the creation of a URL by first trying the normal way and if it fails, it falls back to the SingletonURLStreamHandlerFactory

static java.lang.Object withHttpEchoServer(groovy.lang.Closure closure)

Equivalent to call withHttpEchoServer(int, Closure) with 0 for the port

static java.lang.Object withHttpEchoServer(int port, groovy.lang.Closure closure)

Create a simple http server on localhost on the given port for the duration of the closure.

static java.lang.Object withHttpServer(int port, java.util.Map handlers, groovy.lang.Closure closure)

Create a simple http server on localhost on the given port for the duration of the closure.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

guessFilename

static java.lang.String guessFilename(java.net.URI uri)
Method which tries to infer the filename from the uri.


toURI

static java.net.URI toURI(java.lang.Object s)
Converts the provided parameter into a URI... handle: File, strings, URI, URL, null


toURL

static java.net.URL toURL(java.lang.Object s)
Encapsulates the creation of a URL by first trying the normal way and if it fails, it falls back to the SingletonURLStreamHandlerFactory
Returns:
the url


withHttpEchoServer

static java.lang.Object withHttpEchoServer(groovy.lang.Closure closure)
Equivalent to call withHttpEchoServer(int, Closure) with 0 for the port


withHttpEchoServer

static java.lang.Object withHttpEchoServer(int port, groovy.lang.Closure closure)
Create a simple http server on localhost on the given port for the duration of the closure. The server will respond to http://localhost:/echo?msg=xxxx by returning xxxx. This is mostly used for testing purposes!
Parameters:
port - the port on which to bind the server (0 means pick an ephemeral port)
closure - code to execute while the echo server is up and running. Parameter to the closure = port bound
Returns:
whatever the closure returns


withHttpServer

static java.lang.Object withHttpServer(int port, java.util.Map handlers, groovy.lang.Closure closure)
Create a simple http server on localhost on the given port for the duration of the closure.
Parameters:
port - the port on which to bind the server (0 means pick an ephemeral port)
handlers - a map of path (ex: /echo) to handler (a closure or an instance of HttpHandler)
closure - code to execute while the echo server is up and running. Parameter to the closure = port bound
Returns:
whatever the closure returns


 

Groovy Documentation