-
Notifications
You must be signed in to change notification settings - Fork 9
gServ Standalone
###gServ may be used as a standalone HTTP server to serve static content as well as REST resources written as Groovy scripts ##Requirements Java 1.6+ on the PATH
##Install Copy the contents of dist folder on GitHub to a local folder. Add that folder to your PATH.
##Verify installation type 'gserv' at the prompt
This should print the gServ options to the console.
Here we serve static content from the /public folder on port 12000. prompt> gserv -s /public -p 12000
GServ may be used to serve static content along with dynamic REST resources
prompt> gserv -s /public -r Math.groovy -p 12000The content of Math.groovy:
[Resource("/math"){
get "/", {
write "text/plain", "Welcome to our GServ Math example"
}
get "/:num1/:num2/:operation", { num1, num2, operation ->
def ans = 0
def msg = ""
switch ( operation ){
case "add" : ans = (num1 as int) + (num2 as int);
case "subtract" : ans = (num1 as int) - (num2 as int);
case "multiply" : ans = (num1 as int) * (num2 as int);
case "divide" : ans = (num1 as double) / (num2 as double);
msg = "$operation($num1, $num2) = $ans"
default:
msg = "Operation: $operation is not supported";
}
write "text/plain", msg
}
}]
##GServ Commandline Options
| Option | Meaning |
|---|---|
| -s | Static Content Folder |
| -a | The address to which to listen. Only requests for this particular IP address will be fullfiled. |
Example: gserv -s /public -a 192.166.2.33 -p 12000 |
|
| -p | The port on which to listen. |
Example: gserv -s /public -p 12000 |
|
| -i | GServ Instance Script |
| -n | Name of the application |
| -d | Default Resource |
| --no-status-page | Disables the status page. |
| --status-path | Path to use for the status page. |
| -v | Prints the current gServ version |
| -r | GServ Resource Scripts (separated by commas) |
| --classpath | Classpath (list of Jars separated by commas) |
Example: gserv -s /public -r This.groovy,That.groovy -j This.jar,That.jar |
|
| -c | GServ Config file name |
| -x | Sets the number of threads to use for request processing. Default: Number of processors on system + 1 |
##GServ Deployment Configuration File
Gserv Config files are JSON files describing the appications to deploy. The main elements are: https, plugin, apps, classpath.
https - optional. element containing SSL information
plugins - optional. element containing plugins to register
apps - array element containing application configs for each instance to be deployed
classpath - optional. list of jar files with application dependencies
Below is an example configuration file:{
"https":{
"keyManagerAlgorithm": "SunX509",
"trustManagerAlgorithm": "SunX509",
"keystoreFilePath": "/Users/javaConductor/gserv.keystore",
"keyStoreImplementation": "JKS",
"password": "secretStuff",
"sslProtocol" : "TLS"
},
"plugins": {
"myPlugin": "thirdparty.plugins.MyPlugin"
},
"apps" : [{
"https": false,
"name" : "singlePageMath",
"resourceScripts" : ["resources/Resource1.groovy",
"resources/Resource2.groovy"],
"port" : 11111,
"bindAddress": "127.0.0.1",
"static_roots" : [ "/Users/javaConductor/public" ]
},{
"https": true,
"name" : "singlePageMath2",
"resourceScripts" : ["resources/Resource2.groovy"],
"port" : 11112,
"bindAddress": 127.0.0.1,
"static_roots" : [ "/Users/javaConductor/public" ]
}],
"classpath" : ["/apps/lib/service1.jar","/apps/lib/service2.jar"]
}
gServ © 2014-2017 Lee Collins. All rights reserved.