Tuesday, April 14, 2009

Groovy: No signature of method: java.lang.String.call()

Exception: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types:

The first time I ran into this, took some time to figure out. Maybe because I haven't got used to this dynamic language.


def sendMail(mailhost, port, from, to) {
ant.mail(mailhost:"${mailhostname}", mailport:"${port}", subject:'Test Email') {
from( address:"${from}" )
to( address:"${to}" )
message(msg)
}
}


Code above will throw this exception, because groovy will use input parameter "from" and "to" to evaluate from, to function ant.mail closure.

Change to a different name.

Tuesday, April 7, 2009

HTTP keep-alive

Working on a download manager. If the download manager is generic to just work with any download url, how could it handle the download which requires user to login or accept some agreements/terms? Inside browser, such as FF's download manager, it will work since the cookie is sent each time to server.

1. Keep-alive (default 300 seconds) will make the URL still work for 5 mins. But after that, it will need cookie to make download work.
2. If resuming download from middle of the file, i.e. bytes=(value > 0), then the download works fine. The server only validates the download request for the initial request starting from byte 0. This makes sense. It will make resuming download still works since it's already authenticated.