-
Notifications
You must be signed in to change notification settings - Fork 1
/
jolietraceviewer_service.ol
100 lines (84 loc) · 2.27 KB
/
jolietraceviewer_service.ol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from console import Console
from file import File
from string_utils import StringUtils
from runtime import Runtime
from protocols.http import DefaultOperationHttpRequest
from .frontend import Main as Frontend
constants {
// The default page to serve in case clients do not specify one
DefaultPage = "index.html",
// Print debug messages for all exchanged HTTP messages
DebugHttp = false,
// Add the content of every HTTP message to their debug messages
DebugHttpContent = false
}
interface HTTPInterface {
RequestResponse:
default(DefaultOperationHttpRequest)(undefined)
}
type Params {
location: string
wwwDir: string
}
service Main(params:Params) {
execution: concurrent
embed Frontend as Frontend
embed StringUtils as StringUtils
embed Console as Console
embed File as File
embed Runtime as Runtime
inputPort HTTPInput {
Protocol: http {
keepAlive = true // Keep connections open
debug = DebugHttp
debug.showContent = DebugHttpContent
format -> format
contentType -> mime
statusCode -> statusCode
default = "default"
}
Location: params.location
Interfaces: HTTPInterface
Aggregates: Frontend
}
init
{
if ( is_defined( args[0] ) ) {
documentRootDirectory = args[0]
} else {
documentRootDirectory = params.wwwDir
}
replaceAll@StringUtils( params.location { .regex="socket", .replacement="http"} )( http_location )
println@Console("Jolie Trace Viewer is running, open your browser and set the url " + http_location )()
}
main
{
[ default( request )( response ) {
scope( s ) {
install( FileNotFound => nullProcess; statusCode = 404 );
split@StringUtils( request.operation { .regex = "\\?" } )( s );
// Default page
shouldAddIndex = false;
if ( s.result[0] == "" ) {
shouldAddIndex = true
} else {
endsWith@StringUtils( s.result[0] { .suffix = "/" } )( shouldAddIndex )
};
if ( shouldAddIndex ) {
s.result[0] += DefaultPage
};
file.filename = documentRootDirectory + s.result[0];
getMimeType@File( file.filename )( mime );
mime.regex = "/";
split@StringUtils( mime )( s );
if ( s.result[0] == "text" ) {
file.format = "text";
format = "html"
} else {
file.format = format = "binary"
};
readFile@File( file )( response )
}
} ] { nullProcess }
}
}