URL handling in SAMP message parameters
Mark Taylor
m.b.taylor at bristol.ac.uk
Fri Oct 7 02:04:03 PDT 2011
Laurent,
On Fri, 7 Oct 2011, Laurent Bourgès wrote:
> Dear Samp users,
>
> In several standard MTypes, arguments can be url (string) giving the
> URL of the document to load :
> - table.load.votable
> - table.load.fits
> - table.highlight.row
> - table.select.rowList
> - image.load.fits
> - spectrum.load.ssa-generic
> - voresource.loadlist
>
> Although SAMP is dedicated to desktop interoperability, such URL can
> use any protocol (file://, http://, ftp://).
> To be concrete, I am currently using JSAMP 1.3 and I must handle both
> 'file://' and 'http://' URL when I process one table.load.votable
> message:
> - 'file://' are provided by our JMMC applications: data are stored
> into local files before sending their URL via SAMP
> - 'http://' are provided by topcat because it embeds its own HTTP server
>
> Two questions :
> - Is it possible to describe which URL procotols must be supported by
> SAMP clients (file, http at least) ? I do not want to support other
> protocols (ftp ...) : the specification / MType wiki page should give
> explanations / details
Although in principle this is a legitimate concern, it hasn't come
up before, I guess because most languages/environments in which
people are receiving SAMP messages provide some ready-made machinery
for retrieving data from URLs with a minimum of programmer effort.
So in practice the list of legitimate URL types is the common set
of protocols handled by common SAMP language platforms - for Java
it is (I think) http, https, ftp and file; I expect it's similar
for Python. I expect that nearly all URLs actually sent by
SAMP tools are http or file; there may be the odd https or ftp.
> - Is it possible to provide in SAMP implementations (JSAMP, Sampy ...)
> an easy API to deal with such URL like getDocument(URL url) ?
It's not provided as part of JSAMP, because it comes for free with
Java, in the java.net.URL class:
InputStream in = new URL(urlString).openStream();
allows you to read the resource of a URL without worrying about
whether it's http, https, ftp or file protcol. I'm pretty sure
python, C# and pretty much any other modern language or language+library
platform can provide something similar.
> I think it is boring and error prone that every application developer
> must handle all URL protocols on its own although he only needs to get
> the document itself. I know it is not so difficult but error handling
> can become tricky (http errors ...)
it would be! But the same thing comes up in many situations other
than SAMP, which is why library support to address it is widespread.
Mark
--
Mark Taylor Astronomical Programmer Physics, Bristol University, UK
m.b.taylor at bris.ac.uk +44-117-928-8776 http://www.star.bris.ac.uk/~mbt/
More information about the apps-samp
mailing list