01: package de.schlund.pfixxml.testrecording;
02:
03: import java.io.Serializable;
04: import java.net.MalformedURLException;
05: import java.net.URL;
06:
07: /**
08: * Pustefix application running on a given tomcat.
09: * Note that https is not a property of an application because the same application
10: * may run secure and insecure.
11: */
12: public class Application implements Serializable {
13: private final String name;
14: private final String server;
15: private final boolean tomcat;
16: private final String startPath;
17: private final String sessionSuffix;
18:
19: private static final long serialVersionUID = 6157375568733984286L;
20:
21: public Application(String name, String server, boolean tomcat,
22: String startPath, String sessionSuffix) {
23: if (server.indexOf('/') != -1) {
24: throw new IllegalArgumentException(server);
25: }
26: if (!startPath.startsWith("/") || startPath.endsWith("/")) {
27: throw new IllegalArgumentException(startPath);
28: }
29: this .name = name;
30: this .server = server;
31: this .tomcat = tomcat;
32: this .startPath = startPath;
33: this .sessionSuffix = sessionSuffix;
34: }
35:
36: public Application() {
37: throw new IllegalStateException("TODO: castor");
38: }
39:
40: /** server as stored in session */
41: public String getServer() {
42: return server;
43: }
44:
45: public String getStartPath() {
46: return startPath;
47: }
48:
49: public URL getUrl(boolean https, String path) {
50: return getUrl(https, path, "nosuchsession." + sessionSuffix);
51: }
52:
53: public URL getUrl(boolean https, String path, String sessionId) {
54: String protocol;
55: String port;
56:
57: if (!path.startsWith("/") || path.endsWith("/")) {
58: throw new IllegalArgumentException("invalid path: " + path);
59: }
60: if (https) {
61: protocol = "https";
62: } else {
63: protocol = "http";
64: }
65: if (tomcat) {
66: port = https ? ":8443" : ":8080";
67: } else {
68: port = "";
69: }
70: try {
71: return new URL(protocol + "://" + server + port + path
72: + ";jsessionid=" + sessionId);
73: } catch (MalformedURLException e) {
74: throw new RuntimeException("TODO", e);
75: }
76: }
77:
78: public String getName() {
79: return name;
80: }
81:
82: public String toString() {
83: return "application(name=" + name + ", tomcat=" + tomcat
84: + ", server=" + server + ")";
85: }
86: }
|