/
serverxml.go
121 lines (103 loc) · 2.87 KB
/
serverxml.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package tomcat_info
import (
"encoding/xml"
"errors"
"os"
"github.com/jamesandariese/easy_error"
)
type Valve struct {
ClassName string `xml:"className,attr"`
Directory string `xml:"directory,attr"`
Prefix string `xml:"prefix,attr"`
Suffix string `xml:"suffix,attr"`
Pattern string `xml:"pattern,attr"`
ResolveHosts bool `xml:"resolveHosts,attr"`
}
type Host struct {
Valves []Valve `xml:"Valve"`
Name string `xml:"name,attr"`
AppBase string `xml:"appBase,attr"`
UnpackWars string `xml:"unpackWARs,attr"`
AutoDeploy string `xml:"autoDeploy,attr"`
}
type Realm struct {
Realms []Realm `xml:"Realm"`
ClassName string `xml:"className,attr"`
ResourceName string `xml:"resourceName,attr,omitempty"`
}
type Engine struct {
Realms []Realm `xml:"Realm"`
Hosts []Host `xml:"Host"`
Name string `xml:"name,attr"`
DefaultHost string `xml:"defaultHost,attr"`
}
type Connector struct {
Port int16 `xml:"port,attr"`
MaxThreads int32 `xml:"maxThreads,attr,omitempty"`
Protocol string `xml:"protocol,attr"`
RedirectPort int16 `xml:"redirectPort,attr"`
}
type Service struct {
Connectors []Connector `xml:"Connector"`
Engines []Engine `xml:"Engine"`
Name string `xml:"name,attr"`
}
type Resource struct {
Name string `xml:"name,attr"`
Auth string `xml:"auth,attr"`
Type string `xml:"type,attr"`
Description string `xml:"description,attr"`
Factory string `xml:"factory,attr"`
Pathname string `xml:"pathname,attr"`
}
type GlobalNamingResources struct {
Resources []Resource `xml:"Resource"`
}
type Listener struct {
ClassName string `xml:"className,attr"`
SslEngine string `xml:"SSLEngine,attr,omitempty"`
}
type Server struct {
Port int16 `xml:"port,attr"`
Shutdown string `xml:"shutdown,attr"`
Listeners []Listener `xml:"Listener"`
GlobalNamingResources GlobalNamingResources `xml:"GlobalNamingResources"`
Services []Service `xml:"Service"`
serverpath string // this is the path given to the reader.
}
var ErrServerHasNoPort = errors.New("No port is defined for HTTP/1.1")
func (server *Server) GetHttpPort() (port int16, err error) {
for _, service := range(server.Services) {
for _, connector := range(service.Connectors) {
switch connector.Protocol {
case "HTTP/1.1", "":
port = connector.Port
return
}
}
}
err = ErrServerHasNoPort
return
}
var ErrServerHasNoUserFile = errors.New("No user file is defined")
func (server *Server) GetUserFile() (path string, err error) {
for _, v := range(server.GlobalNamingResources.Resources) {
if v.Name == "UserDatabase" {
path = v.Pathname
return
}
}
err = ErrServerHasNoUserFile
return
}
func ReadServer(serverpath string) (server *Server, err error) {
defer func() {
err = easy_error.Apply(recover())
}()
file := easy_error.Wrap(os.Open(serverpath + "/conf/server.xml")).(*os.File)
decoder := xml.NewDecoder(file)
server = &Server{}
server.serverpath = serverpath
decoder.Decode(server)
return
}