public class HttpApplication extends Application
Application
that allows to execute operations
via REST-like services using HTTP protocol.Modifier and Type | Class and Description |
---|---|
static class |
HttpApplication.HttpApplicationAuthenticator
Authenticator for the
HTTP server
that provides a basic HTTP authentication based on the stored user/password
values. |
log
Constructor and Description |
---|
HttpApplication() |
Modifier and Type | Method and Description |
---|---|
boolean |
algorithmSelectInThread(java.io.PrintStream out,
java.lang.String... args)
Select algorithm to manage in current thread.
|
protected boolean |
controlFileExecuteMethod(java.io.PrintStream out,
java.util.Properties props,
java.lang.String actionName,
java.util.Map<java.lang.String,java.lang.String> variables,
java.util.List<java.lang.String> arguments)
This method reads and executes one action (with name actionName) from the control file (props).
|
static javax.net.ssl.SSLContext |
createHttpSSLContext(java.io.File keystoreFile,
java.io.File truststoreFile,
char[] password)
Creates a SSL context for handling HTTPS requests.
|
boolean |
httpAddContext(java.io.PrintStream out,
java.lang.String... args)
Adds a context to the HTTP server that is processed by the specified action.
|
boolean |
httpListContexts(java.io.PrintStream out,
java.lang.String... args)
List current contexts of the HTTP server.
|
boolean |
httpRemoveContext(java.io.PrintStream out,
java.lang.String... args)
Removes a context from the HTTP server.
|
boolean |
httpSetContextAuth(java.io.PrintStream out,
java.lang.String... args)
Updates a context auth to use HTTP Basic authentication mechanism.
|
static void |
main(java.lang.String[] args)
Start a MESSIF application with HTTP server.
|
protected boolean |
parseArguments(java.lang.String[] args,
int argIndex)
Internal method called from
main method
to read parameters and initialize the application. |
static java.util.Map<java.lang.String,java.lang.String> |
parseParameters(java.lang.String query,
java.util.Map<java.lang.String,java.lang.String> parameters)
Parse query string parameters.
|
boolean |
postDataTemporaryFileSuffix(java.io.PrintStream out,
java.lang.String... args)
Set the temporary file name suffix for the data sent to the HTTP service.
|
boolean |
quit(java.io.PrintStream out,
java.lang.String... args)
Exits this application.
|
protected java.lang.String |
usage()
Returns the command line arguments description.
|
rmiInfo, rmiInfoAll, rmiStart, rmiStop, rmiStopAll
algorithmRestore
addNamedInstance, algorithmInfo, algorithmInfoAll, algorithmSelect, algorithmSelectByName, algorithmStart, algorithmStop, algorithmStopAll, algorithmStore, algorithmSupportedOperations, algorithmToNamedInstance, collectGarbage, controlFile, controlFileExecuteAction, createCFActionRepeatEveryThread, currentTime, decode, echo, getCFActionArguments, getCFActionException, getCFActionForeach, getCFActionOutput, getCFActionRepeat, getCmdSocket, getExtendedNamedInstances, getNamedInstance, getRootCauseInvocationTargetException, help, logException, loggingConsoleChangeLevel, loggingFileAdd, loggingFileChangeLevel, loggingFileRemove, loggingLevel, memoryUsage, methodExecute, methodExecuteOnAlgorithm, namedInstanceAdd, namedInstanceConstructor, namedInstanceEcho, namedInstanceList, namedInstanceRemove, namedInstanceReplace, namedInstanceRestore, namedInstanceStore, namedInstanceThread, objectStreamClose, objectStreamConvert, objectStreamOpen, objectStreamReset, objectStreamSetParameter, objectStreamSkip, operationAnswer, operationAnswerRawObjects, operationArgument, operationBgExecute, operationErrorCode, operationExecute, operationExecuteAgain, operationChangeAnswerCollection, operationChangeAnswerNamedInstance, operationInfo, operationObjectCount, operationParam, operationParamProcessByMethod, operationPrepare, operationProcessByMethod, operationQueryObjectLocator, operationSubAnswer, postponeCFAction, processException, processInteractiveSocket, propertiesOpen, retrieveIntArgument, startApplication, statisticsDisable, statisticsGlobal, statisticsGlobalGet, statisticsLastOperation, statisticsResetGlobal, statisticsSetAutoBinding, stopRepeatEveryThread, substituteVariables, sum, waitForRepeatEveryThread
public boolean algorithmSelectInThread(java.io.PrintStream out, java.lang.String... args)
MESSIF >>> algorithmSelectInThread 0
out
- a stream where the application writes information for the userargs
- the algorithm sequence numberCoreApplication.algorithmInfoAll(java.io.PrintStream, java.lang.String...)
public boolean postDataTemporaryFileSuffix(java.io.PrintStream out, java.lang.String... args)
MESSIF >>> extractorTemporaryFileSuffix myfiles c:\temp tmp
out
- a stream where the application writes information for the userargs
- the temporary file prefix (if not specified, the feature is disabled),
the temporary file directory (optional, defaults to system wide temporary directory),
the temporary file suffix (optional, defaults to "tmp")public boolean httpAddContext(java.io.PrintStream out, java.lang.String... args)
CoreApplication.namedInstanceAdd(java.io.PrintStream, java.lang.String[])
).
The "data" is a new name for a named instance that will get the extracted data in each
context call by passing the request input stream and the passed arguments to the extractor
as ExtractorDataSource
. Note that the new named instance is a InheritableThreadLocal
value, so it is safe in multi-threaded HTTP servers.
Optionally, additional arguments specifying the content-type (defaults to "text/plain"),
and charset (defaults to "utf-8") can be specified.
Example of usage:
MESSIF >>> httpAddContext myfile.cf /search my_search extracted_data=extractorThis will create a HTTP context that will execute the "my_search" action in "myfile.cf" and the named instance "extracted_data" will contain the data extracted by the named instances "extractor" from the respective HTTP request.
out
- a stream where the application writes information for the userargs
- the control file (only if not called from a control file), the context path, the action name to call, the map of context extractors, the content type of the output, and the charset of the outputpublic boolean httpRemoveContext(java.io.PrintStream out, java.lang.String... args)
Example of usage:
MESSIF >>> httpRemoveContext /search
out
- a stream where the application writes information for the userargs
- the context path to removepublic boolean httpListContexts(java.io.PrintStream out, java.lang.String... args)
Example of usage:
MESSIF >>> httpListContexts
out
- a stream where the application writes information for the userargs
- nonepublic boolean httpSetContextAuth(java.io.PrintStream out, java.lang.String... args)
Example of usage:
MESSIF >>> httpSetContextAuth /search myuser mypassword
out
- a stream where the application writes information for the userargs
- the context path for which to set auth, the user name and the password (optional, if not set, the user is removed)public boolean quit(java.io.PrintStream out, java.lang.String... args)
CoreApplication
Example of usage:
MESSIF >>> quit
quit
in class CoreApplication
out
- a stream where the application writes information for the userargs
- this method has no argumentsprotected boolean controlFileExecuteMethod(java.io.PrintStream out, java.util.Properties props, java.lang.String actionName, java.util.Map<java.lang.String,java.lang.String> variables, java.util.List<java.lang.String> arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
CoreApplication
CoreApplication
.controlFileExecuteMethod
in class CoreApplication
out
- the stream to write the output toprops
- the properties with actionsactionName
- the name of the action to executevariables
- the current variables environmentarguments
- the list of arguments parsed from the configuration filejava.lang.NoSuchMethodException
- if there was no method for the given actionjava.lang.reflect.InvocationTargetException
- if there was an error executing the action while the throwException
is trueprotected java.lang.String usage()
CoreApplication
usage
in class DistributedApplication
protected boolean parseArguments(java.lang.String[] args, int argIndex)
CoreApplication
main
method
to read parameters and initialize the application.parseArguments
in class DistributedApplication
args
- the command line argumentsargIndex
- the index of the argument where to startpublic static void main(java.lang.String[] args)
args
- the command line argumentspublic static java.util.Map<java.lang.String,java.lang.String> parseParameters(java.lang.String query, java.util.Map<java.lang.String,java.lang.String> parameters)
name1=value1&name2=value2&...
Note that the query string can be get by
HttpExchange.getRequestURI()
.getQuery()
.query
- the string with URI-like query parametersparameters
- an existing hash map to add the parsed parameters to or nullpublic static javax.net.ssl.SSLContext createHttpSSLContext(java.io.File keystoreFile, java.io.File truststoreFile, char[] password) throws java.lang.Exception
keytool -genkey -alias alias -keypass my_password -storepass my_password -keystore my_keystore_file
keystoreFile
- the key store file with the authentication keystruststoreFile
- the key store file with the peer authentication trust decisionspassword
- the password to unlock the key stores and private keyjava.lang.Exception
- if there was an error creating the SSL context (missing cryptography engines, protocols, etc.)