Menu

[r667]: / trunk / php-java-bridge / server / test / InteractiveRequestAbort.java  Maximize  Restore  History

Download this file

46 lines (35 with data), 1.4 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
package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import php.java.bridge.Request.AbortException;
/**
* Check if Request.handleSubRequests uses an AbortException instead of an IOException to terminate
* the request-handling loop.
*/
public class InteractiveRequestAbort {
public static void main(String[] args) throws Exception {
String devNull = new File("/dev/null").exists()? "/dev/null" : "devNull";
System.setProperty("php.java.bridge.default_log_level", "5");
System.setProperty("php.java.bridge.default_log_file", devNull);
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("php-interactive");
FileOutputStream fos = new FileOutputStream("/dev/null");
e.getContext().setErrorWriter(new FileWriter(new File(devNull)));
e.getContext().setWriter(new FileWriter(new File(devNull)));
try {
e.eval("function toString() {return 'hello'; }; echo java_closure(); echo new JavaException('java.lang.Exception', 'hello'); echo JavaException('foo')");
} catch (ScriptException ex) {
Throwable orig = ex.getCause();
if (orig instanceof AbortException) {
System.out.println("test okay");
System.exit(0);
}
}
System.out.println("test failed");
System.exit(1);
}
}