-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathWebUIServletContext.java
More file actions
104 lines (87 loc) · 2.46 KB
/
Copy pathWebUIServletContext.java
File metadata and controls
104 lines (87 loc) · 2.46 KB
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
package javaforce.webui;
import java.io.*;
import java.lang.reflect.*;
import javaforce.*;
/** WebUIServletContext.
*
* Server-side context.
*
* @author pquiring
*/
public class WebUIServletContext {
private JFClassLoader loader;
private Object servlet;
private Method init;
private Method destroy;
private Method getName;
private Object server;
private Method startServlet;
private Method stopServlet;
private Method connectServlet;
public WebUIServletContext(JFClassLoader loader, Object servlet) {
this.loader = loader;
this.servlet = servlet;
try {
Class<?> servlet_cls = loader.findClass("javaforce.webui.WebUIServlet");
init = servlet_cls.getMethod("init");
destroy = servlet_cls.getMethod("destroy");
getName = servlet_cls.getMethod("getName");
Class<?> server_cls = loader.findClass("javaforce.webui.WebUIServer");
Constructor<?> server_ctor = server_cls.getConstructor();
server = server_ctor.newInstance();
startServlet = server_cls.getMethod("startServlet", servlet_cls);
stopServlet = server_cls.getMethod("stopServlet");
connectServlet = server_cls.getMethod("connectServlet", String.class, String.class, InputStream.class, OutputStream.class, String.class, String.class, String[].class);
} catch (Exception e) {
JFLog.log(e);
}
}
public JFClassLoader getClassLoader() {
return loader;
}
//start WebUIServer within Servlet context
public void startServlet() {
try {
startServlet.invoke(server, servlet);
} catch (Exception e) {
JFLog.log(e);
}
}
//stop WebUIServer within Servlet context
public void stopServlet() {
try {
stopServlet.invoke(server);
} catch (Exception e) {
JFLog.log(e);
}
}
public void connectServlet(String server_host, String client_host, InputStream is, OutputStream os, String host, String url, String[] cookies) {
try {
connectServlet.invoke(server, server_host, client_host, is, os, host, url, cookies);
} catch (Exception e) {
JFLog.log(e);
}
}
public void init() {
try {
init.invoke(servlet);
} catch (Exception e) {
JFLog.log(e);
}
}
public void destroy() {
try {
destroy.invoke(servlet);
} catch (Exception e) {
JFLog.log(e);
}
}
public String getName() {
try {
return (String)getName.invoke(servlet);
} catch (Exception e) {
JFLog.log(e);
return null;
}
}
}