org.autoplot.hapiserver.Util
helpful functions.
Util( )
HAPI_SERVER_HOME_PROPERTY
This should point to the name of the directory containing HAPI configuration.
This directory should contain catalog.json, capabilities.json and a
subdirectory "info" which contains files with the name <ID>.json,
each containing the info response. Note these should also contain a
tag "x_uri" which is the Autoplot URI that serves this data.
csvSplit
csvSplit( String line, int nf ) → String[]
split, but not when comma is within quotes.
Parameters
line - for example 'a,b,"c,d"'
nf - number of fields, or -1 for no constraint
Returns:
['a','b','c,d']
[search for examples]
[view on GitHub]
[view on old javadoc]
fileSystemSafeName
fileSystemSafeName( String s ) → String
convert IDs and NAMEs into safe names which will work on all platforms.
If the name is modified, it will start with an underscore (_).
poolTemperature -> poolTemperature
Iowa City Conditions -> _Iowa+City+Conditions
Parameters
s - a String
Returns:
a String
[search for examples]
[view on GitHub]
[view on old javadoc]
getDurationForHumans
getDurationForHumans( long dt ) → String
return the duration in a easily-human-consumable form.
Parameters
dt - the duration in milliseconds.
Returns:
a duration like "2.6 hours"
[search for examples]
[view on GitHub]
[view on old javadoc]
getHapiHome
getHapiHome( ) → File
return the root of the HAPI server.
Returns:
the root of the HAPI server.
[search for examples]
[view on GitHub]
[view on old javadoc]
getNumberOfElements
getNumberOfElements( JSONObject info ) → int[]
return the total number of elements of each parameter.
Parameters
info - the info
Returns:
an int array with the number of elements in each parameter.
[search for examples]
[view on GitHub]
[view on old javadoc]
hapiVersion
hapiVersion( ) → String
return the HAPI protocol version.
Returns:
the HAPI protocol version.
[search for examples]
[view on GitHub]
[view on old javadoc]
isTrustedClient
isTrustedClient( HttpServletRequest request ) → boolean
return true if the client is trusted and additional information about
the server for debugging can be included in the response.
Parameters
request - a HttpServletRequest
Returns:
a boolean
[search for examples]
[view on GitHub]
[view on old javadoc]
main
main( java.lang.String[][] args ) → void
Parameters
args - a java.lang.String[]
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
maybeInitialize
maybeInitialize( ServletContext context ) → void
if HAPI_HOME has not been set, then set it.
Parameters
context - a ServletContext
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
raiseBadId
raiseBadId( String id, HttpServletResponse response, java.io.PrintWriter out ) → void
send a "bad id" response to the client.
Parameters
id - the id.
response - the response object
out - the print writer for the response object.
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
raiseMisconfiguration
raiseMisconfiguration( String id, java.lang.Exception ex, HttpServletResponse response, java.io.PrintWriter out ) → void
send a "bad id" response to the client.
Parameters
id - the id.
ex - an exception
response - the response object
out - the print writer for the response object.
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
serverVersion
serverVersion( ) → String
return the server implementation version.
Returns:
the server implementation version.
[search for examples]
[view on GitHub]
[view on old javadoc]
setHapiHome
setHapiHome( java.io.File f ) → void
Parameters
f - a File
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
subsetParams
subsetParams( JSONObject info, String parameters ) → JSONObject
return a new JSONObject for the info request, with the subset of parameters.
Parameters
info - the root node of the info response.
parameters - comma-delimited list of parameters.
Returns:
the new JSONObject, with special tag __indexmap__ showing which columns are to be included in a data response.
[search for examples]
[view on GitHub]
[view on old javadoc]
transfer
transfer( java.io.InputStream src, java.io.OutputStream dest ) → void
transfers the data from one channel to another. src and dest are
closed after the operation is complete.
Parameters
src - an InputStream
dest - an OutputStream
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
trimUTF8
trimUTF8( byte[][] bytes, int k ) → byte[]
properly trim the byte array containing a UTF-8 String to a limit
Parameters
bytes - the bytes
k - the number of bytes
Returns:
a byte[][]
[search for examples]
[view on GitHub]
[view on old javadoc]
validateJSON
validateJSON( String json ) → boolean
return true if this is valid JSON, false otherwise, and log the exception at SEVERE.
Parameters
json - a String
Returns:
a boolean
[search for examples]
[view on GitHub]
[view on old javadoc]