forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpHttpScriptContext.java
More file actions
92 lines (72 loc) · 2.27 KB
/
Copy pathPhpHttpScriptContext.java
File metadata and controls
92 lines (72 loc) · 2.27 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
/*-*- mode: Java; tab-width:8 -*-*/
package php.java.script.http;
import java.io.IOException;
import java.io.Writer;
import java.util.Hashtable;
import javax.script.http.HttpScriptContext;
import javax.script.http.SimpleHttpScriptContext;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import php.java.bridge.DynamicJavaBridgeClassLoader;
import php.java.bridge.JavaBridge;
import php.java.bridge.JavaBridgeClassLoader;
import php.java.bridge.SessionFactory;
import php.java.bridge.Util;
import php.java.servlet.ContextManager;
import php.java.servlet.PhpJavaServlet;
public class PhpHttpScriptContext extends SimpleHttpScriptContext {
static {
DynamicJavaBridgeClassLoader.initClassLoader(Util.EXTENSION_DIR);
}
private Hashtable env;
private ContextManager ctx;
/**
* @return Returns the context.
*/
public ContextManager getContext() {
return ctx;
}
public void release() {
super.release();
ctx.remove();
}
public Writer getWriter() {
try {
return getResponse().getWriter();
} catch (IOException e) {
return null;
}
}
public HttpServletResponse getResponse() {
return new PhpHttpScriptResponse(this, response);
}
public void initialize(Servlet servlet, HttpServletRequest req,
HttpServletResponse res) throws ServletException {
super.initialize(servlet, req, res);
env = new Hashtable();
/* send the session context now, otherwise the client has to
* call handleRedirectConnection */
this.env.put("X_JAVABRIDGE_CONTEXT", ctx.getId());
/* the client should connect back to us */
this.env.put("X_JAVABRIDGE_CONTINUATION", String.valueOf(HttpScriptContext.REQUEST_SCOPE));
ctx = PhpHttpScriptContextManager.addNew(this, req, res);
JavaBridge bridge = new JavaBridge();
ctx.setBridge(bridge);
bridge.setClassLoader(new JavaBridgeClassLoader(ctx.getBridge(), DynamicJavaBridgeClassLoader.newInstance(PhpJavaServlet.class.getClassLoader())));
bridge.setSessionFactory(ctx);
}
/**
* @return
*/
public Hashtable getEnvironment() {
return env;
}
/**
* @return
*/
public SessionFactory getContextManager() {
return ctx;
}
}