Writer for scripts to use when displaying output.
- *
- * @return The Writer.
- */
- public Writer getWriter();
-
-
- /**
- * Returns the Writer used to display error output.
- *
- * @return The Writer
- */
- public Writer getErrorWriter();
-
- /**
- * Sets the Writer for scripts to use when displaying output.
- *
- * @param writer The new Writer.
- */
- public void setWriter(Writer writer);
-
- /**
- * Sets the Writer used to display error output.
- *
- * @param writer The Writer.
- */
- public void setErrorWriter(Writer writer);
-
- /**
- * Returns a Reader to be used by the script to read
- * input.
- *
- * @return The Reader.
- */
- public Reader getReader();
-
- /**
- * Sets the Reader for scripts to read input
- * .
- *
- * @param reader The new Reader.
- */
- public void setReader(Reader reader);
-
- /**
- * Returns immutable List of all the valid values for
- * scope in the ScriptContext.
- *
- * @return list of scope values
- */
- public List getScopes();
-}
diff --git a/server/javax/script/ScriptEngine.java b/server/javax/script/ScriptEngine.java
deleted file mode 100644
index 44e170c..0000000
--- a/server/javax/script/ScriptEngine.java
+++ /dev/null
@@ -1,213 +0,0 @@
-
-package javax.script;
-
-import java.io.Reader;
-
-/**
- * The ScriptEngine interfaces contains only the methods which are expected to
- * be fully functional in every Java ScriptEngine.
- *
- * @author Nandika Jayawardana - * Possible scopes are: - *
- * GLOBAL_SCOPE : - * if the ScriptEngine was created by ScriptingEngineManager - * then GLOBAL_SCOPE of it is returned (or null if there is no - * GLOBAL_SCOPE stored in the ScriptEngine). - *
- * ENGINE_SCOPE : - * the set of key-value pairs stored in the ScriptEngine is - * returned. - * - * @param scope the specified level of scope - * @return associated namespace for the specified level of scope - * @throws IllegalArgumentException if the scope is invalid - */ - public Bindings getBindings(int scope) throws IllegalArgumentException; - - /** - * Associates a key and a value in the ScriptEngine namespace. - * - * @param key the specified key associated with the value - * @param value value which is to be associated with the - * specified key - * @throws IllegalArgumentException if the key is null - */ - public void put(String key, Object value) throws IllegalArgumentException; - - /** - * Associates the specified namespace with the specified level of - * scope. - * - * @param namespace namespace to be associated with the specified - * level of scope - * @param scope level of scope for which the namespace should - * be associated with - * @throws IllegalArgumentException if the scope is invalid - */ - public void setBindings(Bindings namespace, int scope) throws - IllegalArgumentException; - - - /** - * @return the default ScriptContext. - */ - public ScriptContext getContext(); - - /** - * Set the default ScriptContext - * - * @param ctx The context - */ - public void setContext(ScriptContext ctx); -} diff --git a/server/javax/script/ScriptEngineFactory.java b/server/javax/script/ScriptEngineFactory.java deleted file mode 100644 index 42c9747..0000000 --- a/server/javax/script/ScriptEngineFactory.java +++ /dev/null @@ -1,117 +0,0 @@ - -package javax.script; - -import java.util.List; - -/** - * ScriptEngineFactory is used to describe a ScriptEngine instance. - * Each ScriptEngine class implementing ScriptEngine has a - * corresponding factory which exposes metadata describing the engine - * class. - *
- * Nandika Jayawardana
- * Nandika Jayawardana
* Example: \",htmlspecialchars($key,ENT_COMPAT)));\n"+
+"}\n"+
+"function writePairBegin_n($key) {\n"+
+"$this->write(sprintf(\" \",$key));\n"+
+"}\n"+
+"function writePairBegin() {\n"+
+"$this->write(\" \");\n"+
+"}\n"+
+"function writePairEnd() {\n"+
+"$this->write(\" Example:
- * A bridge which uses log4j or the default logger.
- */
- public static class Logger implements ILogger {
- protected ChainsawLogger clogger = null;
- protected ILogger logger;
-
- /**
- * Use chainsaw, if available or a default logger.
- */
- public Logger() {
- logger = new FileLogger(); // log to logStream
- }
-
- /**
- * Use chainsaw, if available.
- *
- * @param logger The specified logger.
- */
- public Logger(ILogger logger) {
- this(!DEFAULT_LOG_FILE_SET, logger);
- }
-
- public Logger(boolean useChainsaw, ILogger logger) {
- if (useChainsaw)
- try {
- this.clogger = ChainsawLogger.createChainsawLogger();
- } catch (Throwable t) {
- if (Util.logLevel > 5) t.printStackTrace();
- this.logger = logger;
- }
- else {
- this.logger = logger;
- }
- }
-
- private ILogger getLogger() {
- if (logger == null) return logger = new FileLogger();
- return logger;
- }
-
- /**
- * {@inheritDoc}
- */
- public void printStackTrace(Throwable t) {
- if (clogger == null) logger.printStackTrace(t);
- else
- try {
- clogger.printStackTrace(t);
- } catch (Exception e) {
- clogger = null;
- getLogger().printStackTrace(t);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void log(int level, String msg) {
- if (clogger == null) logger.log(level, msg);
- else
- try {
- clogger.log(level, msg);
- } catch (Exception e) {
- clogger = null;
- getLogger().log(level, msg);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void warn(String msg) {
- if (clogger == null) logger.warn(msg);
- else
- try {
- clogger.warn(msg);
- } catch (Exception e) {
- clogger = null;
- getLogger().warn(msg);
- }
- }
- }
-
/**
- * The default PHP arguments. Can be passed via -Dphp.java.bridge.php_exec_args=list of urlencoded strings separated by space
+ * The default PHP arguments. Can be passed via -Dio.soluble.pjb.bridge.php_exec_args=list of urlencoded strings separated by space
* Default: "-d display_errors=Off -d log_errors=On -d java.persistent_servlet_connections=On"
*/
private static String[] PHP_ARGS;
@@ -283,12 +182,13 @@ public void warn(String msg) {
* libraries).
*/
public static final String DEFAULT_EXT_DIRS[] = {"/usr/share/java/ext", "/usr/java/packages/lib/ext"};
-
+ //TODO: platform neutrality
/**
* Set to true if the VM is gcj, false otherwise
*/
public static final boolean IS_GNU_JAVA = checkVM();
+ //TODO: drop GNU Java support
/**
* The name of the extension, usually "JavaBridge" or "MonoBridge"
@@ -298,7 +198,7 @@ public void warn(String msg) {
/**
* The max. number of threads in the thread pool. Default is 20.
*
- * @see System property
+ * A bridge which uses log4j or the default logger.
+ */
+ public static class Logger implements ILogger {
+ protected ChainsawLogger clogger = null;
+ protected ILogger logger;
+
+ /**
+ * Use chainsaw, if available or a default logger.
+ */
+ public Logger() {
+ logger = new FileLogger(); // log to logStream
+ }
+
+ /**
+ * Use chainsaw, if available.
+ *
+ * @param logger The specified logger.
+ */
+ public Logger(ILogger logger) {
+ this(!DEFAULT_LOG_FILE_SET, logger);
+ }
+
+ public Logger(boolean useChainsaw, ILogger logger) {
+ if (useChainsaw)
+ try {
+ this.clogger = ChainsawLogger.createChainsawLogger();
+ } catch (Exception e) {
+ if (Util.logLevel > 5) e.printStackTrace();
+ this.logger = logger;
+ }
+ else {
+ this.logger = logger;
+ }
+ }
+
+ private ILogger getLogger() {
+ if (logger == null) return logger = new FileLogger();
+ return logger;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void printStackTrace(Throwable t) {
+ if (clogger == null) logger.printStackTrace(t);
+ else
+ try {
+ clogger.printStackTrace(t);
+ } catch (Exception e) {
+ clogger = null;
+ getLogger().printStackTrace(t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void log(int level, String msg) {
+ if (clogger == null) logger.log(level, msg);
+ else
+ try {
+ clogger.log(level, msg);
+ } catch (Exception e) {
+ clogger = null;
+ getLogger().log(level, msg);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void warn(String msg) {
+ if (clogger == null) logger.warn(msg);
+ else
+ try {
+ clogger.warn(msg);
+ } catch (Exception e) {
+ clogger = null;
+ getLogger().warn(msg);
+ }
+ }
+ }
+
/**
* Starts a CGI process and returns the process handle.
*/
@@ -1050,22 +1315,25 @@ public static class Process extends java.lang.Process {
protected java.lang.Process proc;
private String[] args;
private File homeDir;
- private Map env;
- private boolean tryOtherLocations;
- private boolean preferSystemPhp;
private boolean isOldPhpVersion = false; // php < 5.3
- private boolean includeJava;
- private String cgiDir;
- private String pearDir;
- private String webInfDir;
+ private final Map env;
+ private final boolean tryOtherLocations;
+ private final boolean preferSystemPhp;
+ private final boolean includeJava;
+ private final String cgiDir;
+ private final String pearDir;
+ private final String webInfDir;
- private String getQuoted(String key, String val) {
- if (isOldPhpVersion) return key + val;
- StringBuffer buf = new StringBuffer(key);
- buf.append("'");
- buf.append(val);
- buf.append("'");
- return buf.toString();
+ protected Process(String[] args, boolean includeJava, String cgiDir, String pearDir, String webInfDir, File homeDir, Map env, boolean tryOtherLocations, boolean preferSystemPhp) {
+ this.args = args;
+ this.homeDir = homeDir;
+ this.env = env;
+ this.tryOtherLocations = tryOtherLocations;
+ this.preferSystemPhp = preferSystemPhp;
+ this.includeJava = includeJava;
+ this.cgiDir = cgiDir;
+ this.pearDir = pearDir;
+ this.webInfDir = webInfDir;
}
/**
@@ -1079,7 +1347,12 @@ private String getQuoted(String key, String val) {
* @return args with PHP_ARGS appended
*/
private String[] getPhpArgs(String[] args, boolean includeJava, String cgiDir, String pearDir, String webInfDir) {
- String[] allArgs = new String[args.length + PHP_ARGS.length + ((sessionSavePath != null) ? 2 : 0) + (includeJava ? 1 : 0) + (cgiDir != null ? 2 : 0) + (pearDir != null ? 2 : 0) + (webInfDir != null ? 2 : 0)];
+ String[] allArgs = new String[args.length + PHP_ARGS.length +
+ ((sessionSavePath != null) ? 2 : 0) +
+ (includeJava ? 1 : 0) +
+ (cgiDir != null ? 2 : 0) +
+ (pearDir != null ? 2 : 0) +
+ (webInfDir != null ? 2 : 0)];
int i = 0;
for (i = 0; i < args.length; i++) {
allArgs[i] = args[i];
@@ -1108,13 +1381,22 @@ private String[] getPhpArgs(String[] args, boolean includeJava, String cgiDir, S
allArgs[i++] = getQuoted("java.web_inf_dir=", webInfDir);
}
if (includeJava) allArgs[i++] = "-C"; // don't chdir, we'll do it
- for (int j = 0; j < PHP_ARGS.length; j++) {
- allArgs[i++] = PHP_ARGS[j];
+ for (String PHP_ARGS1 : PHP_ARGS) {
+ allArgs[i++] = PHP_ARGS1;
}
return allArgs;
}
+ private String getQuoted(String key, String val) {
+ if (isOldPhpVersion) return key + val;
+ StringBuilder buf = new StringBuilder(key);
+ buf.append("'");
+ buf.append(val);
+ buf.append("'");
+ return buf.toString();
+ }
+
protected String[] quoteArgs(String[] s) {
// quote all args for windows
if (!USE_SH_WRAPPER)
@@ -1304,22 +1586,10 @@ protected void start() throws NullPointerException, IOException {
throw new IOException("PHP not found. Please install php-cgi. PHP test command was: " + java.util.Arrays.asList(getTestArgumentArray(php, args)) + " ");
}
- protected Process(String[] args, boolean includeJava, String cgiDir, String pearDir, String webInfDir, File homeDir, Map env, boolean tryOtherLocations, boolean preferSystemPhp) {
- this.args = args;
- this.homeDir = homeDir;
- this.env = env;
- this.tryOtherLocations = tryOtherLocations;
- this.preferSystemPhp = preferSystemPhp;
- this.includeJava = includeJava;
- this.cgiDir = cgiDir;
- this.pearDir = pearDir;
- this.webInfDir = webInfDir;
- }
-
/**
* Starts a CGI process and returns the process handle.
*
- * @param args The args array, e.g.: new String[]{null, "-b", ...};. If args is null or if args[0] is null, the function looks for the system property "php.java.bridge.php_exec".
+ * @param args The args array, e.g.: new String[]{null, "-b", ...};. If args is null or if args[0] is null, the function looks for the system property "io.soluble.pjb.bridge.php_exec".
* @param homeDir The home directory. If null, the current working directory is used.
* @param env The CGI environment. If null, Util.DEFAULT_CGI_ENVIRONMENT is used.
* @param tryOtherLocations true if we should check the DEFAULT_CGI_LOCATIONS first
@@ -1431,9 +1701,11 @@ protected ProcessWithErrorHandler(String[] args, boolean includeJava, String cgi
this.err = err;
}
+ @Override
protected void start() throws IOException {
super.start();
(new Util.Thread("CGIErrorReader") {
+ @Override
public void run() {
readErrorStream();
}
@@ -1443,6 +1715,7 @@ public void run() {
/**
* {@inheritDoc}
*/
+ @Override
public void checkError() throws PhpException {
String errorString = error == null ? null : Util.checkError(error.toString());
if (errorString != null) throw new PhpException(errorString);
@@ -1476,6 +1749,7 @@ private synchronized void readErrorStream() {
/**
* {@inheritDoc}
*/
+ @Override
public synchronized int waitFor() throws InterruptedException {
if (in == null) wait();
return super.waitFor();
@@ -1484,7 +1758,11 @@ public synchronized int waitFor() throws InterruptedException {
/**
* Starts a CGI process and returns the process handle.
*
- * @param args The args array, e.g.: new String[]{null, "-b", ...};. If args is null or if args[0] is null, the function looks for the system property "php.java.bridge.php_exec".
+ * @param args The args array, e.g.: new String[]{null, "-b", ...};. If args is null or if args[0] is null, the function looks for the system property "io.soluble.pjb.bridge.php_exec".
+ * @param includeJava
+ * @param cgiDir
+ * @param pearDir
+ * @param webInfDir
* @param homeDir The home directory. If null, the current working directory is used.
* @param env The CGI environment. If null, Util.DEFAULT_CGI_ENVIRONMENT is used.
* @param tryOtherLocations true if the should check DEFAULT_CGI_LOCATIONS
@@ -1501,168 +1779,9 @@ public static Process start(String[] args, boolean includeJava, String cgiDir, S
}
}
- /**
- * Redirect System.out and System.err to the configured logFile or System.err.
- * System.out is always redirected, either to the logFile or to System.err.
- * This is because System.out is reserved to report the status back to the
- * container (IIS, Apache, ...) running the JavaBridge back-end.
- *
- * @param redirectOutput this flag is set, if natcJavaBridge has already redirected stdin, stdout, stderr
- * @param logFile the log file
- */
- static void redirectOutput(String logFile) {
- redirectJavaOutput(logFile);
- }
-
- static void redirectJavaOutput(String logFile) {
- Util.logStream = System.err;
- if (logFile != null && logFile.length() > 0)
- try {
- Util.logStream = new java.io.PrintStream(new java.io.FileOutputStream(logFile));
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- System.setErr(logStream);
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- System.setOut(logStream);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(9);
- }
- }
-
- private static List getEnvironmentBlacklist(Properties p) {
- List l = new LinkedList();
- try {
- String s = getProperty(p, "PHP_ENV_BLACKLIST", "PHPRC");
- StringTokenizer t = new StringTokenizer(s, " ");
- while (t.hasMoreTokens()) l.add(t.nextToken());
- } catch (Exception e) {
- e.printStackTrace();
- l = new LinkedList();
- l.add("PHPRC");
- }
- return l;
- }
-
- private static HashMap getCommonEnvironment(List blacklist) {
- String entries[] = {
- "PATH", "PATH", "LD_LIBRARY_PATH", "LD_ASSUME_KERNEL", "USER", "TMP", "TEMP", "HOME", "HOMEPATH", "LANG", "TZ", "OS"
- };
- HashMap defaultEnv = new HashMap();
- String key, val;
- Method m = null;
- try {
- m = System.class.getMethod("getenv", new Class[]{String.class});
- } catch (Exception e) {/*ignore*/}
- for (int i = 0; i < entries.length; i++) {
- val = null;
- if (m != null) {
- try {
- val = (String) m.invoke(System.class, (Object[]) new String[]{entries[i]});
- } catch (Exception e) {
- m = null;
- }
- }
- if (val == null) {
- try {
- val = System.getProperty(entries[i]);
- } catch (Exception e) {/*ignore*/}
- }
- if ((val != null) && (!blacklist.contains(entries[i])))
- defaultEnv.put(entries[i], val);
- }
-
- // check for windows SystemRoot, needed for socket operations
- key = val = null;
- if ((new File("c:/winnt")).isDirectory()) val = "c:\\winnt";
- else if ((new File("c:/windows")).isDirectory()) val = "c:\\windows";
- try {
- String s = System.getenv(key = "SystemRoot");
- if (s != null) val = s;
- } catch (Throwable t) {/*ignore*/}
- try {
- String s = System.getProperty(key = "Windows.SystemRoot");
- if (s != null) val = s;
- } catch (Throwable t) {/*ignore*/}
- if (val != null && (!blacklist.contains(key))) defaultEnv.put("SystemRoot", val);
-
- // add all non-blacklisted environment entries
- try {
- m = System.class.getMethod("getenv", ZERO_PARAM);
- Map map = (Map) m.invoke(System.class, ZERO_ARG);
- for (Iterator ii = map.entrySet().iterator(); ii.hasNext(); ) {
- Entry entry = (Entry) ii.next();
- key = (String) entry.getKey();
- val = (String) entry.getValue();
-
- if (!blacklist.contains(key))
- defaultEnv.put(key, val);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return defaultEnv;
- }
-
- /**
- * This procedure should be used whenever
* A ContextServer instance represents the current web context.
* When the PipeContextServer is used, there can be more than one PipeContextServer instance per classloader, the ContextFactory.get() checks
@@ -43,7 +44,7 @@
*
* This ContextFactory can be used in environments where no custom class loaders and no threads are allowed.
*
* @author jostb
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.bridge.http.ContextServer
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.bridge.http.ContextServer
*/
public class RemoteHttpContextFactory extends SessionFactory implements IContextFactory, Serializable {
@@ -159,7 +159,7 @@ public void destroy() {
* Return an emulated JSR223 context.
*
* @return The context.
- * @see php.java.servlet.HttpContext
+ * @see io.soluble.pjb.servlet.HttpContext
*/
private IContext createContext() {
return new Context();
diff --git a/server/php/java/bridge/http/SimpleContextFactory.java b/src/main/java/io/soluble/pjb/bridge/http/SimpleContextFactory.java
similarity index 95%
rename from server/php/java/bridge/http/SimpleContextFactory.java
rename to src/main/java/io/soluble/pjb/bridge/http/SimpleContextFactory.java
index a6a28bb..0818d36 100644
--- a/server/php/java/bridge/http/SimpleContextFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/SimpleContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -27,10 +27,10 @@
import java.io.IOException;
import java.io.InputStream;
-import php.java.bridge.ISession;
-import php.java.bridge.JavaBridge;
-import php.java.bridge.Request;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.JavaBridge;
+import io.soluble.pjb.bridge.Request;
+import io.soluble.pjb.bridge.Util;
/**
@@ -38,8 +38,8 @@
*
* Instances of this class are thrown away at the end of the request.
*
- * @see php.java.servlet.ServletContextFactory
- * @see php.java.script.PhpScriptContextFactory
+ * @see io.soluble.pjb.servlet.ServletContextFactory
+ * @see io.soluble.pjb.script.PhpScriptContextFactory
*/
public class SimpleContextFactory implements IContextFactoryVisitor {
diff --git a/server/php/java/bridge/http/SimpleHeaderParser.java b/src/main/java/io/soluble/pjb/bridge/http/SimpleHeaderParser.java
similarity index 97%
rename from server/php/java/bridge/http/SimpleHeaderParser.java
rename to src/main/java/io/soluble/pjb/bridge/http/SimpleHeaderParser.java
index 03b08b4..b6882ad 100644
--- a/server/php/java/bridge/http/SimpleHeaderParser.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/SimpleHeaderParser.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
diff --git a/server/php/java/bridge/http/SocketChannel.java b/src/main/java/io/soluble/pjb/bridge/http/SocketChannel.java
similarity index 97%
rename from server/php/java/bridge/http/SocketChannel.java
rename to src/main/java/io/soluble/pjb/bridge/http/SocketChannel.java
index 23dcab9..13fb686 100644
--- a/server/php/java/bridge/http/SocketChannel.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/SocketChannel.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/http/SocketChannelFactory.java b/src/main/java/io/soluble/pjb/bridge/http/SocketChannelFactory.java
similarity index 97%
rename from server/php/java/bridge/http/SocketChannelFactory.java
rename to src/main/java/io/soluble/pjb/bridge/http/SocketChannelFactory.java
index ca5eb89..a447d63 100644
--- a/server/php/java/bridge/http/SocketChannelFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/SocketChannelFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
import java.io.File;
import java.io.IOException;
@@ -11,9 +11,9 @@
import java.net.UnknownHostException;
import java.util.Map;
-import php.java.bridge.ILogger;
-import php.java.bridge.Util;
-import php.java.bridge.Util.Process;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.Util.Process;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/http/SocketContextServer.java b/src/main/java/io/soluble/pjb/bridge/http/SocketContextServer.java
similarity index 93%
rename from server/php/java/bridge/http/SocketContextServer.java
rename to src/main/java/io/soluble/pjb/bridge/http/SocketContextServer.java
index eac456c..94fb17c 100644
--- a/server/php/java/bridge/http/SocketContextServer.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/SocketContextServer.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -33,16 +33,16 @@
import java.util.Iterator;
import java.util.List;
-import php.java.bridge.AppThreadPool;
-import php.java.bridge.ILogger;
-import php.java.bridge.ISocketFactory;
-import php.java.bridge.JavaBridge;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.AppThreadPool;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.ISocketFactory;
+import io.soluble.pjb.bridge.JavaBridge;
+import io.soluble.pjb.bridge.Util;
/**
* This class manages the fallback physical connection for the
* operating system which doesn't support named pipes, "Windows", or when the
- * System property php.java.bridge.promiscuous is set to true.
+ * System property io.soluble.pjb.bridge.promiscuous is set to true.
*
* When isAvailable() returns true, a server socket bound to the local
* interface (127.0.0.1) has been created on a port in the range
@@ -53,10 +53,10 @@
* It is possible to switch
* off this server by setting the VM property
- * php.java.bridge.no_socket_server to true, e.g.:
- * -Dphp.java.bridge.no_socket_server=true.
*
- * @see php.java.script.InvocablePhpScriptEngine
- * @see php.java.script.PhpScriptEngine
+ * @see io.soluble.pjb.script.InvocablePhpScriptEngine
+ * @see io.soluble.pjb.script.PhpScriptEngine
*/
-abstract class AbstractPhpScriptEngine extends AbstractScriptEngine implements IPhpScriptEngine, Compilable, java.io.FileFilter, CloneableScript {
+abstract class AbstractPhpScriptEngine extends AbstractScriptEngine
+ implements IPhpScriptEngine, Compilable, java.io.FileFilter, CloneableScript {
/**
* The allocated script
@@ -139,6 +140,7 @@ protected void setNewContextFactory() {
/* (non-Javadoc)
* @see javax.script.ScriptEngine#eval(java.io.Reader, javax.script.ScriptContext)
*/
+ @Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
return evalPhp(reader, context);
}
@@ -181,18 +183,15 @@ protected void compilePhp(Reader reader) throws IOException {
}
FileWriter writer = new FileWriter(compilerOutputFile);
char[] buf = new char[Util.BUF_SIZE];
- Reader localReader = getLocalReader(reader, true);
- try {
+ try (Reader localReader = getLocalReader(reader, true)) {
int c;
while ((c = localReader.read(buf)) > 0)
writer.write(buf, 0, c);
writer.close();
- } finally {
- localReader.close();
}
}
- private void updateGlobalEnvironment(ScriptContext context) throws IOException {
+ private void updateGlobalEnvironment() throws IOException {
if (isCompiled) {
if (compilerOutputFile == null)
throw new NullPointerException("SCRIPT_FILENAME");
@@ -201,12 +200,13 @@ private void updateGlobalEnvironment(ScriptContext context) throws IOException {
}
private final class SimpleHeaderParser extends HeaderParser {
- private WriterOutputStream writer;
+ private final WriterOutputStream writer;
public SimpleHeaderParser(WriterOutputStream writer) {
this.writer = writer;
}
+ @Override
public void parseHeader(String header) {
if (header == null) return;
int idx = header.indexOf(':');
@@ -216,6 +216,7 @@ public void parseHeader(String header) {
addHeader(key, val);
}
+ @Override
public void addHeader(String key, String val) {
if (val != null && key.equals("content-type")) {
int idx = val.indexOf(';');
@@ -232,7 +233,7 @@ public void addHeader(String key, String val) {
protected Continuation getContinuation(Reader reader, ScriptContext context) throws IOException {
HeaderParser headerParser = HeaderParser.DEFAULT_HEADER_PARSER; // ignore encoding, we pass everything directly
IPhpScriptContext phpScriptContext = (IPhpScriptContext) context;
- updateGlobalEnvironment(context);
+ updateGlobalEnvironment();
OutputStream out = ((PhpScriptWriter) (context.getWriter())).getOutputStream();
OutputStream err = ((PhpScriptWriter) (context.getErrorWriter())).getOutputStream();
@@ -271,8 +272,9 @@ final protected Object doEval(Reader reader, ScriptContext context) throws Excep
*/
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
+ @Override
public Object eval(String script, ScriptContext context)
throws ScriptException {
if (script == null) return evalPhp((Reader) null, context);
@@ -289,8 +291,9 @@ public Object eval(String script, ScriptContext context)
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
+ @Override
public ScriptEngineFactory getFactory() {
return this.factory;
}
@@ -298,6 +301,7 @@ public ScriptEngineFactory getFactory() {
/**
* Release the continuation
*/
+ @Override
public void release() {
if (continuation != null) {
try {
diff --git a/server/php/java/script/CGIRunner.java b/src/main/java/io/soluble/pjb/script/CGIRunner.java
similarity index 92%
rename from server/php/java/script/CGIRunner.java
rename to src/main/java/io/soluble/pjb/script/CGIRunner.java
index f5ef49d..f6d66e5 100644
--- a/server/php/java/script/CGIRunner.java
+++ b/src/main/java/io/soluble/pjb/script/CGIRunner.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -33,10 +33,10 @@
import java.io.Writer;
import java.util.Map;
-import php.java.bridge.ILogger;
-import php.java.bridge.Util;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.OutputStreamFactory;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.OutputStreamFactory;
/**
* This class can be used to run a PHP CGI binary. Used only when
@@ -44,9 +44,9 @@
* please use a HttpProxy and a URLReader instead.
*
* @author jostb
- * @see php.java.bridge.http.HttpServer
- * @see php.java.script.URLReader
- * @see php.java.script.HttpProxy
+ * @see io.soluble.pjb.bridge.http.HttpServer
+ * @see io.soluble.pjb.script.URLReader
+ * @see io.soluble.pjb.script.HttpProxy
*/
public class CGIRunner extends Continuation {
diff --git a/server/php/java/script/CloneableScript.java b/src/main/java/io/soluble/pjb/script/CloneableScript.java
similarity index 97%
rename from server/php/java/script/CloneableScript.java
rename to src/main/java/io/soluble/pjb/script/CloneableScript.java
index e00cb43..cced3a8 100644
--- a/server/php/java/script/CloneableScript.java
+++ b/src/main/java/io/soluble/pjb/script/CloneableScript.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
diff --git a/server/php/java/script/CloseableInteractivePhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/CloseableInteractivePhpScriptEngine.java
similarity index 97%
rename from server/php/java/script/CloseableInteractivePhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/CloseableInteractivePhpScriptEngine.java
index 5d8f7ed..e600d2d 100644
--- a/server/php/java/script/CloseableInteractivePhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/CloseableInteractivePhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/CloseableInvocablePhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/CloseableInvocablePhpScriptEngine.java
similarity index 97%
rename from server/php/java/script/CloseableInvocablePhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/CloseableInvocablePhpScriptEngine.java
index 599cb19..62ad7cb 100644
--- a/server/php/java/script/CloseableInvocablePhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/CloseableInvocablePhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/CloseablePhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/CloseablePhpScriptEngine.java
similarity index 97%
rename from server/php/java/script/CloseablePhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/CloseablePhpScriptEngine.java
index 8fa755c..8251f56 100644
--- a/server/php/java/script/CloseablePhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/CloseablePhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/CompiledPhpScript.java b/src/main/java/io/soluble/pjb/script/CompiledPhpScript.java
similarity index 98%
rename from server/php/java/script/CompiledPhpScript.java
rename to src/main/java/io/soluble/pjb/script/CompiledPhpScript.java
index dd6f28b..e1aa760 100644
--- a/server/php/java/script/CompiledPhpScript.java
+++ b/src/main/java/io/soluble/pjb/script/CompiledPhpScript.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
diff --git a/server/php/java/script/Continuation.java b/src/main/java/io/soluble/pjb/script/Continuation.java
similarity index 95%
rename from server/php/java/script/Continuation.java
rename to src/main/java/io/soluble/pjb/script/Continuation.java
index c0fe4bc..9f08b04 100644
--- a/server/php/java/script/Continuation.java
+++ b/src/main/java/io/soluble/pjb/script/Continuation.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -28,17 +28,17 @@
import java.io.OutputStream;
import java.util.Map;
-import php.java.bridge.Util;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.HeaderParser;
/**
* This class represents the logic to run PHP scripts through CGI, FastCGI or on a remote HTTP server
* (accessed through URLReader).
*
* @author jostb
- * @see php.java.bridge.http.HttpServer
- * @see php.java.script.URLReader
- * @see php.java.script.HttpProxy
+ * @see io.soluble.pjb.bridge.http.HttpServer
+ * @see io.soluble.pjb.script.URLReader
+ * @see io.soluble.pjb.script.HttpProxy
*/
public abstract class Continuation implements IContinuation, Runnable {
diff --git a/server/php/java/script/FCGIProcess.java b/src/main/java/io/soluble/pjb/script/FCGIProcess.java
similarity index 93%
rename from server/php/java/script/FCGIProcess.java
rename to src/main/java/io/soluble/pjb/script/FCGIProcess.java
index 1f0d9e0..a2d265c 100644
--- a/server/php/java/script/FCGIProcess.java
+++ b/src/main/java/io/soluble/pjb/script/FCGIProcess.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,8 +29,8 @@
import java.util.LinkedList;
import java.util.Map;
-import php.java.bridge.Util;
-import php.java.bridge.http.IFCGIProcess;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IFCGIProcess;
/**
* Represents the FastCGI process.
@@ -67,7 +67,7 @@ protected String[] getArgumentArray(String[] php, String[] args) {
}
/* (non-Javadoc)
- * @see php.java.servlet.fastcgi.IFCGIProcess#start()
+ * @see io.soluble.pjb.servlet.fastcgi.IFCGIProcess#start()
*/
public void start() throws NullPointerException, IOException {
super.start();
diff --git a/server/php/java/script/FastCGIProxy.java b/src/main/java/io/soluble/pjb/script/FastCGIProxy.java
similarity index 91%
rename from server/php/java/script/FastCGIProxy.java
rename to src/main/java/io/soluble/pjb/script/FastCGIProxy.java
index fbb79c5..64ba6b8 100644
--- a/server/php/java/script/FastCGIProxy.java
+++ b/src/main/java/io/soluble/pjb/script/FastCGIProxy.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -34,26 +34,26 @@
import java.util.HashMap;
import java.util.Map;
-import php.java.bridge.ILogger;
-import php.java.bridge.Util;
-import php.java.bridge.http.FCGIConnectException;
-import php.java.bridge.http.FCGIConnection;
-import php.java.bridge.http.FCGIConnectionFactory;
-import php.java.bridge.http.FCGIConnectionPool;
-import php.java.bridge.http.FCGIIOFactory;
-import php.java.bridge.http.FCGIInputStream;
-import php.java.bridge.http.FCGIOutputStream;
-import php.java.bridge.http.FCGIUtil;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.IFCGIProcess;
-import php.java.bridge.http.IFCGIProcessFactory;
-import php.java.bridge.http.OutputStreamFactory;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.FCGIConnectException;
+import io.soluble.pjb.bridge.http.FCGIConnection;
+import io.soluble.pjb.bridge.http.FCGIConnectionFactory;
+import io.soluble.pjb.bridge.http.FCGIConnectionPool;
+import io.soluble.pjb.bridge.http.FCGIIOFactory;
+import io.soluble.pjb.bridge.http.FCGIInputStream;
+import io.soluble.pjb.bridge.http.FCGIOutputStream;
+import io.soluble.pjb.bridge.http.FCGIUtil;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.IFCGIProcess;
+import io.soluble.pjb.bridge.http.IFCGIProcessFactory;
+import io.soluble.pjb.bridge.http.OutputStreamFactory;
/**
* This class can be used to run (and to connect to) a FastCGI server.
*
* @author jostb
- * @see php.java.script.servlet.HttpFastCGIProxy
+ * @see io.soluble.pjb.script.servlet.HttpFastCGIProxy
*/
public class FastCGIProxy extends Continuation implements IFCGIProcessFactory {
diff --git a/server/php/java/script/HttpProxy.java b/src/main/java/io/soluble/pjb/script/HttpProxy.java
similarity index 93%
rename from server/php/java/script/HttpProxy.java
rename to src/main/java/io/soluble/pjb/script/HttpProxy.java
index cabf3fd..a285aec 100644
--- a/server/php/java/script/HttpProxy.java
+++ b/src/main/java/io/soluble/pjb/script/HttpProxy.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,9 +29,9 @@
import java.io.Reader;
import java.util.Map;
-import php.java.bridge.ILogger;
-import php.java.bridge.Util.Process.PhpException;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.Util.Process.PhpException;
+import io.soluble.pjb.bridge.http.HeaderParser;
/**
* Represents the script continuation.
diff --git a/server/php/java/script/IContinuation.java b/src/main/java/io/soluble/pjb/script/IContinuation.java
similarity index 97%
rename from server/php/java/script/IContinuation.java
rename to src/main/java/io/soluble/pjb/script/IContinuation.java
index fdeb40f..d93d2b5 100644
--- a/server/php/java/script/IContinuation.java
+++ b/src/main/java/io/soluble/pjb/script/IContinuation.java
@@ -1,4 +1,4 @@
-package php.java.script;
+package io.soluble.pjb.script;
/**
* Classes implementing this interface represent the script continuation;
diff --git a/server/php/java/script/IPhpScriptContext.java b/src/main/java/io/soluble/pjb/script/IPhpScriptContext.java
similarity index 90%
rename from server/php/java/script/IPhpScriptContext.java
rename to src/main/java/io/soluble/pjb/script/IPhpScriptContext.java
index b8bd73c..2b3d1c4 100644
--- a/server/php/java/script/IPhpScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/IPhpScriptContext.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -30,12 +30,12 @@
import javax.script.ScriptContext;
-import php.java.bridge.ILogger;
-import php.java.bridge.IManaged;
-import php.java.bridge.Invocable;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.IManaged;
+import io.soluble.pjb.bridge.Invocable;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.IContext;
/**
* Common methods for all PHP ScriptContexts
diff --git a/server/php/java/script/IPhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/IPhpScriptEngine.java
similarity index 93%
rename from server/php/java/script/IPhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/IPhpScriptEngine.java
index 2051caa..3b0b400 100644
--- a/server/php/java/script/IPhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/IPhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -41,12 +41,11 @@ public interface IPhpScriptEngine extends ScriptEngine, Compilable, java.io.File
*
* @throws IOException
*/
- public void close() throws IOException;
+ void close() throws IOException;
/**
* alias for {@link #close()}
*
- * @throws IOException
*/
- public void release();
+ void release();
}
diff --git a/server/php/java/script/IScriptReader.java b/src/main/java/io/soluble/pjb/script/IScriptReader.java
similarity index 80%
rename from server/php/java/script/IScriptReader.java
rename to src/main/java/io/soluble/pjb/script/IScriptReader.java
index ddc0782..8eab9d3 100644
--- a/server/php/java/script/IScriptReader.java
+++ b/src/main/java/io/soluble/pjb/script/IScriptReader.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier and others.
@@ -29,8 +29,8 @@
import java.io.OutputStream;
import java.util.Map;
-import php.java.bridge.Util;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.HeaderParser;
/**
* Read data from a URL or from a servlet and write the result to the output stream and a header parser.
@@ -42,8 +42,9 @@ public interface IScriptReader {
/**
* These header values appear in the environment map passed to PHP
*/
- public static final String[] HEADER = new String[]{Util.X_JAVABRIDGE_CONTEXT, Util.X_JAVABRIDGE_OVERRIDE_HOSTS,
- Util.X_JAVABRIDGE_INCLUDE_ONLY, Util.X_JAVABRIDGE_INCLUDE, Util.X_JAVABRIDGE_REDIRECT, Util.X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT};
+ static final String[] HEADER = new String[]{Util.X_JAVABRIDGE_CONTEXT, Util.X_JAVABRIDGE_OVERRIDE_HOSTS,
+ Util.X_JAVABRIDGE_INCLUDE_ONLY, Util.X_JAVABRIDGE_INCLUDE, Util.X_JAVABRIDGE_REDIRECT,
+ Util.X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT};
/**
* Read from the URL and write the data to out.
@@ -52,9 +53,7 @@ public interface IScriptReader {
* @param out The OutputStream.
* @param headerParser The header parser
* @throws IOException
- * @throws ServletException
*/
- public abstract void read(Map env, OutputStream out,
- HeaderParser headerParser) throws IOException;
+ abstract void read(Map env, OutputStream out, HeaderParser headerParser) throws IOException;
}
\ No newline at end of file
diff --git a/server/php/java/script/InteractivePhpScriptContextFactory.java b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptContextFactory.java
similarity index 92%
rename from server/php/java/script/InteractivePhpScriptContextFactory.java
rename to src/main/java/io/soluble/pjb/script/InteractivePhpScriptContextFactory.java
index 0a0f934..f50e362 100644
--- a/server/php/java/script/InteractivePhpScriptContextFactory.java
+++ b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -24,9 +24,9 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-import php.java.bridge.ISession;
-import php.java.bridge.http.IContext;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.http.IContext;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* A custom context factory, creates a ContextFactory for JSR223 contexts. sessions do not expire.
diff --git a/server/php/java/script/InteractivePhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngine.java
similarity index 94%
rename from server/php/java/script/InteractivePhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngine.java
index 44cfe0e..ea18b3c 100644
--- a/server/php/java/script/InteractivePhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -31,8 +31,8 @@
import javax.script.ScriptContext;
import javax.script.ScriptException;
-import php.java.bridge.Util;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IContext;
/**
* A convenience variant of the PHP script engine which can be used interactively.
@@ -49,7 +49,7 @@
public class InteractivePhpScriptEngine extends InvocablePhpScriptEngine {
private static final String restoreState = "" +
- "$javabridge_values=unserialize(java_values(java_context()->getAttribute('php.java.bridge.JAVABRIDGE_TMP_VALUES', 100)));" +
+ "$javabridge_values=unserialize(java_values(java_context()->getAttribute('io.soluble.pjb.bridge.JAVABRIDGE_TMP_VALUES', 100)));" +
"if($javabridge_values)" +
"foreach ($javabridge_values as $javabridge_key=>$javabridge_val) " +
"{eval(\"\\$$javabridge_key=\\$javabridge_values[\\$javabridge_key];\");}\n";
@@ -57,7 +57,7 @@ public class InteractivePhpScriptEngine extends InvocablePhpScriptEngine {
"foreach (get_defined_vars() as $javabridge_key=>$javabridge_val) " +
"{if(in_array($javabridge_key, $javabridge_ignored_keys)) continue;" +
"eval(\"\\$javabridge_values[\\$javabridge_key]=\\$$javabridge_key;\");};" +
- "java_context()->setAttribute('php.java.bridge.JAVABRIDGE_TMP_VALUES', serialize($javabridge_values), 100);\n";
+ "java_context()->setAttribute('io.soluble.pjb.bridge.JAVABRIDGE_TMP_VALUES', serialize($javabridge_values), 100);\n";
public InteractivePhpScriptEngine() {
diff --git a/server/php/java/script/InteractivePhpScriptEngineFactory.java b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngineFactory.java
similarity index 98%
rename from server/php/java/script/InteractivePhpScriptEngineFactory.java
rename to src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngineFactory.java
index 55bd9c7..d4bfbf8 100644
--- a/server/php/java/script/InteractivePhpScriptEngineFactory.java
+++ b/src/main/java/io/soluble/pjb/script/InteractivePhpScriptEngineFactory.java
@@ -1,5 +1,5 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/InvocablePhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngine.java
similarity index 96%
rename from server/php/java/script/InvocablePhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngine.java
index c0703d4..514b6a6 100644
--- a/server/php/java/script/InvocablePhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -42,9 +42,10 @@
import javax.script.ScriptContext;
import javax.script.ScriptException;
-import php.java.bridge.PhpProcedure;
-import php.java.bridge.Util;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.PhpProcedure;
+import io.soluble.pjb.bridge.Request;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IContext;
/**
* This class implements the ScriptEngine and the Invocable interface.
@@ -70,8 +71,8 @@
*
*
- * In a servlet environment please use a
diff --git a/server/php/java/script/PhpScriptEngineFactory.java b/src/main/java/io/soluble/pjb/script/PhpScriptEngineFactory.java
similarity index 98%
rename from server/php/java/script/PhpScriptEngineFactory.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptEngineFactory.java
index 839aa0d..cde77f9 100644
--- a/server/php/java/script/PhpScriptEngineFactory.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptEngineFactory.java
@@ -1,5 +1,5 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,7 +29,7 @@
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/**
* Create a standalone PHP script engines.
diff --git a/server/php/java/script/PhpScriptException.java b/src/main/java/io/soluble/pjb/script/PhpScriptException.java
similarity index 98%
rename from server/php/java/script/PhpScriptException.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptException.java
index 2ca230d..ce983ae 100644
--- a/server/php/java/script/PhpScriptException.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptException.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/PhpScriptWriter.java b/src/main/java/io/soluble/pjb/script/PhpScriptWriter.java
similarity index 98%
rename from server/php/java/script/PhpScriptWriter.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptWriter.java
index bc90763..a7e7306 100644
--- a/server/php/java/script/PhpScriptWriter.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptWriter.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/PhpSecureScriptContext.java b/src/main/java/io/soluble/pjb/script/PhpSecureScriptContext.java
similarity index 98%
rename from server/php/java/script/PhpSecureScriptContext.java
rename to src/main/java/io/soluble/pjb/script/PhpSecureScriptContext.java
index 14d3686..b5edba4 100644
--- a/server/php/java/script/PhpSecureScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/PhpSecureScriptContext.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
import javax.script.ScriptContext;
diff --git a/server/php/java/script/ResultProxy.java b/src/main/java/io/soluble/pjb/script/ResultProxy.java
similarity index 98%
rename from server/php/java/script/ResultProxy.java
rename to src/main/java/io/soluble/pjb/script/ResultProxy.java
index ae40f68..f0f2831 100644
--- a/server/php/java/script/ResultProxy.java
+++ b/src/main/java/io/soluble/pjb/script/ResultProxy.java
@@ -1,10 +1,10 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
import java.io.IOException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/ScriptContextDecorator.java b/src/main/java/io/soluble/pjb/script/ScriptContextDecorator.java
similarity index 99%
rename from server/php/java/script/ScriptContextDecorator.java
rename to src/main/java/io/soluble/pjb/script/ScriptContextDecorator.java
index c4061e1..83b2597 100644
--- a/server/php/java/script/ScriptContextDecorator.java
+++ b/src/main/java/io/soluble/pjb/script/ScriptContextDecorator.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/URLReader.java b/src/main/java/io/soluble/pjb/script/URLReader.java
similarity index 97%
rename from server/php/java/script/URLReader.java
rename to src/main/java/io/soluble/pjb/script/URLReader.java
index 65af051..9bdd8c3 100644
--- a/server/php/java/script/URLReader.java
+++ b/src/main/java/io/soluble/pjb/script/URLReader.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -48,8 +48,8 @@
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
-import php.java.bridge.Util;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.HeaderParser;
/**
* This class can be used to connect to a HTTP server to allocate and to invoke php scripts.
@@ -179,7 +179,7 @@ private void appendListValues(StringBuffer buf, List list) {
}
/* (non-Javadoc)
- * @see php.java.script.IScriptReader#read(java.util.Map, java.io.OutputStream, php.java.bridge.Util.HeaderParser)
+ * @see io.soluble.pjb.script.IScriptReader#read(java.util.Map, java.io.OutputStream, io.soluble.pjb.Util.HeaderParser)
*/
public void read(Map env, OutputStream out, HeaderParser headerParser) throws IOException {
InputStream natIn = null;
diff --git a/server/php/java/script/package.html b/src/main/java/io/soluble/pjb/script/package.html
similarity index 100%
rename from server/php/java/script/package.html
rename to src/main/java/io/soluble/pjb/script/package.html
diff --git a/server/php/java/script/servlet/HttpFastCGIProxy.java b/src/main/java/io/soluble/pjb/script/servlet/HttpFastCGIProxy.java
similarity index 84%
rename from server/php/java/script/servlet/HttpFastCGIProxy.java
rename to src/main/java/io/soluble/pjb/script/servlet/HttpFastCGIProxy.java
index dcaae87..d6229f1 100644
--- a/server/php/java/script/servlet/HttpFastCGIProxy.java
+++ b/src/main/java/io/soluble/pjb/script/servlet/HttpFastCGIProxy.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script.servlet;
+package io.soluble.pjb.script.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -28,21 +28,21 @@
import java.io.OutputStream;
import java.util.Map;
-import php.java.bridge.Util;
-import php.java.bridge.http.FCGIConnectionPool;
-import php.java.bridge.http.FCGIInputStream;
-import php.java.bridge.http.FCGIOutputStream;
-import php.java.bridge.http.FCGIUtil;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.OutputStreamFactory;
-import php.java.script.Continuation;
-import php.java.script.ResultProxy;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.FCGIConnectionPool;
+import io.soluble.pjb.bridge.http.FCGIInputStream;
+import io.soluble.pjb.bridge.http.FCGIOutputStream;
+import io.soluble.pjb.bridge.http.FCGIUtil;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.OutputStreamFactory;
+import io.soluble.pjb.script.Continuation;
+import io.soluble.pjb.script.ResultProxy;
/**
* This class can be used to connect to a FastCGI server.
*
* @author jostb
- * @see php.java.script.FastCGIProxy
+ * @see io.soluble.pjb.script.FastCGIProxy
*/
public class HttpFastCGIProxy extends Continuation {
diff --git a/server/php/java/script/servlet/PhpHttpScriptContext.java b/src/main/java/io/soluble/pjb/script/servlet/PhpHttpScriptContext.java
similarity index 78%
rename from server/php/java/script/servlet/PhpHttpScriptContext.java
rename to src/main/java/io/soluble/pjb/script/servlet/PhpHttpScriptContext.java
index d9e6709..1d8a4d5 100644
--- a/server/php/java/script/servlet/PhpHttpScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/servlet/PhpHttpScriptContext.java
@@ -1,4 +1,4 @@
-package php.java.script.servlet;
+package io.soluble.pjb.script.servlet;
/*-*- mode: Java; tab-width:8 -*-*/
@@ -16,21 +16,19 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.ILogger;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.WriterOutputStream;
-import php.java.script.Continuation;
-import php.java.script.IPhpScriptContext;
-import php.java.script.PhpScriptContextDecorator;
-import php.java.script.PhpScriptWriter;
-import php.java.script.ResultProxy;
-import php.java.script.servlet.HttpFastCGIProxy;
-import php.java.script.servlet.PhpScriptLogWriter;
-import php.java.servlet.ContextLoaderListener;
-import php.java.servlet.ServletUtil;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.WriterOutputStream;
+import io.soluble.pjb.script.Continuation;
+import io.soluble.pjb.script.IPhpScriptContext;
+import io.soluble.pjb.script.PhpScriptContextDecorator;
+import io.soluble.pjb.script.PhpScriptWriter;
+import io.soluble.pjb.script.ResultProxy;
+import io.soluble.pjb.servlet.ContextLoaderListener;
+import io.soluble.pjb.servlet.ServletUtil;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -60,9 +58,9 @@
* Use
* When Apache, IIS or php
@@ -49,11 +47,11 @@
* requests and then re-directs to a private (socket- or pipe-)
* communication channel. This is the fastest mechanism to connect
* php and java. It is even 1.5 times faster than local ("unix
- * domain") sockets used by the php.java.bridge.JavaBridge standalone
+ * domain") sockets used by the io.soluble.pjb.JavaBridge standalone
* listener.
- * To enable fcg/servlet debug code start the servlet engine with -Dphp.java.bridge.default_log_level=6.
- * For example: There cannot be more than one PhpJavaServlet instance per web application. If you extend from this class, make sure to change
* the .phpjavabridge => PhpJavaServlet mapping in the WEB-INF/web.xml.
* This ContextFactory can be used in environments where no custom class loaders and no threads are allowed.
*
* @author jostb
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.bridge.http.ContextServer
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.bridge.http.ContextServer
*/
public class RemoteHttpServletContextFactory extends JavaBridgeFactory implements IContextFactory, Serializable {
@@ -238,7 +238,7 @@ public void destroy() {
* Return an emulated JSR223 context.
*
* @return The context.
- * @see php.java.servlet.HttpContext
+ * @see io.soluble.pjb.servlet.HttpContext
*/
private IContext createContext() {
diff --git a/server/php/java/servlet/RemoteHttpServletRequest.java b/src/main/java/io/soluble/pjb/servlet/RemoteHttpServletRequest.java
similarity index 96%
rename from server/php/java/servlet/RemoteHttpServletRequest.java
rename to src/main/java/io/soluble/pjb/servlet/RemoteHttpServletRequest.java
index ffee8a4..c23437d 100644
--- a/server/php/java/servlet/RemoteHttpServletRequest.java
+++ b/src/main/java/io/soluble/pjb/servlet/RemoteHttpServletRequest.java
@@ -1,7 +1,7 @@
/**
*
*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
diff --git a/server/php/java/servlet/RemoteHttpServletResponse.java b/src/main/java/io/soluble/pjb/servlet/RemoteHttpServletResponse.java
similarity index 96%
rename from server/php/java/servlet/RemoteHttpServletResponse.java
rename to src/main/java/io/soluble/pjb/servlet/RemoteHttpServletResponse.java
index a981660..f208153 100644
--- a/server/php/java/servlet/RemoteHttpServletResponse.java
+++ b/src/main/java/io/soluble/pjb/servlet/RemoteHttpServletResponse.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -34,7 +34,7 @@
/**
* A servlet response which writes its output to an internal buffer. The buffer can be fetched using
- * "getBufferContents()". May be used by remote PHP scripts (those accessing PhpJavaServlet) through the "java_context()->getHttpServletResponse()" API.
+ * "getBufferContents()". May be used by remote PHP scripts (those accessing PhpJavaServlet) through the "java_context()->getHttpServletResponse()" API.
* Also used by the "java_virtual()" API.
*
* @author jostb
diff --git a/server/php/java/servlet/RemoteServletContextFactory.java b/src/main/java/io/soluble/pjb/servlet/RemoteServletContextFactory.java
similarity index 92%
rename from server/php/java/servlet/RemoteServletContextFactory.java
rename to src/main/java/io/soluble/pjb/servlet/RemoteServletContextFactory.java
index 454f3e6..a1afa95 100644
--- a/server/php/java/servlet/RemoteServletContextFactory.java
+++ b/src/main/java/io/soluble/pjb/servlet/RemoteServletContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -30,17 +30,17 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.ISession;
-import php.java.bridge.http.IContext;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.http.IContext;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* Create session contexts for servlets. In addition to the
* standard ContextFactory this factory keeps a reference to the
* HttpServletRequest.
*
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.bridge.http.ContextServer
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.bridge.http.ContextServer
*/
public class RemoteServletContextFactory extends SimpleServletContextFactory {
protected RemoteServletContextFactory(Servlet servlet, ServletContext ctx, HttpServletRequest proxy, HttpServletRequest req, HttpServletResponse res) {
@@ -88,7 +88,7 @@ public static IContextFactory addNew(Servlet servlet, ServletContext kontext, Ht
* Return an emulated JSR223 context.
*
* @return The context.
- * @see php.java.servlet.HttpContext
+ * @see io.soluble.pjb.servlet.HttpContext
*/
public IContext createContext() {
IContext ctx = new HttpContext(kontext, req, res);
diff --git a/server/php/java/servlet/ServletContextFactory.java b/src/main/java/io/soluble/pjb/servlet/ServletContextFactory.java
similarity index 92%
rename from server/php/java/servlet/ServletContextFactory.java
rename to src/main/java/io/soluble/pjb/servlet/ServletContextFactory.java
index 3e2fd01..92ab925 100644
--- a/server/php/java/servlet/ServletContextFactory.java
+++ b/src/main/java/io/soluble/pjb/servlet/ServletContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,16 +29,16 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* Create session contexts for servlets. In addition to the
* standard ContextFactory this factory keeps a reference to the
* HttpServletRequest.
*
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.bridge.http.ContextServer
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.bridge.http.ContextServer
*/
public class ServletContextFactory extends SimpleServletContextFactory {
protected ServletContextFactory(Servlet servlet, ServletContext ctx,
diff --git a/server/php/java/servlet/ServletUtil.java b/src/main/java/io/soluble/pjb/servlet/ServletUtil.java
similarity index 98%
rename from server/php/java/servlet/ServletUtil.java
rename to src/main/java/io/soluble/pjb/servlet/ServletUtil.java
index 71d9ef0..ecd2c8f 100644
--- a/server/php/java/servlet/ServletUtil.java
+++ b/src/main/java/io/soluble/pjb/servlet/ServletUtil.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import java.io.File;
import java.io.IOException;
@@ -18,8 +18,8 @@
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.Util;
-import php.java.bridge.http.WriterOutputStream;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.WriterOutputStream;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/servlet/SimpleHttpServletResponse.java b/src/main/java/io/soluble/pjb/servlet/SimpleHttpServletResponse.java
similarity index 98%
rename from server/php/java/servlet/SimpleHttpServletResponse.java
rename to src/main/java/io/soluble/pjb/servlet/SimpleHttpServletResponse.java
index 95279d1..f0b3f4e 100644
--- a/server/php/java/servlet/SimpleHttpServletResponse.java
+++ b/src/main/java/io/soluble/pjb/servlet/SimpleHttpServletResponse.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/servlet/SimpleServletContextFactory.java b/src/main/java/io/soluble/pjb/servlet/SimpleServletContextFactory.java
similarity index 91%
rename from server/php/java/servlet/SimpleServletContextFactory.java
rename to src/main/java/io/soluble/pjb/servlet/SimpleServletContextFactory.java
index 2dd999b..3524735 100644
--- a/server/php/java/servlet/SimpleServletContextFactory.java
+++ b/src/main/java/io/soluble/pjb/servlet/SimpleServletContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -30,18 +30,18 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import php.java.bridge.ISession;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.http.IContext;
/**
* Create session contexts for servlets. In addition to the
* standard ContextFactory this factory keeps a reference to the
* HttpServletRequest.
*
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.bridge.http.ContextServer
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.bridge.http.ContextServer
*/
-public class SimpleServletContextFactory extends php.java.bridge.http.SimpleContextFactory {
+public class SimpleServletContextFactory extends io.soluble.pjb.bridge.http.SimpleContextFactory {
protected HttpServletRequest proxy, req;
protected HttpServletResponse res;
protected ServletContext kontext;
@@ -60,7 +60,7 @@ protected SimpleServletContextFactory(Servlet servlet, ServletContext ctx, HttpS
* Set the HttpServletRequest for session sharing. This implementation does nothing, the proxy must have been set in the constructor.
*
* @param req The HttpServletRequest
- * @see php.java.servlet.RemoteServletContextFactory#setSessionFactory(HttpServletRequest)
+ * @see io.soluble.pjb.servlet.RemoteServletContextFactory#setSessionFactory(HttpServletRequest)
*/
protected void setSessionFactory(HttpServletRequest req) {
}
@@ -98,7 +98,7 @@ public synchronized void destroy() {
* Return an emulated JSR223 context.
*
* @return The context.
- * @see php.java.servlet.HttpContext
+ * @see io.soluble.pjb.servlet.HttpContext
*/
public IContext createContext() {
IContext ctx = new HttpContext(kontext, req, res);
diff --git a/server/php/java/servlet/VoidInputHttpServletRequest.java b/src/main/java/io/soluble/pjb/servlet/VoidInputHttpServletRequest.java
similarity index 96%
rename from server/php/java/servlet/VoidInputHttpServletRequest.java
rename to src/main/java/io/soluble/pjb/servlet/VoidInputHttpServletRequest.java
index 8d6081c..2411519 100644
--- a/server/php/java/servlet/VoidInputHttpServletRequest.java
+++ b/src/main/java/io/soluble/pjb/servlet/VoidInputHttpServletRequest.java
@@ -1,7 +1,7 @@
/**
*
*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/server/php/java/servlet/fastcgi/FCGIProcess.java b/src/main/java/io/soluble/pjb/servlet/fastcgi/FCGIProcess.java
similarity index 93%
rename from server/php/java/servlet/fastcgi/FCGIProcess.java
rename to src/main/java/io/soluble/pjb/servlet/fastcgi/FCGIProcess.java
index 93dc8c6..fc86b93 100644
--- a/server/php/java/servlet/fastcgi/FCGIProcess.java
+++ b/src/main/java/io/soluble/pjb/servlet/fastcgi/FCGIProcess.java
@@ -1,5 +1,5 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet.fastcgi;
+package io.soluble.pjb.servlet.fastcgi;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -28,8 +28,8 @@
import java.util.LinkedList;
import java.util.Map;
-import php.java.bridge.Util;
-import php.java.bridge.http.IFCGIProcess;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IFCGIProcess;
/**
* Represents the FastCGI process.
@@ -64,7 +64,7 @@ protected String[] getArgumentArray(String[] php, String[] args) {
}
/* (non-Javadoc)
- * @see php.java.servlet.fastcgi.IFCGIProcess#start()
+ * @see io.soluble.pjb.servlet.fastcgi.IFCGIProcess#start()
*/
public void start() throws NullPointerException, IOException {
super.start();
diff --git a/server/php/java/servlet/fastcgi/FastCGIServlet.java b/src/main/java/io/soluble/pjb/servlet/fastcgi/FastCGIServlet.java
similarity index 90%
rename from server/php/java/servlet/fastcgi/FastCGIServlet.java
rename to src/main/java/io/soluble/pjb/servlet/fastcgi/FastCGIServlet.java
index 841392e..80c7d1f 100644
--- a/server/php/java/servlet/fastcgi/FastCGIServlet.java
+++ b/src/main/java/io/soluble/pjb/servlet/fastcgi/FastCGIServlet.java
@@ -1,5 +1,5 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet.fastcgi;
+package io.soluble.pjb.servlet.fastcgi;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -37,19 +37,19 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.Util;
-import php.java.bridge.http.AbstractChannelName;
-import php.java.bridge.http.FCGIConnectException;
-import php.java.bridge.http.FCGIConnectionException;
-import php.java.bridge.http.FCGIConnectionPool;
-import php.java.bridge.http.FCGIInputStream;
-import php.java.bridge.http.FCGIOutputStream;
-import php.java.bridge.http.FCGIUtil;
-import php.java.bridge.http.IContextFactory;
-import php.java.servlet.ContextLoaderListener;
-import php.java.servlet.PhpJavaServlet;
-import php.java.servlet.ServletContextFactory;
-import php.java.servlet.ServletUtil;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.AbstractChannelName;
+import io.soluble.pjb.bridge.http.FCGIConnectException;
+import io.soluble.pjb.bridge.http.FCGIConnectionException;
+import io.soluble.pjb.bridge.http.FCGIConnectionPool;
+import io.soluble.pjb.bridge.http.FCGIInputStream;
+import io.soluble.pjb.bridge.http.FCGIOutputStream;
+import io.soluble.pjb.bridge.http.FCGIUtil;
+import io.soluble.pjb.bridge.http.IContextFactory;
+import io.soluble.pjb.servlet.ContextLoaderListener;
+import io.soluble.pjb.servlet.PhpJavaServlet;
+import io.soluble.pjb.servlet.ServletContextFactory;
+import io.soluble.pjb.servlet.ServletUtil;
/**
* A CGI Servlet which connects to a FastCGI server. If allowed by the
@@ -67,7 +67,7 @@
* ",htmlspecialchars($key,ENT_COMPAT)));
+}
+function writePairBegin_n($key) {
+$this->write(sprintf(" ",$key));
+}
+function writePairBegin() {
+$this->write(" ");
+}
+function writePairEnd() {
+$this->write(" ",htmlspecialchars($key,ENT_COMPAT)));
+}
+function writePairBegin_n($key) {
+$this->write(sprintf(" ",$key));
+}
+function writePairBegin() {
+$this->write(" ");
+}
+function writePairEnd() {
+$this->write("
* and then start the PHP/Java Bridge:java -classpath
* /usr/share/java/log4j.jar org.apache.log4j.chainsaw.Main
- *
+ * java -classpath /usr/share/java/log4j.jar:/usr/share/java/JavaBridge.jar php.java.bridge.JavaBridge
* or set the PHP .ini option java -classpath /usr/share/java/log4j.jar:/usr/share/java/JavaBridge.jar io.soluble.pjb.bridge.JavaBridge
.
*/
public class ChainsawLogger extends SimpleLog4jLogger implements ILogger {
@@ -89,8 +89,7 @@ protected void init() throws Exception {
/**
* Create a new chainsaw logger.
*
- * @throws UnknownHostException If the host does not exist.
- * @see php.java.bridge.Util#setDefaultLogger(ILogger)
+ * @see io.soluble.pjb.bridge.Util#setDefaultLogger(ILogger)
*/
protected ChainsawLogger() {
super();
@@ -101,7 +100,7 @@ protected ChainsawLogger() {
*
* @return The chainsaw logger
* @throws Exception If chainsaw isn't running.
- * @see php.java.bridge.Util#setDefaultLogger(ILogger)
+ * @see io.soluble.pjb.bridge.Util#setDefaultLogger(ILogger)
*/
public static ChainsawLogger createChainsawLogger() throws Exception {
ChainsawLogger logger = new ChainsawLogger();
diff --git a/server/php/java/bridge/ConstructorCache.java b/src/main/java/io/soluble/pjb/bridge/ConstructorCache.java
similarity index 99%
rename from server/php/java/bridge/ConstructorCache.java
rename to src/main/java/io/soluble/pjb/bridge/ConstructorCache.java
index 8cd14da..65671af 100644
--- a/server/php/java/bridge/ConstructorCache.java
+++ b/src/main/java/io/soluble/pjb/bridge/ConstructorCache.java
@@ -22,7 +22,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
import java.lang.reflect.Constructor;
import java.util.HashMap;
diff --git a/server/php/java/bridge/DefaultOptions.java b/src/main/java/io/soluble/pjb/bridge/DefaultOptions.java
similarity index 95%
rename from server/php/java/bridge/DefaultOptions.java
rename to src/main/java/io/soluble/pjb/bridge/DefaultOptions.java
index 9d97392..489faef 100644
--- a/server/php/java/bridge/DefaultOptions.java
+++ b/src/main/java/io/soluble/pjb/bridge/DefaultOptions.java
@@ -1,8 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -25,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
/**
* Exposes the request options. There is one Options instance for each request, but certain options may change for each packet.
* For example if a user calls java_set_file_encoding(enc), the new file encoding becomes available in the next packet.
@@ -34,14 +31,17 @@
final class DefaultOptions extends Options {
+ @Override
public boolean base64Data() {
return true;
}
+ @Override
public boolean preferValues() {
return true;
}
+ @Override
public boolean passContext() {
return false;
}
diff --git a/server/php/java/bridge/FileLogger.java b/src/main/java/io/soluble/pjb/bridge/FileLogger.java
similarity index 96%
rename from server/php/java/bridge/FileLogger.java
rename to src/main/java/io/soluble/pjb/bridge/FileLogger.java
index 129bab1..b26bd86 100644
--- a/server/php/java/bridge/FileLogger.java
+++ b/src/main/java/io/soluble/pjb/bridge/FileLogger.java
@@ -22,7 +22,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
import java.io.FileNotFoundException;
import java.util.Date;
@@ -86,7 +86,7 @@ public void log(String s) {
}
/* (non-Javadoc)
- * @see php.java.bridge.ILogger#printStackTrace(java.lang.Throwable)
+ * @see io.soluble.pjb.bridge.ILogger#printStackTrace(java.lang.Throwable)
*/
public void printStackTrace(Throwable t) {
if (!isInit) init();
@@ -101,7 +101,7 @@ public void printStackTrace(Throwable t) {
}
/* (non-Javadoc)
- * @see php.java.bridge.ILogger#log(int, java.lang.String)
+ * @see io.soluble.pjb.bridge.ILogger#log(int, java.lang.String)
*/
public void log(int level, String msg) {
StringBuffer b = new StringBuffer(now());
diff --git a/server/php/java/bridge/GlobalRef.java b/src/main/java/io/soluble/pjb/bridge/GlobalRef.java
similarity index 99%
rename from server/php/java/bridge/GlobalRef.java
rename to src/main/java/io/soluble/pjb/bridge/GlobalRef.java
index a4cdc85..229b01f 100644
--- a/server/php/java/bridge/GlobalRef.java
+++ b/src/main/java/io/soluble/pjb/bridge/GlobalRef.java
@@ -22,7 +22,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/**
* A global array of object references that the client keeps during
diff --git a/server/php/java/bridge/HexOutputBuffer.java b/src/main/java/io/soluble/pjb/bridge/HexOutputBuffer.java
similarity index 98%
rename from server/php/java/bridge/HexOutputBuffer.java
rename to src/main/java/io/soluble/pjb/bridge/HexOutputBuffer.java
index d544d81..6ad8862 100644
--- a/server/php/java/bridge/HexOutputBuffer.java
+++ b/src/main/java/io/soluble/pjb/bridge/HexOutputBuffer.java
@@ -1,6 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -23,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
diff --git a/server/php/java/bridge/IDocHandler.java b/src/main/java/io/soluble/pjb/bridge/IDocHandler.java
similarity index 89%
rename from server/php/java/bridge/IDocHandler.java
rename to src/main/java/io/soluble/pjb/bridge/IDocHandler.java
index a52dccf..3ad820f 100644
--- a/server/php/java/bridge/IDocHandler.java
+++ b/src/main/java/io/soluble/pjb/bridge/IDocHandler.java
@@ -1,5 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -22,7 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
import java.io.IOException;
import java.io.InputStream;
@@ -41,7 +39,7 @@ public interface IDocHandler {
* @return true, if the parser should stop after reading the top-level end tag, false otherwise.
* Implements a short path: Set this to true, if you already know that the current top-level request doesn't need a reply.
*/
- public boolean begin(ParserTag[] tag);
+ boolean begin(ParserTag[] tag);
/**
* Called for each </tag>
@@ -49,7 +47,7 @@ public interface IDocHandler {
* @param strings The tag and the args.
* @see IDocHandler#begin(ParserTag[])
*/
- public void end(ParserString[] strings);
+ void end(ParserString[] strings);
/**
* Called for the header
@@ -57,7 +55,7 @@ public interface IDocHandler {
* @param in the input stream
* @throws IOException
*/
- public void parseHeader(InputStream in) throws IOException;
+ void parseHeader(InputStream in) throws IOException;
}
diff --git a/server/php/java/bridge/IJavaBridgeFactory.java b/src/main/java/io/soluble/pjb/bridge/IJavaBridgeFactory.java
similarity index 93%
rename from server/php/java/bridge/IJavaBridgeFactory.java
rename to src/main/java/io/soluble/pjb/bridge/IJavaBridgeFactory.java
index d44c74e..5ba6281 100644
--- a/server/php/java/bridge/IJavaBridgeFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/IJavaBridgeFactory.java
@@ -1,8 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -25,10 +20,12 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.IOException;
import java.io.InputStream;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.http.IContext;
/**
* Create {@link JavaBridge}, {@link IContext} and {@link ISession} instances.
@@ -42,7 +39,7 @@ public interface IJavaBridgeFactory {
* @param clientIsNew one of {@link ISession#SESSION_CREATE_NEW} {@link ISession#SESSION_GET_OR_CREATE} or {@link ISession#SESSION_GET}
* @param timeout timeout in seconds. If 0 the session does not expire.
* @return The session
- * @see php.java.bridge.ISession
+ * @see io.soluble.pjb.bridge.ISession
*/
public ISession getSession(String name, short clientIsNew, int timeout);
@@ -50,7 +47,7 @@ public interface IJavaBridgeFactory {
* Return the associated JSR223 context
*
* @return The JSR223 context, if supported by the environment or null.
- * @see php.java.bridge.http.ContextFactory#getContext()
+ * @see io.soluble.pjb.bridge.http.ContextFactory#getContext()
*/
public IContext getContext();
diff --git a/server/php/java/bridge/ILogger.java b/src/main/java/io/soluble/pjb/bridge/ILogger.java
similarity index 77%
rename from server/php/java/bridge/ILogger.java
rename to src/main/java/io/soluble/pjb/bridge/ILogger.java
index a0f8840..7d25ef9 100644
--- a/server/php/java/bridge/ILogger.java
+++ b/src/main/java/io/soluble/pjb/bridge/ILogger.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,39 +20,41 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
/**
* The log interface for the PHP/Java Bridge log.
*
* @author jostb
- * @see php.java.bridge.FileLogger
- * @see php.java.bridge.ChainsawLogger
- * @see php.java.bridge.SimpleLog4jLogger
+ * @see io.soluble.pjb.bridge.FileLogger
+ * @see io.soluble.pjb.bridge.ChainsawLogger
+ * @see io.soluble.pjb.bridge.SimpleLog4jLogger
*/
public interface ILogger {
/**
* fatal log level
*/
- public static final int FATAL = 1;
+ static final int FATAL = 1;
/**
* error log level
*/
- public static final int ERROR = 2;
+ static final int ERROR = 2;
/**
* info log level
*/
- public static final int INFO = 3;
+ static final int INFO = 3;
/**
* debug log level
*/
- public static final int DEBUG = 4;
+ static final int DEBUG = 4;
/**
* Log a stack trace
*
* @param t The Throwable
*/
- public void printStackTrace(Throwable t);
+ void printStackTrace(Throwable t);
/**
* Log a message.
@@ -64,12 +62,12 @@ public interface ILogger {
* @param level The log level 0: FATAL, 1:ERROR, 2: INFO, 3: DEBUG
* @param msg The message
*/
- public void log(int level, String msg);
+ void log(int level, String msg);
/**
- * Display a warning if logLevel >= 1
+ * Display a warning if logLevel >= 1
*
* @param msg The warn message
*/
- public void warn(String msg);
+ void warn(String msg);
}
diff --git a/server/php/java/bridge/IManaged.java b/src/main/java/io/soluble/pjb/bridge/IManaged.java
similarity index 94%
rename from server/php/java/bridge/IManaged.java
rename to src/main/java/io/soluble/pjb/bridge/IManaged.java
index faa174e..0fa5334 100644
--- a/server/php/java/bridge/IManaged.java
+++ b/src/main/java/io/soluble/pjb/bridge/IManaged.java
@@ -1,8 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
-
/*
* Copyright (C) 2003-2009 Jost Boekemeier
*
@@ -25,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
/**
* Classes which implement this interface receive a notification before their container terminates.
* This usually happens when the ContextLoaderListener.contextDestroyed(javax.servlet.ServletContextEvent)
@@ -35,7 +32,7 @@
public interface IManaged {
/**
- * Initialize a library. This method may be called via java_context()->init(...)
+ * Initialize a library. This method may be called via java_context()->init(...)
* to initialize a library. Within init() onShutdown() may be called to
* register a shutdown hook for the library.
*
@@ -46,7 +43,7 @@ public interface IManaged {
public Object init(Object callable) throws Exception;
/**
- * Register a shutdown hook for the library. This method may be called via java_context()->onShutdown(...)
+ * Register a shutdown hook for the library. This method may be called via java_context()->onShutdown(...)
* to register a shutdown hook during init().
*
* @param closeable Its close() method will be called before the context or the VM terminates.
diff --git a/server/php/java/bridge/ISession.java b/src/main/java/io/soluble/pjb/bridge/ISession.java
similarity index 99%
rename from server/php/java/bridge/ISession.java
rename to src/main/java/io/soluble/pjb/bridge/ISession.java
index 8f04d0f..f96b758 100644
--- a/server/php/java/bridge/ISession.java
+++ b/src/main/java/io/soluble/pjb/bridge/ISession.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.util.Map;
/**
diff --git a/server/php/java/bridge/ISocketFactory.java b/src/main/java/io/soluble/pjb/bridge/ISocketFactory.java
similarity index 96%
rename from server/php/java/bridge/ISocketFactory.java
rename to src/main/java/io/soluble/pjb/bridge/ISocketFactory.java
index 785a155..e11d42c 100644
--- a/server/php/java/bridge/ISocketFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/ISocketFactory.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.IOException;
import java.net.Socket;
diff --git a/server/php/java/bridge/IntegerComparator.java b/src/main/java/io/soluble/pjb/bridge/IntegerComparator.java
similarity index 89%
rename from server/php/java/bridge/IntegerComparator.java
rename to src/main/java/io/soluble/pjb/bridge/IntegerComparator.java
index 83f94a5..ba688e2 100644
--- a/server/php/java/bridge/IntegerComparator.java
+++ b/src/main/java/io/soluble/pjb/bridge/IntegerComparator.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,12 +20,15 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.util.Comparator;
final class IntegerComparator implements Comparator {
+ @Override
public int compare(Object arg0, Object arg1) {
- int k0 = ((Integer) arg0).intValue();
- int k1 = ((Integer) arg1).intValue();
+ int k0 = ((Integer) arg0);
+ int k1 = ((Integer) arg1);
if (k0 < k1) return -1;
else if (k0 > k1) return 1;
return 0;
diff --git a/server/php/java/bridge/Invocable.java b/src/main/java/io/soluble/pjb/bridge/Invocable.java
similarity index 89%
rename from server/php/java/bridge/Invocable.java
rename to src/main/java/io/soluble/pjb/bridge/Invocable.java
index 9b64de4..5a5052e 100644
--- a/server/php/java/bridge/Invocable.java
+++ b/src/main/java/io/soluble/pjb/bridge/Invocable.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -33,8 +33,8 @@
* java.log_file=@127.0.0.1:4445
*
* @author jostb
- * @see php.java.bridge.PhpProcedure#invoke(Object, String, Object[])
- * @see php.java.bridge.PhpProcedure#invoke(Object, java.lang.reflect.Method, Object[])
+ * @see io.soluble.pjb.bridge.PhpProcedure#invoke(Object, String, Object[])
+ * @see io.soluble.pjb.bridge.PhpProcedure#invoke(Object, java.lang.reflect.Method, Object[])
*/
public interface Invocable {
diff --git a/server/php/java/bridge/JavaBridge.java b/src/main/java/io/soluble/pjb/bridge/JavaBridge.java
similarity index 72%
rename from server/php/java/bridge/JavaBridge.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridge.java
index 46f0c2f..63fca89 100644
--- a/server/php/java/bridge/JavaBridge.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridge.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier and others.
*
@@ -23,6 +19,7 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
import java.beans.BeanInfo;
import java.beans.Introspector;
@@ -50,28 +47,38 @@
import java.util.Map.Entry;
/**
- * This is the main interface of the PHP/Java Bridge. It
- * contains utility methods which can be used by clients.
+ * This is the main interface of the PHP/Java Bridge. It contains utility methods which can be used by clients.
*
* @author Sam Ruby (methods coerce and select)
* @author Kai Londenberg
* @author Jost Boekemeier
- * @see php.java.bridge.Standalone
- * @see php.java.servlet.PhpJavaServlet
+ * @see io.soluble.pjb.bridge.Standalone
+ * @see io.soluble.pjb.servlet.PhpJavaServlet
*/
-public class JavaBridge implements Runnable {
+public final class JavaBridge implements Runnable {
+
+ static final int DISPLAY_MAX_ELEMENTS = 10;
+ static final int DISPLAY_MAX_CHARS = 80;
+ static final String PHPSESSION = "PHPSESSION";
+ static final String INTERNAL_PHPSESSION = "INTERNAL_PHPSESSION";
+ static final HashMap SESSION_HASH = new HashMap();
+
+ private final MethodCache methodCache = new MethodCache();
+ private final ConstructorCache constructorCache = new ConstructorCache();
+ boolean canModifySecurityPermission = true; // false if we detect that setAccessible is not possible
+ StringCache stringCache = new StringCache(this);
+ Options options;
+
/**
* For PHP4's last_exception_get.
*/
- public Throwable lastException = null;
- protected Throwable lastAsyncException; // reported by end_document()
+ Throwable lastException = null;
+ Throwable lastAsyncException; // reported by end_document()
// array of objects in use in the current script
GlobalRef globalRef = new GlobalRef();
- static HashMap sessionHash = new HashMap();
-
/**
* For internal use only. The input stream for the current channel.
*/
@@ -86,6 +93,19 @@ public class JavaBridge implements Runnable {
*/
public int logLevel = Util.logLevel;
+ /**
+ * For internal use only. The current request (if any)
+ */
+ public Request request;
+
+
+ /**
+ * For internal use only.
+ */
+ private IJavaBridgeFactory sessionFactory;
+ private Object o[] = new Object[1];
+ private Class c[] = new Class[1];
+
/**
* Return the log level:
*
@@ -105,19 +125,23 @@ public int getLogLevel() {
/**
* Handle requests from the InputStream, write the responses to OutputStream
*
- * @param in the InputStream
- * @param out the OutputStream
- * @param logger the default logger can be obtained via getServletContext().getAttribute(ContextLoaderListener.LOGGER)
+ * @param in the InputStream
+ * @param out the OutputStream
+ * @param logger the default logger can be obtained via
+ * getServletContext().getAttribute(ContextLoaderListener.LOGGER)
* @throws IOException
* @deprecated Example:
*
*
@@ -129,20 +153,23 @@ public void handleRequests(InputStream in, OutputStream out, ILogger logger) thr
/**
* Handle requests from the InputStream, write the responses to OutputStream
*
- * @param in the InputStream
+ * @param in the InputStream
* @param out the OutputStream
* @throws IOException Example:
- *
- * protected void doPut (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
*
- * IContextFactory ctx = new RemoteHttpServletContextFactory(this, getServletContext(), req, req, resr);
+ * protected void doPut (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ *
+ * IContextFactory ctx = new RemoteHttpServletContextFactory(this, getServletContext(), req, req,
+ * resr);
* res.setHeader("X_JAVABRIDGE_CONTEXT", ctx.getId());
* res.setHeader("Pragma", "no-cache");
* res.setHeader("Cache-Control", "no-cache");
- * try { ctx.getBridge().handleRequests(req.getInputStream(), res.getOutputStream(), myLogge); } finally { ctx.destroy(); }
+ * try { ctx.getBridge().handleRequests(req.getInputStream(), res.getOutputStream(), myLogge); } finally
+ * { ctx.destroy(); }
* }
*
- *
+ *
- * protected void doPut (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
- *
- * IContextFactory ctx = new RemoteHttpServletContextFactory(this, getServletContext(), req, req, resr);
- * res.setHeader("X_JAVABRIDGE_CONTEXT", ctx.getId());
- * res.setHeader("Pragma", "no-cache");
- * res.setHeader("Cache-Control", "no-cache");
- * try { ctx.getBridge().handleRequests(req.getInputStream(), res.getOutputStream(), myLogge); } finally { ctx.destroy(); }
- * }
- *
+ *
*/
public void handleRequests(InputStream in, OutputStream out) throws IOException {
this.request = new Request(this);
@@ -157,34 +184,18 @@ public void handleRequests(InputStream in, OutputStream out) throws IOException
}
- /**
- * For internal use only. The current request (if any)
- */
- public Request request;
-
- // false if we detect that setAccessible is not possible
- boolean canModifySecurityPermission = true;
- private MethodCache methodCache = new MethodCache();
- private ConstructorCache constructorCache = new ConstructorCache();
- StringCache stringCache = new StringCache(this);
-
- /**
- * For internal use only.
- */
- private IJavaBridgeFactory sessionFactory;
-
/**
* Return the session/jsr223 factory associated with this bridge
*
* @return The session/jsr223 factory
*/
public IJavaBridgeFactory getFactory() {
- if (sessionFactory == null) throw new NullPointerException("session factory");
+ if (sessionFactory == null) {
+ throw new NullPointerException("session factory");
+ }
return sessionFactory;
}
- Options options;
-
/**
* Returns the connection options
*
@@ -194,7 +205,6 @@ public Options getOptions() {
return options;
}
-
/**
* Communication with client in a new thread
*/
@@ -204,7 +214,9 @@ public void run() {
request = new Request(this);
try {
- if (!request.init(in, out)) return;
+ if (!request.init(in, out)) {
+ return;
+ }
} catch (Throwable e) {
printStackTrace(e);
return;
@@ -221,15 +233,19 @@ public void run() {
} catch (Exception t) {
printStackTrace(t);
} finally {
- if (in != null) try {
- in.close();
- } catch (IOException e1) {
- printStackTrace(e1);
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e1) {
+ printStackTrace(e1);
+ }
}
- if (out != null) try {
- out.close();
- } catch (IOException e2) {
- printStackTrace(e2);
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e2) {
+ printStackTrace(e2);
+ }
}
sessionFactory.destroy();
}
@@ -247,11 +263,9 @@ public static ISocketFactory bind(String sockname) throws IOException {
}
/**
- * Global init. Redirects System.out and System.err to the server
- * log file(s) or to System.err and creates and opens the
- * communcation channel. Note: Do not write anything to
- * System.out, this stream is connected with a pipe which waits
- * for the channel name.
+ * Global init. Redirects System.out and System.err to the server log file(s) or to System.err and creates and opens
+ * the communcation channel. Note: Do not write anything to System.out, this stream is connected with a pipe which
+ * waits for the channel name.
*
* @param s an array of [socketname, level, logFile]
*/
@@ -263,7 +277,9 @@ public static void init(String s[]) {
static void initLog(String socket, int logLevel, String s[]) {
String logFile = null, rawLogFile = null;
- if (logLevel == -1) logLevel = Util.DEFAULT_LOG_LEVEL;
+ if (logLevel == -1) {
+ logLevel = Util.DEFAULT_LOG_LEVEL;
+ }
Util.logLevel = logLevel;
try {
@@ -271,11 +287,14 @@ static void initLog(String socket, int logLevel, String s[]) {
rawLogFile = logFile = s.length > 0 ? "" : Util.DEFAULT_LOG_FILE;
if (s.length > 2) {
rawLogFile = logFile = s[2];
- if (Util.setConfiguredLogger(logFile))
+ if (Util.setConfiguredLogger(logFile)) {
logFile = null; // when log4j is used, System.out and System.err are not redirected
- else
+ } else {
Util.setDefaultLogger(new FileLogger()); // use specified log file
- if (Util.logLevel > 3) System.err.println(Util.EXTENSION_NAME + " log: " + rawLogFile);
+ }
+ if (Util.logLevel > 3) {
+ System.err.println(Util.EXTENSION_NAME + " log: " + rawLogFile);
+ }
}
} catch (Throwable t) {
t.printStackTrace();
@@ -283,13 +302,14 @@ static void initLog(String socket, int logLevel, String s[]) {
Util.redirectOutput(logFile);
Util.logMessage("VM : " + Util.VM_NAME);
- if (Util.VERSION != null)
+ if (Util.VERSION != null) {
Util.logMessage(Util.EXTENSION_NAME + " version : " + Util.VERSION);
+ }
Util.logMessage("logFile : " + rawLogFile);
Util.logMessage("default logLevel : " + Util.logLevel);
Util.logMessage("socket : " + socket);
Util.logMessage("java.ext.dirs : " + System.getProperty("java.ext.dirs"));
- Util.logMessage("php.java.bridge.base: " + Util.JAVABRIDGE_BASE);
+ Util.logMessage("io.soluble.pjb.bridge.base: " + Util.JAVABRIDGE_BASE);
Util.logMessage("thread pool size : " + Util.THREAD_POOL_MAX_SIZE);
} catch (Throwable t) {
throw new RuntimeException(t);
@@ -304,7 +324,7 @@ static void init(ISocketFactory socket, int logLevel, String s[]) {
String policy = System.getProperty("java.security.policy");
String base = Util.JAVABRIDGE_BASE;
if (policy != null && base != null) {
- SecurityManager manager = new php.java.bridge.JavaBridgeSecurityManager();
+ SecurityManager manager = new JavaBridgeSecurityManager();
System.setSecurityManager(manager);
Util.logMessage(Util.EXTENSION_NAME + " policy base : " + base);
Util.logMessage(Util.EXTENSION_NAME + " security policy : " + policy);
@@ -333,7 +353,7 @@ static void init(ISocketFactory socket, int logLevel, String s[]) {
}
}
- } catch (Throwable t) {
+ } catch (IOException t) {
throw new RuntimeException(t);
}
}
@@ -342,28 +362,24 @@ static void init(ISocketFactory socket, int logLevel, String s[]) {
* Start the PHP/Java Bridge.
+ * protected void doPut (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ *
+ *
+ * IContextFactory ctx = new RemoteHttpServletContextFactory(this, getServletContext(), req, req,
+ * resr);
+ * res.setHeader("X_JAVABRIDGE_CONTEXT", ctx.getId());
+ * res.setHeader("Pragma", "no-cache");
+ * res.setHeader("Cache-Control", "no-cache");
+ * try { ctx.getBridge().handleRequests(req.getInputStream(), res.getOutputStream(), myLogge); } finally
+ * { ctx.destroy(); }
+ * }
+ *
* Example:
* java -Djava.awt.headless=true -jar JavaBridge.jar INET:9656 5 /var/log/php-java-bridge.log
- * Note: Do not write anything to System.out, this
- * stream is connected with a pipe which waits for the channel name.
+ * Note: Do not write anything to System.out, this stream is connected with a pipe which waits for the channel name.
*
- * @param s an array of [socketname, level, logFile]
- * Use Standalone.main()
- * @see php.java.bridge.Standalone#main(String[])
+ * @param s an array of [socketname, level, logFile] Use Standalone.main()
+ * @see io.soluble.pjb.bridge.Standalone#main(String[])
*/
public static void main(String s[]) {
Standalone.main(s);
}
-
/**
* Print a stack trace to the log file.
*
* @param t the throwable
*/
public void printStackTrace(Throwable t) {
- if (logLevel > 0)
- if ((t instanceof Error) || logLevel > 1) {
- Util.getLogger().printStackTrace(t);
- }
+ if (logLevel > 0 && ((t instanceof Error) || logLevel > 1)) {
+ Util.getLogger().printStackTrace(t);
+ }
}
private String getId() {
@@ -376,7 +392,9 @@ private String getId() {
* @param msg The message
*/
public void logDebug(String msg) {
- if (logLevel > 3) Util.println(4, getId() + " " + msg);
+ if (logLevel > 3) {
+ Util.println(4, getId() + " " + msg);
+ }
}
/**
@@ -385,7 +403,9 @@ public void logDebug(String msg) {
* @param msg The message
*/
public void logFatal(String msg) {
- if (logLevel > 0) Util.println(1, getId() + " " + msg);
+ if (logLevel > 0) {
+ Util.println(1, getId() + " " + msg);
+ }
}
/**
@@ -394,7 +414,9 @@ public void logFatal(String msg) {
* @param msg The message
*/
public void logError(String msg) {
- if (logLevel > 1) Util.println(2, getId() + " " + msg);
+ if (logLevel > 1) {
+ Util.println(2, getId() + " " + msg);
+ }
}
/**
@@ -403,7 +425,9 @@ public void logError(String msg) {
* @param msg The message
*/
public void logMessage(String msg) {
- if (logLevel > 2) Util.println(3, getId() + " " + msg);
+ if (logLevel > 2) {
+ Util.println(3, getId() + " " + msg);
+ }
}
/**
@@ -412,14 +436,20 @@ public void logMessage(String msg) {
* @param msg The warning.
*/
public void warn(String msg) {
- if (logLevel > 0) Util.warn(getId() + " " + msg);
+ if (logLevel > 0) {
+ Util.warn(getId() + " " + msg);
+ }
}
void setException(Response response, Throwable e, String method, Object obj, String name, Object args[], Class params[], boolean hasDeclaredExceptions) {
if (e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException) e).getTargetException();
- if (t != null) e = t;
- if (logLevel > 3 || (!options.preferValues() && !hasDeclaredExceptions)) printStackTrace(e);
+ if (t != null) {
+ e = t;
+ }
+ if (logLevel > 3 || (!options.preferValues() && !hasDeclaredExceptions)) {
+ printStackTrace(e);
+ }
} else {
printStackTrace(e);
}
@@ -448,26 +478,28 @@ void setException(Response response, Throwable e, String method, Object obj, Str
lastException = new Exception(buf.toString(), e);
StackTraceElement[] trace = e.getStackTrace();
- if (trace != null) lastException.setStackTrace(trace);
+ if (trace != null) {
+ lastException.setStackTrace(trace);
+ }
response.setResultException(lastException, hasDeclaredExceptions);
}
private Exception getUnresolvedExternalReferenceException(Throwable e, String what) {
- return new ClassNotFoundException("Unresolved external reference: " + e + ". -- " +
- "Unable to " + what + ", see the README section \"Java platform issues\" " +
- "for details and DO NOT REPORT THIS PROBLEM TO THE PHP/Java Bridge MAILING LIST!", e);
+ return new ClassNotFoundException("Unresolved external reference: " + e + ". -- "
+ + "Unable to " + what + ", see the README section \"Java platform issues\" "
+ + "for details and DO NOT REPORT THIS PROBLEM TO THE PHP/Java Bridge MAILING LIST!", e);
}
/**
* Create an new instance of a given class, to be called by clients.
*
- * @param name The class name
+ * @param name The class name
* @param createInstance true if we should create an instance, false otherwise
- * @param args The argument array
- * @param response The response writer
+ * @param args The argument array
+ * @param response The response writer
*/
public void CreateObject(String name, boolean createInstance,
- Object args[], Response response) {
+ Object args[], Response response) {
Class params[] = null;
LinkedList candidates = new LinkedList();
LinkedList matches = new LinkedList();
@@ -483,23 +515,25 @@ public void CreateObject(String name, boolean createInstance,
selected = constructorCache.get(entry);
if (selected == null) {
Constructor cons[] = clazz.getConstructors();
- for (int i = 0; i < cons.length; i++) {
- candidates.add(cons[i]);
- if (cons[i].getParameterTypes().length == args.length) {
- matches.add(cons[i]);
+ for (Constructor con : cons) {
+ candidates.add(con);
+ if (con.getParameterTypes().length == args.length) {
+ matches.add(con);
}
}
selected = (Constructor) select(matches, args);
- if (selected != null) constructorCache.put(entry, selected);
+ if (selected != null) {
+ constructorCache.put(entry, selected);
+ }
}
}
if (selected == null) {
if (args.length > 0) {
- throw createInstance ?
- (Exception) new InstantiationException("No matching constructor found. " + "Candidates: " + String.valueOf(candidates)) :
- (Exception) new JavaBridgeIllegalArgumentException("ReferenceClass must be called w/o arguments; either write new JavaClass(\"" + name + "\") or new Java(\"" + name + "\", args...).");
+ throw createInstance
+ ? (Exception) new InstantiationException("No matching constructor found. " + "Candidates: " + String.valueOf(candidates))
+ : (Exception) new JavaBridgeIllegalArgumentException("ReferenceClass must be called w/o arguments; either write new JavaClass(\"" + name + "\") or new Java(\"" + name + "\", args...).");
} else {
// for classes which have no visible constructor, return the class
// useful for classes like java.lang.System and java.util.Calendar.
@@ -511,7 +545,7 @@ public void CreateObject(String name, boolean createInstance,
}
}
- Object coercedArgs[] = coerce(params = entry.getParameterTypes(selected), args, response);
+ Object coercedArgs[] = coerce(params = entry.getParameterTypes(selected), args, response); //TODO possible null pointer
// If we have a logLevel of 5 or above, do very detailed invocation logging
hasDeclaredExceptions = selected.getExceptionTypes().length != 0;
if (this.logLevel > 4) {
@@ -523,7 +557,9 @@ public void CreateObject(String name, boolean createInstance,
}
} catch (Throwable e) {
Throwable e1 = e;
- if (e1 instanceof InvocationTargetException) e1 = ((InvocationTargetException) e1).getTargetException();
+ if (e1 instanceof InvocationTargetException) {
+ e1 = ((InvocationTargetException) e1).getTargetException();
+ }
if (e1 instanceof Request.AbortException) {
throw (Request.AbortException) e1;
}
@@ -546,8 +582,8 @@ public void CreateObject(String name, boolean createInstance,
private int weight(Class param, Class arg, Object phpArrayValue) {
int w = 0;
if (param.isAssignableFrom(arg)) {
- for (Class c = arg; (c = c.getSuperclass()) != null; ) {
- if (!param.isAssignableFrom(c)) {
+ for (Class clazz = arg; (clazz = clazz.getSuperclass()) != null;) {
+ if (!param.isAssignableFrom(clazz)) {
break;
}
w += 16; // prefer more specific arg, for
@@ -555,18 +591,21 @@ private int weight(Class param, Class arg, Object phpArrayValue) {
// over Object hashMap.
}
} else if (param == java.lang.String.class) {
- if (!(String.class.isAssignableFrom(arg)) && !(PhpString.class.isAssignableFrom(arg)))
- if (byte[].class.isAssignableFrom(arg))
+ if (!(String.class.isAssignableFrom(arg)) && !(PhpString.class.isAssignableFrom(arg))) {
+ if (byte[].class.isAssignableFrom(arg)) {
w += 32;
- else
+ } else {
w += 8000; // conversion to string is always possible
+ }
+ }
} else if (param.isArray()) {
if (PhpString.class.isAssignableFrom(arg)) {
- Class c = param.getComponentType();
- if (c == byte.class)
+ Class clazz = param.getComponentType();
+ if (clazz == byte.class) {
w += 32;
- else
+ } else {
w += 9999;
+ }
} else if (arg == PhpArray.class) {
Iterator iterator = phpArrayValue == null ? EMPTY_ITERATOR : ((Map) phpArrayValue).values().iterator();
if (iterator.hasNext()) {
@@ -581,30 +620,51 @@ private int weight(Class param, Class arg, Object phpArrayValue) {
if (ptype != atype) {
w += (ptype == Object.class ? 10 : 8200) + weight(ptype, atype, null);
}
- } else w += 9999;
+ } else {
+ w += 9999;
+ }
} else if ((java.util.Collection.class).isAssignableFrom(param)) {
- if (java.util.Map.class.isAssignableFrom(arg)) w += 8100; // conversion to Collection is always possible
- else if (!(PhpArray.class.isAssignableFrom(arg))) w += 9999;
+ if (java.util.Map.class.isAssignableFrom(arg)) {
+ w += 8100; // conversion to Collection is always possible
+ } else if (!(PhpArray.class.isAssignableFrom(arg))) {
+ w += 9999;
+ }
} else if (param.isPrimitive()) {
- Class c = param;
+ Class clazz = param;
if (Number.class.isAssignableFrom(arg)) {
if (Double.class.isAssignableFrom(arg)) {
- if (c == Float.TYPE) w += 1;
- else if (c == Double.TYPE) w += 0;
- else w += 256;
+ if (clazz == Float.TYPE) {
+ w += 1;
+ } else if (clazz == Double.TYPE) {
+ w += 0;
+ } else {
+ w += 256;
+ }
} else {
- if (c == Boolean.TYPE) w += 5;
- else if (c == Character.TYPE) w += 4;
- else if (c == Byte.TYPE) w += 3;
- else if (c == Short.TYPE) w += 2;
- else if (c == Integer.TYPE) w += 1;
- else if (c == Long.TYPE) w += 0;
- else w += 256;
+ if (clazz == Boolean.TYPE) {
+ w += 5;
+ } else if (clazz == Character.TYPE) {
+ w += 4;
+ } else if (clazz == Byte.TYPE) {
+ w += 3;
+ } else if (clazz == Short.TYPE) {
+ w += 2;
+ } else if (clazz == Integer.TYPE) {
+ w += 1;
+ } else if (clazz == Long.TYPE) {
+ w += 0;
+ } else {
+ w += 256;
+ }
}
} else if (Boolean.class.isAssignableFrom(arg)) {
- if (c != Boolean.TYPE) w += 9999;
+ if (clazz != Boolean.TYPE) {
+ w += 9999;
+ }
} else if (Character.class.isAssignableFrom(arg)) {
- if (c != Character.TYPE) w += 9999;
+ if (clazz != Character.TYPE) {
+ w += 9999;
+ }
} else if ((String.class.isAssignableFrom(arg)) || (PhpString.class.isAssignableFrom(arg))) {
w += 64;
} else {
@@ -612,66 +672,80 @@ private int weight(Class param, Class arg, Object phpArrayValue) {
}
} else if (Number.class.isAssignableFrom(param)) {
if (param == Float.class || param == Double.class) {
- if (!(Double.class.isAssignableFrom(arg))) w += 9999;
- } else if (!(PhpExactNumber.class.isAssignableFrom(arg))) w += 9999;
+ if (!(Double.class.isAssignableFrom(arg))) {
+ w += 9999;
+ }
+ } else if (!(PhpExactNumber.class.isAssignableFrom(arg))) {
+ w += 9999;
+ }
} else {
w += 9999;
}
- if (logLevel > 4) logDebug("weight " + param + " " + arg + ": " + w);
+ if (logLevel > 4) {
+ logDebug("weight " + param + " " + arg + ": " + w);
+ }
return w;
}
private Object select(LinkedList methods, Object args[]) {
- if (methods.size() == 1) return methods.getFirst();
+ if (methods.size() == 1) {
+ return methods.getFirst();
+ }
Object similar = null, selected = null;
int best = Integer.MAX_VALUE;
- int n = 0;
-
- for (Iterator e = methods.iterator(); e.hasNext(); n++) {
+ for (Iterator e = methods.iterator(); e.hasNext();) {
Object element = e.next();
int w = 0;
- Class parms[] = (element instanceof Method) ?
- ((Method) element).getParameterTypes() :
- ((Constructor) element).getParameterTypes();
+ Class parms[] = (element instanceof Method)
+ ? ((Method) element).getParameterTypes()
+ : ((Constructor) element).getParameterTypes();
for (int i = 0; i < parms.length; i++) {
Object arg = args[i];
- if (arg != null)
+ if (arg != null) {
w += weight(parms[i], arg.getClass(), arg);
+ }
}
if (w < best) {
if (w == 0) {
- if (logLevel > 4) logDebug("Selected: " + element + " " + w);
+ if (logLevel > 4) {
+ logDebug("Selected: " + element + " " + w);
+ }
return element;
}
best = w;
selected = element;
if (logLevel > 2) {
similar = null;
- if (logLevel > 4) logDebug("best: " + selected + " " + w);
+ if (logLevel > 4) {
+ logDebug("best: " + selected + " " + w);
+ }
}
} else {
if (logLevel > 2) {
- if (w == best) similar = element;
- if (logLevel > 4) logDebug("skip: " + element + " " + w);
+ if (w == best) {
+ similar = element;
+ }
+ if (logLevel > 4) {
+ logDebug("skip: " + element + " " + w);
+ }
}
}
}
if (logLevel > 2 && similar != null) {
StringBuffer buf = new StringBuffer();
- for (int i = 0; i < args.length; i++) {
- Util.appendParam(args[i], buf);
+ for (Object arg : args) {
+ Util.appendParam(arg, buf);
}
logMessage("Portability warning: " + selected + " and " + similar + " both match " + buf.toString());
}
- if (logLevel > 4) logDebug("Selected: " + selected + " " + best);
+ if (logLevel > 4) {
+ logDebug("Selected: " + selected + " " + best);
+ }
return selected;
}
- private Object o[] = new Object[1];
- private Class c[] = new Class[1];
-
Object coerce(Class param, Object arg, Response response) {
o[0] = arg;
c[0] = param;
@@ -690,28 +764,39 @@ Object[] coerce(Class parms[], Object args[], Response response) {
int size = 0;
for (int i = 0; i < args.length; i++) {
- if ((arg = args[i]) == null) continue;
+ if ((arg = args[i]) == null) {
+ continue;
+ }
if (parms[i] == String.class) {
- if (arg instanceof PhpString)
+ if (arg instanceof PhpString) {
result[i] = ((PhpString) arg).getString();
- else
+ } else {
result[i] = arg.toString();
+ }
} else if (arg instanceof PhpString || arg instanceof String) {
if (!parms[i].isArray()) {
- Class c = parms[i];
+ Class clazz = parms[i];
String s = (arg instanceof String) ? (String) arg : ((PhpString) arg).getString();
result[i] = s;
try {
- if (c == Boolean.TYPE) result[i] = new Boolean(s);
- else if (c == Byte.TYPE) result[i] = new Byte(s);
- else if (c == Short.TYPE) result[i] = new Short(s);
- else if (c == Integer.TYPE) result[i] = new Integer(s);
- else if (c == Float.TYPE) result[i] = new Float(s);
- else if (c == Double.TYPE) result[i] = new Double(s);
- else if (c == Long.TYPE) result[i] = new Long(s);
- else if (c == Character.TYPE && s.length() > 0)
- result[i] = new Character(s.charAt(0));
+ if (clazz == Boolean.TYPE) {
+ result[i] = Boolean.valueOf(s);
+ } else if (clazz == Byte.TYPE) {
+ result[i] = new Byte(s);
+ } else if (clazz == Short.TYPE) {
+ result[i] = new Short(s);
+ } else if (clazz == Integer.TYPE) {
+ result[i] = new Integer(s);
+ } else if (clazz == Float.TYPE) {
+ result[i] = new Float(s);
+ } else if (clazz == Double.TYPE) {
+ result[i] = new Double(s);
+ } else if (clazz == Long.TYPE) {
+ result[i] = new Long(s);
+ } else if (clazz == Character.TYPE && s.length() > 0) {
+ result[i] = s.charAt(0);
+ }
} catch (NumberFormatException n) {
printStackTrace(n);
// oh well, we tried!
@@ -721,24 +806,31 @@ else if (c == Character.TYPE && s.length() > 0)
}
} else if (arg instanceof Number) {
if (parms[i].isPrimitive()) {
- Class c = parms[i];
+ Class clazz = parms[i];
Number n = (Number) arg;
- if (c == Boolean.TYPE) result[i] = new Boolean(0.0 != n.floatValue());
- else if (c == Byte.TYPE) result[i] = new Byte(n.byteValue());
- else if (c == Short.TYPE) result[i] = new Short(n.shortValue());
- else if (c == Integer.TYPE) result[i] = new Integer(n.intValue());
- else if (c == Float.TYPE) result[i] = new Float(n.floatValue());
- else if (c == Double.TYPE) result[i] = new Double(n.doubleValue());
- else if (c == Long.TYPE && !(n instanceof Long))
- result[i] = new Long(n.longValue());
+ if (clazz == Boolean.TYPE) {
+ result[i] = 0.0 != n.floatValue();
+ } else if (clazz == Byte.TYPE) {
+ result[i] = n.byteValue();
+ } else if (clazz == Short.TYPE) {
+ result[i] = n.shortValue();
+ } else if (clazz == Integer.TYPE) {
+ result[i] = n.intValue();
+ } else if (clazz == Float.TYPE) {
+ result[i] = n.floatValue();
+ } else if (clazz == Double.TYPE) {
+ result[i] = n.doubleValue();
+ } else if (clazz == Long.TYPE && !(n instanceof Long)) {
+ result[i] = n.longValue();
+ }
} else {
if (arg.getClass() == PhpExactNumber.class) {
{
- Class c = parms[i];
- if (c.isAssignableFrom(Integer.class)) {
- result[i] = new Integer(((Number) arg).intValue());
+ Class clazz = parms[i];
+ if (clazz.isAssignableFrom(Integer.class)) {
+ result[i] = ((Number) arg).intValue();
} else {
- result[i] = new Long(((Number) arg).longValue());
+ result[i] = ((Number) arg).longValue();
}
}
}
@@ -761,7 +853,7 @@ else if (c == Long.TYPE && !(n instanceof Long))
throw new JavaBridgeIllegalArgumentException("Could not create array from Map: " + firstChars(arg), ex);
}
try {
- for (Iterator ii = ht.entrySet().iterator(); ii.hasNext(); ) {
+ for (Iterator ii = ht.entrySet().iterator(); ii.hasNext();) {
e = (Entry) ii.next();
Array.set(tempArray, ((Number) (e.getKey())).intValue(), coerce(targetType, e.getValue(), response));
}
@@ -773,22 +865,26 @@ else if (c == Long.TYPE && !(n instanceof Long))
} else if ((java.util.Collection.class).isAssignableFrom(parms[i])) {
try {
Map m = (Map) arg;
- Collection c = m.values();
- if (!parms[i].isInstance(c))
+ Collection coll = m.values();
+ if (!parms[i].isInstance(coll)) {
try { // could be a concrete class, for example LinkedList.
Collection collection = (Collection) parms[i].newInstance();
- collection.addAll(c);
- c = collection;
+ collection.addAll(coll);
+ coll = collection;
} catch (Exception e) { // it was an interface, try some concrete class
try {
- c = new ArrayList(c);
- } catch (Exception ex) {/*we've tried*/}
+ coll = new ArrayList(coll);
+ } catch (Exception ex) {/*we've tried*/
+ }
}
- result[i] = c;
+ }
+ result[i] = coll;
} catch (Exception ex) {
//logError("Could not create Collection from Map: " +objectDebugDescription(arg) + ". Cause: " + ex);
throw new JavaBridgeIllegalArgumentException("Could not create Collection from Map: " + firstChars(arg), ex);
}
+ } else if ((java.util.Map.class).isAssignableFrom(parms[i])) {
+ result[i] = arg;
} else if ((java.util.Hashtable.class).isAssignableFrom(parms[i])) {
try {
Map ht = (Map) arg;
@@ -801,8 +897,6 @@ else if (c == Long.TYPE && !(n instanceof Long))
logError("Could not create Hashtable from Map: " + objectDebugDescription(arg) + ". Cause: " + ex);
throw new JavaBridgeIllegalArgumentException("Could not create Hashtable from Map: " + firstChars(arg), ex);
}
- } else if ((java.util.Map.class).isAssignableFrom(parms[i])) {
- result[i] = arg;
} else if (arg instanceof PhpString) {
result[i] = ((PhpString) arg).getString(); // always prefer strings over byte[]
}
@@ -812,6 +906,7 @@ else if (c == Long.TYPE && !(n instanceof Long))
}
static abstract class FindMatchingInterface {
+
JavaBridge bridge;
String name;
Object args[];
@@ -831,19 +926,21 @@ public boolean checkAccessible(AccessibleObject o) {
}
}
-
static final FindMatchingInterfaceVoid MATCH_VOID_ICASE = new FindMatchingInterfaceVoid(true);
static final FindMatchingInterfaceVoid MATCH_VOID_CASE = new FindMatchingInterfaceVoid(false);
static class FindMatchingInterfaceVoid extends FindMatchingInterface {
+
public FindMatchingInterfaceVoid(boolean b) {
super(null, null, null, b);
}
+ @Override
Class findMatchingInterface(Class jclass) {
return jclass;
}
+ @Override
public boolean checkAccessible(AccessibleObject o) {
if (!o.isAccessible()) {
try {
@@ -857,20 +954,27 @@ public boolean checkAccessible(AccessibleObject o) {
}
static class FindMatchingInterfaceForInvoke extends FindMatchingInterface {
+
protected FindMatchingInterfaceForInvoke(JavaBridge bridge, String name, Object args[], boolean ignoreCase) {
super(bridge, name, args, ignoreCase);
}
public static FindMatchingInterface getInstance(JavaBridge bridge, String name, Object args[], boolean ignoreCase, boolean canModifySecurityPermission) {
- if (canModifySecurityPermission) return ignoreCase ? MATCH_VOID_ICASE : MATCH_VOID_CASE;
- else return new FindMatchingInterfaceForInvoke(bridge, name, args, ignoreCase);
+ if (canModifySecurityPermission) {
+ return ignoreCase ? MATCH_VOID_ICASE : MATCH_VOID_CASE;
+ } else {
+ return new FindMatchingInterfaceForInvoke(bridge, name, args, ignoreCase);
+ }
}
+ @Override
Class findMatchingInterface(Class jclass) {
- if (jclass == null) return jclass;
- if (bridge.logLevel > 3)
- if (bridge.logLevel > 3)
- bridge.logDebug("searching for matching interface for Invoke for class " + jclass);
+ if (jclass == null) {
+ return jclass;
+ }
+ if (bridge.logLevel > 3) {
+ bridge.logDebug("searching for matching interface for Invoke for class " + jclass);
+ }
while (!Modifier.isPublic(jclass.getModifiers())) {
// OK, some joker gave us an instance of a non-public class
// This often occurs in the case of enumerators
@@ -878,15 +982,17 @@ Class findMatchingInterface(Class jclass) {
// and barring that, try the superclass
Class interfaces[] = jclass.getInterfaces();
Class superclass = jclass.getSuperclass();
- for (int i = interfaces.length; i-- > 0; ) {
+ for (int i = interfaces.length; i-- > 0;) {
if (Modifier.isPublic(interfaces[i].getModifiers())) {
jclass = interfaces[i];
Method methods[] = jclass.getMethods();
- for (int j = 0; j < methods.length; j++) {
- String nm = methods[j].getName();
+ for (Method method : methods) {
+ String nm = method.getName();
boolean eq = ignoreCase ? nm.equalsIgnoreCase(name) : nm.equals(name);
- if (eq && (methods[j].getParameterTypes().length == args.length)) {
- if (bridge.logLevel > 3) bridge.logDebug("matching interface for Invoke: " + jclass);
+ if (eq && (method.getParameterTypes().length == args.length)) {
+ if (bridge.logLevel > 3) {
+ bridge.logDebug("matching interface for Invoke: " + jclass);
+ }
return jclass;
}
}
@@ -894,26 +1000,35 @@ Class findMatchingInterface(Class jclass) {
}
jclass = superclass;
}
- if (bridge.logLevel > 3) bridge.logDebug("interface for Invoke: " + jclass);
+ if (bridge.logLevel > 3) {
+ bridge.logDebug("interface for Invoke: " + jclass);
+ }
return jclass;
}
}
static class FindMatchingInterfaceForGetSetProp extends FindMatchingInterface {
+
protected FindMatchingInterfaceForGetSetProp(JavaBridge bridge, String name, Object args[], boolean ignoreCase) {
super(bridge, name, args, ignoreCase);
}
public static FindMatchingInterface getInstance(JavaBridge bridge, String name, Object args[], boolean ignoreCase, boolean canModifySecurityPermission) {
- if (canModifySecurityPermission) return ignoreCase ? MATCH_VOID_ICASE : MATCH_VOID_CASE;
- else return new FindMatchingInterfaceForGetSetProp(bridge, name, args, ignoreCase);
+ if (canModifySecurityPermission) {
+ return ignoreCase ? MATCH_VOID_ICASE : MATCH_VOID_CASE;
+ } else {
+ return new FindMatchingInterfaceForGetSetProp(bridge, name, args, ignoreCase);
+ }
}
+ @Override
Class findMatchingInterface(Class jclass) {
- if (jclass == null) return jclass;
- if (bridge.logLevel > 3)
- if (bridge.logLevel > 3)
- bridge.logDebug("searching for matching interface for GetSetProp for class " + jclass);
+ if (jclass == null) {
+ return jclass;
+ }
+ if (bridge.logLevel > 3) {
+ bridge.logDebug("searching for matching interface for GetSetProp for class " + jclass);
+ }
while (!Modifier.isPublic(jclass.getModifiers())) {
// OK, some joker gave us an instance of a non-public class
// This often occurs in the case of enumerators
@@ -921,16 +1036,17 @@ Class findMatchingInterface(Class jclass) {
// and barring that, try the superclass
Class interfaces[] = jclass.getInterfaces();
Class superclass = jclass.getSuperclass();
- for (int i = interfaces.length; i-- > 0; ) {
+ for (int i = interfaces.length; i-- > 0;) {
if (Modifier.isPublic(interfaces[i].getModifiers())) {
jclass = interfaces[i];
Field jfields[] = jclass.getFields();
- for (int j = 0; j < jfields.length; j++) {
- String nm = jfields[j].getName();
+ for (Field jfield : jfields) {
+ String nm = jfield.getName();
boolean eq = ignoreCase ? nm.equalsIgnoreCase(name) : nm.equals(name);
if (eq) {
- if (bridge.logLevel > 3)
+ if (bridge.logLevel > 3) {
bridge.logDebug("matching interface for GetSetProp: " + jclass);
+ }
return jclass;
}
}
@@ -938,27 +1054,33 @@ Class findMatchingInterface(Class jclass) {
}
jclass = superclass;
}
- if (bridge.logLevel > 3) bridge.logDebug("interface for GetSetProp: " + jclass);
+ if (bridge.logLevel > 3) {
+ bridge.logDebug("interface for GetSetProp: " + jclass);
+ }
return jclass;
}
}
private static ClassIterator getClassClassIterator(Class clazz) {
- if (clazz == Class.class) return new MetaClassIterator();
+ if (clazz == Class.class) {
+ return new MetaClassIterator();
+ }
return new ClassClassIterator();
}
private static abstract class ClassIterator {
+
Object object;
Class current;
FindMatchingInterface match;
public static ClassIterator getInstance(Object object, FindMatchingInterface match) {
ClassIterator c;
- if (object instanceof Class)
+ if (object instanceof Class) {
c = getClassClassIterator((Class) object);
- else
+ } else {
c = new ObjectClassIterator();
+ }
c.match = match;
c.object = object;
@@ -974,25 +1096,32 @@ public static ClassIterator getInstance(Object object, FindMatchingInterface mat
}
static class ObjectClassIterator extends ClassIterator {
+
private Class next() {
- if (current == null) return current = object.getClass();
+ if (current == null) {
+ return current = object.getClass();
+ }
return null;
}
+ @Override
public Class getNext() {
return match.findMatchingInterface(next());
}
+ @Override
public boolean checkAccessible(AccessibleObject o) {
return match.checkAccessible(o);
}
+ @Override
public boolean isVisible(int modifier) {
return true;
}
}
static class ClassClassIterator extends ClassIterator {
+
boolean hasNext = false;
private Class next() {
@@ -1008,14 +1137,17 @@ private Class next() {
return null;
}
+ @Override
public Class getNext() {
return next();
}
+ @Override
public boolean checkAccessible(AccessibleObject o) {
return true;
}
+ @Override
public boolean isVisible(int modifier) {
// all members of the class class or only static members of the class
return !hasNext || ((modifier & Modifier.STATIC) != 0);
@@ -1023,6 +1155,7 @@ public boolean isVisible(int modifier) {
}
static class MetaClassIterator extends ClassIterator {
+
private Class next() {
// The ClassClass has the ClassClass as its class
if (current == null) {
@@ -1031,14 +1164,17 @@ private Class next() {
return null;
}
+ @Override
public Class getNext() {
return next();
}
+ @Override
public boolean checkAccessible(AccessibleObject o) {
return true;
}
+ @Override
public boolean isVisible(int modifier) {
return true;
}
@@ -1047,7 +1183,9 @@ public boolean isVisible(int modifier) {
private static void logInvoke(Object obj, String method, Object args[]) {
String dmsg = "\nInvoking " + objectDebugDescription(obj) + "." + method + "(";
for (int t = 0; t < args.length; t++) {
- if (t > 0) dmsg += ",";
+ if (t > 0) {
+ dmsg += ",";
+ }
dmsg += objectDebugDescription(args[t]);
}
@@ -1063,14 +1201,13 @@ private static void logResult(Object obj) {
/**
* Invoke a method on a given object, to be called by clients.
*
- * @param object The object
- * @param method The method of the object
- * @param args The argument array
+ * @param object The object
+ * @param method The method of the object
+ * @param args The argument array
* @param response The response writer
* @throws NullPointerException If the object was null
*/
- public void Invoke
- (Object object, String method, Object args[], Response response) {
+ public void Invoke(Object object, String method, Object args[], Response response) {
Class jclass;
boolean again;
Object coercedArgs[] = null;
@@ -1085,7 +1222,7 @@ private static void logResult(Object obj) {
object = Request.PHPNULL;
throw new NullPointerException("cannot call \"" + method + "()\" on a Java null object. A previous Java call has returned a null value, use java_is_null($jvalue) to check.");
}
- /* PR1616498: Do not use Util.getClass(): if object is a class, we must pass the class class.
+ /* PR1616498: Do not use Util.getClass(): if object is a class, we must pass the class class.
* All VM, including gcc >= 3.3.3, return the class class for class.getClass(), not null. This is okay for the cache implementation. */
MethodCache.Entry entry = methodCache.getEntry(method, object, args);
selected = (Method) methodCache.get(entry);
@@ -1095,10 +1232,9 @@ private static void logResult(Object obj) {
again = false;
ClassIterator iter;
if (selected == null) {
- for (iter = ClassIterator.getInstance(object, FindMatchingInterfaceForInvoke.getInstance(this, method, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null; ) {
+ for (iter = ClassIterator.getInstance(object, FindMatchingInterfaceForInvoke.getInstance(this, method, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null;) {
Method methods[] = jclass.getMethods();
- for (int i = 0; i < methods.length; i++) {
- Method meth = methods[i];
+ for (Method meth : methods) {
if (meth.getName().equalsIgnoreCase(method) && iter.isVisible(meth.getModifiers())) {
candidates.add(meth);
if (meth.getParameterTypes().length == args.length) {
@@ -1108,8 +1244,9 @@ private static void logResult(Object obj) {
}
}
selected = (Method) select(matches, args);
- if (selected == null)
+ if (selected == null) {
checkM(object, String.valueOf(method) + "(" + Util.argsToString(args, params) + "). " + "Candidates: " + String.valueOf(candidates));
+ }
methodCache.put(entry, selected);
if (!iter.checkAccessible(selected)) {
logDebug("Security restriction: Cannot use setAccessible(), reverting to interface searching.");
@@ -1122,7 +1259,7 @@ private static void logResult(Object obj) {
coercedArgs = coerce(params = entry.getParameterTypes(selected), args, response);
} while (again);
- hasDeclaredExceptions = selected.getExceptionTypes().length != 0;
+ hasDeclaredExceptions = selected.getExceptionTypes().length != 0; //TODO possible null pointer
// If we have a logLevel of 5 or above, do very detailed invocation logging
if (this.logLevel > 4) {
logInvoke(object, method, coercedArgs);
@@ -1134,7 +1271,9 @@ private static void logResult(Object obj) {
}
} catch (Throwable e) {
Throwable e1 = e;
- if (e1 instanceof InvocationTargetException) e1 = ((InvocationTargetException) e1).getTargetException();
+ if (e1 instanceof InvocationTargetException) {
+ e1 = ((InvocationTargetException) e1).getTargetException();
+ }
if (e1 instanceof Request.AbortException) {
throw (Request.AbortException) e1;
}
@@ -1146,39 +1285,37 @@ private static void logResult(Object obj) {
e = getUnresolvedExternalReferenceException(e1, "call the method");
}
- if (selected != null && e1 instanceof IllegalArgumentException) {
- if (this.logLevel > 3) {
- String errMsg = "\nInvoked " + method + " on " + objectDebugDescription(object) + "\n";
- errMsg += " Expected Arguments for this Method:\n";
- Class paramTypes[] = selected.getParameterTypes();
- for (int k = 0; k < paramTypes.length; k++) {
- errMsg += " (" + k + ") " + classDebugDescription(paramTypes[k]) + "\n";
- }
- errMsg += " Plain Arguments for this Method:\n";
- for (int k = 0; k < args.length; k++) {
- errMsg += " (" + k + ") " + objectDebugDescription(args[k]) + "\n";
- }
- if (coercedArgs != null) {
- errMsg += " Coerced Arguments for this Method:\n";
- for (int k = 0; k < coercedArgs.length; k++) {
- errMsg += " (" + k + ") " + objectDebugDescription(coercedArgs[k]) + "\n";
- }
+ if (selected != null && e1 instanceof IllegalArgumentException && this.logLevel > 3) {
+ String errMsg = "\nInvoked " + method + " on " + objectDebugDescription(object) + "\n";
+ errMsg += " Expected Arguments for this Method:\n";
+ Class paramTypes[] = selected.getParameterTypes();
+ for (int k = 0; k < paramTypes.length; k++) {
+ errMsg += " (" + k + ") " + classDebugDescription(paramTypes[k]) + "\n";
+ }
+ errMsg += " Plain Arguments for this Method:\n";
+ for (int k = 0; k < args.length; k++) {
+ errMsg += " (" + k + ") " + objectDebugDescription(args[k]) + "\n";
+ }
+ if (coercedArgs != null) {
+ errMsg += " Coerced Arguments for this Method:\n";
+ for (int k = 0; k < coercedArgs.length; k++) {
+ errMsg += " (" + k + ") " + objectDebugDescription(coercedArgs[k]) + "\n";
}
- this.logDebug(errMsg);
}
+ this.logDebug(errMsg);
}
setException(response, e, "Invoke", object, method, args, params, hasDeclaredExceptions);
}
}
private void checkM(Object object, String string) throws NoSuchMethodException {
- if (object instanceof Class) throw new NoSuchProcedureException(string);
- else throw new NoSuchMethodException(string);
+ if (object instanceof Class) {
+ throw new NoSuchProcedureException(string);
+ } else {
+ throw new NoSuchMethodException(string);
+ }
}
- static private final int DISPLAY_MAX_ELEMENTS = 10;
- static private final int DISPLAY_MAX_CHARS = 80;
-
private static String firstChars(Object o) {
String append = "";
String s = o instanceof java.lang.reflect.Proxy ? o.getClass().getName() : String.valueOf(o);
@@ -1208,13 +1345,21 @@ public static String objectDebugDescription(Object ob) {
* @return A debug description.
*/
private static String objectDebugDescription(Object ob, int level) {
- if (ob == null) return "[Object null]";
+ if (ob == null) {
+ return "[Object null]";
+ }
Object obj = ob;
- if (obj instanceof Collection) obj = ((Collection) obj).toArray();
- else if (obj instanceof List) obj = ((List) obj).toArray();
- else if (obj instanceof Map) obj = ((Map) obj).values().toArray();
+ if (obj instanceof Collection) {
+ obj = ((Collection) obj).toArray();
+ } else if (obj instanceof List) {
+ obj = ((List) obj).toArray();
+ } else if (obj instanceof Map) {
+ obj = ((Map) obj).values().toArray();
+ }
if (level < DISPLAY_MAX_ELEMENTS && obj.getClass().isArray()) {
- StringBuffer buf = new StringBuffer("[Object " + System.identityHashCode(ob) + " - Class: " + classDebugDescription(ob.getClass()) + "]: ");
+ StringBuilder buf
+ = new StringBuilder("[Object " + System.identityHashCode(ob)
+ + " - Class: " + classDebugDescription(ob.getClass()) + "]: ");
buf.append("{\n");
int length = Array.getLength(obj);
for (int i = 0; i < length; i++) {
@@ -1245,14 +1390,13 @@ public static String classDebugDescription(Class cls) {
/**
* Get or Set a property, to be called by clients.
*
- * @param object The object
- * @param prop The object property
- * @param args The argument array
+ * @param object The object
+ * @param prop The object property
+ * @param args The argument array
* @param response The response writer
* @throws NullPointerException If the object is null
*/
- public void GetSetProp
- (Object object, String prop, Object args[], Response response) throws NullPointerException {
+ public void GetSetProp(Object object, String prop, Object args[], Response response) throws NullPointerException {
LinkedList matches = new LinkedList();
boolean set = (args != null && args.length > 0);
Class params[] = null;
@@ -1268,11 +1412,10 @@ public static String classDebugDescription(Class cls) {
// first search for the field *exactly*
again2:
// because of security exception
- for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForGetSetProp.getInstance(this, prop, args, false, canModifySecurityPermission)); (jclass = iter.getNext()) != null; ) {
+ for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForGetSetProp.getInstance(this, prop, args, false, canModifySecurityPermission)); (jclass = iter.getNext()) != null;) {
try {
Field jfields[] = jclass.getFields();
- for (int i = 0; i < jfields.length; i++) {
- Field fld = jfields[i];
+ for (Field fld : jfields) {
if (fld.getName().equals(prop) && iter.isVisible(fld.getModifiers())) {
matches.add(fld.getName());
Object res = null;
@@ -1293,25 +1436,26 @@ public static String classDebugDescription(Class cls) {
return;
}
}
- } catch (Exception ee) {/* may happen when field is not static */}
+ } catch (Exception ee) {/* may happen when field is not static */
+ }
}
matches.clear();
// search for a getter/setter, ignore case
again1:
// because of security exception
- for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForInvoke.getInstance(this, prop, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null; ) {
+ for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForInvoke.getInstance(this, prop, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null;) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(jclass);
- PropertyDescriptor props[] = beanInfo.getPropertyDescriptors();
- for (int i = 0; i < props.length; i++) {
- if (props[i].getName().equalsIgnoreCase(prop)) {
+ PropertyDescriptor propDesc[] = beanInfo.getPropertyDescriptors();
+ for (PropertyDescriptor pd : propDesc) {
+ if (pd.getName().equalsIgnoreCase(prop)) {
Method method;
if (set) {
- method = props[i].getWriteMethod();
+ method = pd.getWriteMethod();
args = coerce(params = method.getParameterTypes(), args, response);
} else {
- method = props[i].getReadMethod();
+ method = pd.getReadMethod();
}
matches.add(method);
if (!iter.checkAccessible(method)) {
@@ -1325,18 +1469,18 @@ public static String classDebugDescription(Class cls) {
return;
}
}
- } catch (Exception ee) {/* may happen when method is not static */}
+ } catch (Exception ee) {/* may happen when method is not static */
+ }
}
matches.clear();
// search for the field, ignore case
again0:
// because of security exception
- for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForGetSetProp.getInstance(this, prop, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null; ) {
+ for (ClassIterator iter = ClassIterator.getInstance(object, FindMatchingInterfaceForGetSetProp.getInstance(this, prop, args, true, canModifySecurityPermission)); (jclass = iter.getNext()) != null;) {
try {
Field jfields[] = jclass.getFields();
- for (int i = 0; i < jfields.length; i++) {
- Field fld = jfields[i];
+ for (Field fld : jfields) {
if (fld.getName().equalsIgnoreCase(prop) && iter.isVisible(fld.getModifiers())) {
matches.add(prop);
Object res = null;
@@ -1357,13 +1501,16 @@ public static String classDebugDescription(Class cls) {
return;
}
}
- } catch (Exception ee) {/* may happen when field is not static */}
+ } catch (Exception ee) {/* may happen when field is not static */
+ }
}
checkF(object, String.valueOf(prop) + " (with args:" + Util.argsToString(args, params) + "). " + "Candidates: " + String.valueOf(matches));
} catch (Throwable e) {
Throwable e1 = e;
- if (e1 instanceof InvocationTargetException) e1 = ((InvocationTargetException) e1).getTargetException();
+ if (e1 instanceof InvocationTargetException) {
+ e1 = ((InvocationTargetException) e1).getTargetException();
+ }
if (e1 instanceof Request.AbortException) {
throw (Request.AbortException) e1;
}
@@ -1378,17 +1525,17 @@ public static String classDebugDescription(Class cls) {
}
}
-
private void checkF(Object object, String string) throws NoSuchFieldException {
- if (object instanceof Class) throw new NoSuchConstantException(string);
- else throw new NoSuchFieldException(string);
+ if (object instanceof Class) {
+ throw new NoSuchConstantException(string);
+ } else {
+ throw new NoSuchFieldException(string);
+ }
}
/**
- * Convert Map or Collection into a PHP array,
- * sends the entire array, Map or Collection to the client. This
- * is much more efficient than generating round-trips while
- * iterating over the values of an array, Map or Collection.
+ * Convert Map or Collection into a PHP array, sends the entire array, Map or Collection to the client. This is much
+ * more efficient than generating round-trips while iterating over the values of an array, Map or Collection.
*
* @param ob - The object to expand
* @return The passed ob, will be expanded by the appropriate writer.
@@ -1413,7 +1560,7 @@ public long unwrapClosure(Object closure) throws IllegalArgumentException {
/**
* Cast a object to a type
*
- * @param ob - The object to cast
+ * @param ob - The object to cast
* @param type - The target type
* @return The passed ob, will be coerced by the appropriate writer.
*/
@@ -1437,7 +1584,7 @@ public Object castToString(Object ob) {
* Cast a throwable to a string
*
* @param throwable The throwable to cast
- * @param trace The PHP stack trace
+ * @param trace The PHP stack trace
* @return The result String object, will be coerced by the appropriate writer.
*/
public Object castToString(Exception throwable, String trace) {
@@ -1503,7 +1650,7 @@ protected JavaBridge(IJavaBridgeFactory factory) {
*
* @param value - The value which must be an array or implement Map or Collection.
* @return The PHP map.
- * @see php.java.bridge.PhpMap
+ * @see io.soluble.pjb.bridge.PhpMap
*/
public PhpMap getPhpMap(Object value) {
return PhpMap.getPhpMap(value, this);
@@ -1518,37 +1665,37 @@ public PhpMap getPhpMap(Object value) {
public String inspect(Object object) {
Class jclass;
ClassIterator iter;
- StringBuffer buf = new StringBuffer("[");
+ StringBuilder buf = new StringBuilder("[");
buf.append(String.valueOf(Util.getClass(object)));
buf.append(":\nConstructors:\n");
- for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null; ) {
+ for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null;) {
Constructor[] constructors = jclass.getConstructors();
- for (int i = 0; i < constructors.length; i++) {
- buf.append(String.valueOf(constructors[i]));
+ for (Constructor constructor : constructors) {
+ buf.append(String.valueOf(constructor));
buf.append("\n");
}
}
buf.append("\nFields:\n");
- for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null; ) {
+ for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null;) {
Field jfields[] = jclass.getFields();
- for (int i = 0; i < jfields.length; i++) {
- buf.append(String.valueOf(jfields[i]));
+ for (Field jfield : jfields) {
+ buf.append(String.valueOf(jfield));
buf.append("\n");
}
}
buf.append("\nMethods:\n");
- for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null; ) {
+ for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null;) {
Method jmethods[] = jclass.getMethods();
- for (int i = 0; i < jmethods.length; i++) {
- buf.append(String.valueOf(jmethods[i]));
+ for (Method jmethod : jmethods) {
+ buf.append(String.valueOf(jmethod));
buf.append("\n");
}
}
buf.append("\nClasses:\n");
- for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null; ) {
+ for (iter = ClassIterator.getInstance(object, MATCH_VOID_CASE); (jclass = iter.getNext()) != null;) {
Class jclasses[] = jclass.getClasses();
- for (int i = 0; i < jclasses.length; i++) {
- buf.append(String.valueOf(jclasses[i].getName()));
+ for (Class jclasse : jclasses) {
+ buf.append(String.valueOf(jclasse.getName()));
buf.append("\n");
}
}
@@ -1557,8 +1704,7 @@ public String inspect(Object object) {
}
/**
- * Set a new file encoding, used to code and decode strings.
- * Example: setFileEncoding("UTF-8")
+ * Set a new file encoding, used to code and decode strings. Example: setFileEncoding("UTF-8")
*
* @param fileEncoding The file encoding.
*/
@@ -1569,7 +1715,7 @@ public void setFileEncoding(String fileEncoding) {
/**
* Check if object is an instance of class.
*
- * @param ob The object
+ * @param ob The object
* @param claz The class or an instance of a class
* @return true if ob is an instance of class, false otherwise.
*/
@@ -1585,7 +1731,9 @@ public boolean InstanceOf(Object ob, Object claz) {
* @return A string representation.
*/
public Object ObjectToString(Object ob) {
- if (ob == null && !options.preferValues()) ob = Request.PHPNULL;
+ if (ob == null && !options.preferValues()) {
+ ob = Request.PHPNULL;
+ }
return castToString(Util.stringValueOf(ob));
}
@@ -1596,8 +1744,10 @@ public Object ObjectToString(Object ob) {
* @return A string representation.
*/
public Object ObjectToString(Boolean ob) {
- if (ob == null) return ObjectToString((Object) null);
- return castToString(ob.booleanValue() ? "1" : "");
+ if (ob == null) {
+ return ObjectToString((Object) null);
+ }
+ return castToString(ob ? "1" : "");
}
/**
@@ -1607,7 +1757,9 @@ public Object ObjectToString(Boolean ob) {
* @return A string representation.
*/
public Object ObjectToString(String ob) {
- if (ob == null) return ObjectToString((Object) null);
+ if (ob == null) {
+ return ObjectToString((Object) null);
+ }
return castToString(ob);
}
@@ -1618,14 +1770,16 @@ public Object ObjectToString(String ob) {
* @return A string representation.
*/
public Object ObjectToString(byte[] ob) {
- if (ob == null) return ObjectToString((Object) null);
+ if (ob == null) {
+ return ObjectToString((Object) null);
+ }
return castToString(ob);
}
/**
* Returns a string representation of the object
*
- * @param ob The Throwable
+ * @param ob The Throwable
* @param trace The stack trace
* @return A string representation.
*/
@@ -1658,24 +1812,27 @@ public Object ObjectToString(Throwable ob, String trace) {
* @return The JSR223 context.
*/
public Object getContext() {
- if (contextCache != null) return contextCache;
+ if (contextCache != null) {
+ return contextCache;
+ }
return contextCache = sessionFactory.getContext();
}
/**
- * Return a session handle shared among all JavaBridge
- * instances. If it is a HTTP session, the session is shared with
- * the servlet or jsp.
+ * Return a session handle shared among all JavaBridge instances. If it is a HTTP session, the session is shared
+ * with the servlet or jsp.
*
- * @param name The session name, if any
+ * @param name The session name, if any
* @param clientIsNew true, if the client wants a new session
- * @param timeout session timeout in seconds. If timeout is <= 0, the session will never expire
- * @return The session context.
+ * @param timeout session timeout in seconds. If timeout is <= 0, the session will never expire @return The session context
+ * @return
* @throws Exception
- * @see php.java.bridge.ISession
+ * @see io.soluble.pjb.bridge.ISession
*/
public ISession getSession(String name, short clientIsNew, int timeout) throws Exception {
- if (timeout == 0) timeout = -1;
+ if (timeout == 0) {
+ timeout = -1;
+ }
try {
return sessionFactory.getSession(name, clientIsNew, timeout);
} catch (Exception t) {
@@ -1690,11 +1847,13 @@ public ISession getSession(String name, short clientIsNew, int timeout) throws E
* java_closure($this, $map);
*
* @param object the PHP environment (the php instance)
- * @param names maps java to php names
+ * @param names maps java to php names
* @return the proxy
*/
public Object makeClosure(long object, Map names) {
- if (names == null) return makeClosure(object);
+ if (names == null) {
+ return makeClosure(object);
+ }
return PhpProcedure.createProxy(getFactory(), null, names, Util.ZERO_PARAM, object);
}
@@ -1703,13 +1862,15 @@ public Object makeClosure(long object, Map names) {
* Example:
* java_closure($this, $map, $interfaces);
*
- * @param object the PHP environment (the php instance)
- * @param names maps java to php names
+ * @param object the PHP environment (the php instance)
+ * @param names maps java to php names
* @param interfaces list of interfaces which the PHP environment must implement
* @return the proxy
*/
public Object makeClosure(long object, Map names, Class interfaces[]) {
- if (names == null) names = emptyMap;
+ if (names == null) {
+ names = EMPTY_MAP;
+ }
return PhpProcedure.createProxy(getFactory(), null, names, interfaces, object);
}
@@ -1719,8 +1880,8 @@ public Object makeClosure(long object, Map names, Class interfaces[]) {
* java_closure($this, $map, $interfaces);
*
* @param object the PHP environment (the php instance)
- * @param name maps all java names to this php name
- * @param iface interface which the PHP environment must implement
+ * @param name maps all java names to this php name
+ * @param iface interface which the PHP environment must implement
* @return the proxy
*/
public Object makeClosure(long object, String name, Class iface) {
@@ -1734,8 +1895,8 @@ public Object makeClosure(long object, String name, Class iface) {
* java_closure($this, $map, $interfaces);
*
* @param object the PHP environment (the php instance)
- * @param names maps java to php names
- * @param iface interface which the PHP environment must implement
+ * @param names maps java to php names
+ * @param iface interface which the PHP environment must implement
* @return the proxy
*/
public Object makeClosure(long object, Map names, Class iface) {
@@ -1749,11 +1910,13 @@ public Object makeClosure(long object, Map names, Class iface) {
* java_closure($this, "clickMe");
*
* @param object the PHP environment (the php instance)
- * @param name maps all java names to this php name
+ * @param name maps all java names to this php name
* @return the proxy
*/
public Object makeClosure(long object, String name) {
- if (name == null) return makeClosure(object);
+ if (name == null) {
+ return makeClosure(object);
+ }
return PhpProcedure.createProxy(getFactory(), name, null, Util.ZERO_PARAM, object);
}
@@ -1762,17 +1925,19 @@ public Object makeClosure(long object, String name) {
* Example:
* java_closure($this, "clickMe", $interfaces);
*
- * @param object the PHP environment (the php instance)
- * @param name maps all java names to this php name
+ * @param object the PHP environment (the php instance)
+ * @param name maps all java names to this php name
* @param interfaces list of interfaces which the PHP environment must implement
* @return the proxy
*/
public Object makeClosure(long object, String name, Class interfaces[]) {
- if (name == null) return makeClosure(object, emptyMap, interfaces);
+ if (name == null) {
+ return makeClosure(object, EMPTY_MAP, interfaces);
+ }
return PhpProcedure.createProxy(getFactory(), name, null, interfaces, object);
}
- private static final HashMap emptyMap = new HashMap();
+ private static final HashMap EMPTY_MAP = new HashMap();
/**
* Create a dynamic proxy proxy for calling PHP code.
@@ -1784,12 +1949,11 @@ public Object makeClosure(long object, String name, Class interfaces[]) {
* @return the proxy
*/
public Object makeClosure(long object) {
- return PhpProcedure.createProxy(getFactory(), null, emptyMap, Util.ZERO_PARAM, object);
+ return PhpProcedure.createProxy(getFactory(), null, EMPTY_MAP, Util.ZERO_PARAM, object);
}
/**
- * This method sets a new session factory. Used by the servlet to
- * implement session sharing.
+ * This method sets a new session factory. Used by the servlet to implement session sharing.
*
* @param sessionFactory The sessionFactory to set.
*/
@@ -1797,23 +1961,22 @@ void setFactory(IJavaBridgeFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
- protected static final String PHPSESSION = "PHPSESSION";
- protected static final String INTERNAL_PHPSESSION = "INTERNAL_PHPSESSION";
-
/**
- * Load the object from the session store.
- * The C code requires that this method is called "deserialize" even though it doesn't deserialize anything.
- * See the JSessionAdapter in the php_java_lib folder. For real serialization/deserialization see the JPersistenceAdapter in the php_java_lib folder.
+ * Load the object from the session store. The C code requires that this method is called "deserialize" even though
+ * it doesn't deserialize anything. See the JSessionAdapter in the php_java_lib folder. For real
+ * serialization/deserialization see the JPersistenceAdapter in the php_java_lib folder.
*
* @param serialID The key
- * @param timeout The timeout, usually 1400 seconds.
+ * @param timeout The timeout, usually 1400 seconds.
* @return the new object identity.
* @throws IllegalArgumentException if serialID does not exist anymore.
*/
public int deserialize(String serialID, int timeout) throws IllegalArgumentException {
ISession session = sessionFactory.getSession(JavaBridge.INTERNAL_PHPSESSION, ISession.SESSION_GET_OR_CREATE, timeout);
Object obj = session.get(serialID);
- if (obj == null) throw new IllegalArgumentException("Session serialID " + serialID + " expired.");
+ if (obj == null) {
+ throw new IllegalArgumentException("Session serialID " + serialID + " expired.");
+ }
return globalRef.append(castToExact(obj));
}
@@ -1824,16 +1987,18 @@ private static synchronized int getSerialID() {
}
/**
- * Store the object in the session store and return the serial id.
- * The C code requires that this method is called "serialize" even though it doesn't serialize anything.
- * See the JSessionAdapter in the php_java_lib folder. For real serialization/deserialization see the JPersistenceAdapter in the php_java_lib folder.
+ * Store the object in the session store and return the serial id. The C code requires that this method is called
+ * "serialize" even though it doesn't serialize anything. See the JSessionAdapter in the php_java_lib folder. For
+ * real serialization/deserialization see the JPersistenceAdapter in the php_java_lib folder.
*
- * @param obj The object
+ * @param obj The object
* @param timeout The timeout, usually 1400 seconds
* @return the serialID
*/
public String serialize(Object obj, int timeout) throws IllegalArgumentException {
- if (obj == null) obj = Request.PHPNULL;
+ if (obj == null) {
+ obj = Request.PHPNULL;
+ }
ISession session = sessionFactory.getSession(JavaBridge.INTERNAL_PHPSESSION, ISession.SESSION_GET_OR_CREATE, timeout);
String id = Integer.toHexString(getSerialID());
session.put(id, obj);
@@ -1844,7 +2009,7 @@ public String serialize(Object obj, int timeout) throws IllegalArgumentException
* Checks if a given position exists.
*
* @param value The map.
- * @param pos The position
+ * @param pos The position
* @return true if an element exists at this position, false otherwise.
*/
private boolean offsetExists(Map value, Object pos) {
@@ -1856,7 +2021,7 @@ private boolean offsetExists(Map value, Object pos) {
* Returns the object at the posisition.
*
* @param value The map.
- * @param pos The position.
+ * @param pos The position.
* @return The object at the given position.
*/
private Object offsetGet(Map value, Object pos) {
@@ -1867,14 +2032,16 @@ private Object offsetGet(Map value, Object pos) {
* Set an object at position.
*
* @param value The map.
- * @param pos The position.
- * @param val The object.
+ * @param pos The position.
+ * @param val The object.
*/
private void offsetSet(Map value, Object pos, Object val) {
Class type = value.getClass().getComponentType();
- if (type != null) val = coerce(type, val, request.response);
+ if (type != null) {
+ val = coerce(type, val, request.response);
+ }
if (pos == null) {
- pos = new Integer(value.size());
+ pos = value.size();
}
value.put(pos, val);
}
@@ -1883,7 +2050,7 @@ private void offsetSet(Map value, Object pos, Object val) {
* Remove an object from the position.
*
* @param value The map.
- * @param pos The position.
+ * @param pos The position.
*/
private void offsetUnset(Map value, Object pos) {
value.remove(pos);
@@ -1893,7 +2060,7 @@ private void offsetUnset(Map value, Object pos) {
* Checks if a given position exists.
*
* @param value The list.
- * @param pos The position
+ * @param pos The position
* @return true if an element exists at this position, false otherwise.
*/
private boolean offsetExists(List value, int pos) {
@@ -1910,7 +2077,7 @@ private boolean offsetExists(List value, int pos) {
* Returns the object at the posisition.
*
* @param value The list.
- * @param pos The position.
+ * @param pos The position.
* @return The object at the given position.
*/
private Object offsetGet(List value, int pos) {
@@ -1921,12 +2088,13 @@ private Object offsetGet(List value, int pos) {
* Set an object at position.
*
* @param value The list.
- * @param pos The position.
- * @param val The object.
+ * @param pos The position.
+ * @param val The object.
*/
private void offsetSet(List value, Number off, Object val) {
- if (off == null) value.add(val);
- else {
+ if (off == null) {
+ value.add(val);
+ } else {
int pos = off.intValue();
value.set(pos, val);
}
@@ -1936,7 +2104,7 @@ private void offsetSet(List value, Number off, Object val) {
* Remove an object from the position.
*
* @param value The list.
- * @param pos The position.
+ * @param pos The position.
*/
private void offsetUnset(List value, int pos) {
value.remove(pos);
@@ -1952,7 +2120,7 @@ boolean offsetExists(int length, int pos) {
* Checks if a given position exists.
*
* @param value The array.
- * @param pos The position
+ * @param pos The position
* @return true if an element exists at this position, false otherwise.
*/
private boolean offsetExists(Object value, int pos) {
@@ -1963,12 +2131,16 @@ private boolean offsetExists(Object value, int pos) {
* Checks if a given position exists.
*
* @param table The table.
- * @param off The offset
+ * @param off The offset
* @return true if an element exists at this position, false otherwise.
*/
public boolean offsetExists(Object table, Object off) {
- if (table.getClass().isArray()) return offsetExists(table, ((Number) off).intValue());
- if (table instanceof List) return offsetExists((List) table, ((Number) off).intValue());
+ if (table.getClass().isArray()) {
+ return offsetExists(table, ((Number) off).intValue());
+ }
+ if (table instanceof List) {
+ return offsetExists((List) table, ((Number) off).intValue());
+ }
return offsetExists((Map) table, off);
}
@@ -1976,25 +2148,29 @@ public boolean offsetExists(Object table, Object off) {
* Returns the object at the posisition.
*
* @param value The array.
- * @param pos The position.
+ * @param pos The position.
* @return The object at the given position.
*/
private Object offsetGet(Object value, int pos) {
int i = pos;
- Object o = Array.get(value, i);
- return o == this ? null : o;
+ Object obj = Array.get(value, i);
+ return obj == this ? null : obj;
}
/**
* Returns the object at the posisition.
*
* @param table The table.
- * @param off The offset.
+ * @param off The offset.
* @return The object at the given position.
*/
public Object offsetGet(Object table, Object off) {
- if (table.getClass().isArray()) return offsetGet(table, ((Number) off).intValue());
- if (table instanceof List) return offsetGet((List) table, ((Number) off).intValue());
+ if (table.getClass().isArray()) {
+ return offsetGet(table, ((Number) off).intValue());
+ }
+ if (table instanceof List) {
+ return offsetGet((List) table, ((Number) off).intValue());
+ }
return offsetGet((Map) table, off);
}
@@ -2015,15 +2191,17 @@ public void beginDocument() {
public void endDocument() throws Throwable {
Response res = request.response;
res.setDefaultWriter();
- if (lastAsyncException != null) throw lastAsyncException;
+ if (lastAsyncException != null) {
+ throw lastAsyncException;
+ }
}
/**
* Set an object at position.
*
* @param value The array.
- * @param pos The position.
- * @param val The object.
+ * @param pos The position.
+ * @param val The object.
*/
private void offsetSet(Object value, int pos, Object val) {
Array.set(value, pos, coerce(value.getClass().getComponentType(), val, request.response));
@@ -2033,20 +2211,24 @@ private void offsetSet(Object value, int pos, Object val) {
* Set an object at position.
*
* @param table The table
- * @param off The offset.
- * @param val The value
+ * @param off The offset.
+ * @param val The value
*/
public void offsetSet(Object table, Object off, Object val) {
- if (table.getClass().isArray()) offsetSet(table, ((Number) off).intValue(), val);
- else if (table instanceof List) offsetSet((List) table, ((Number) off), val);
- else offsetSet((Map) table, off, val);
+ if (table.getClass().isArray()) {
+ offsetSet(table, ((Number) off).intValue(), val);
+ } else if (table instanceof List) {
+ offsetSet((List) table, ((Number) off), val);
+ } else {
+ offsetSet((Map) table, off, val);
+ }
}
/**
* Remove an object from the position.
*
* @param value The array.
- * @param pos The position.
+ * @param pos The position.
*/
private void offsetUnset(Object value, int pos) {
int i = pos;
@@ -2057,24 +2239,27 @@ private void offsetUnset(Object value, int pos) {
* Remove an object from the position.
*
* @param table The table.
- * @param off The offset.
+ * @param off The offset.
*/
public void offsetUnset(Object table, Object off) {
- if (table.getClass().isArray()) offsetUnset(table, ((Number) off).intValue());
- else if (table instanceof List) offsetUnset((List) table, ((Number) off).intValue());
- else offsetUnset((Map) table, off);
+ if (table.getClass().isArray()) {
+ offsetUnset(table, ((Number) off).intValue());
+ } else if (table instanceof List) {
+ offsetUnset((List) table, ((Number) off).intValue());
+ } else {
+ offsetUnset((Map) table, off);
+ }
}
/**
- * Re-initialize the current bridge for keep-alive
- * See php.ini option java.persistent_connections
+ * Re-initialize the current bridge for keep-alive See php.ini option java.persistent_connections
*/
public void recycle() {
this.contextCache = null;
globalRef = new GlobalRef();
options.recycle();
-
+
/* resets the bridge: make sure to set the original bridge before calling sessionFactory.recycle() */
request.recycle();
/* resets the currentThreadContextClassLoader from the bridge's loader */
@@ -2090,8 +2275,8 @@ public void recycle() {
/**
* Return a new string using the current file encoding (see java_set_file_encoding()).
*
- * @param b The byte array
- * @param start The start index
+ * @param b The byte array
+ * @param start The start index
* @param length The number of bytes to encode.
* @return The encoded string.
*/
@@ -2108,8 +2293,8 @@ public String getString(byte[] b, int start, int length) {
/**
* Return a cached string using the current file encoding (see java_set_file_encoding()).
*
- * @param b The byte array
- * @param start The start index
+ * @param b The byte array
+ * @param start The start index
* @param length The number of bytes to encode.
* @return The encoded string.
*/
@@ -2137,7 +2322,8 @@ public boolean typeExists(String name) {
Util.classForName(name);
castToBoolean(null);
return true;
- } catch (ClassNotFoundException ex) {/*ignore*/}
+ } catch (ClassNotFoundException ex) {/*ignore*/
+ }
castToBoolean(null);
return false;
}
@@ -2149,12 +2335,16 @@ public boolean typeExists(String name) {
*/
public Throwable getLastException() {
request.response.setCoerceWriter().setType(Object.class);
- if (lastAsyncException != null) return lastAsyncException;
+ if (lastAsyncException != null) {
+ return lastAsyncException;
+ }
return lastException;
}
protected Throwable setLastAsyncException(Throwable t) {
- if (lastAsyncException == null) lastException = lastAsyncException = t;
+ if (lastAsyncException == null) {
+ lastException = lastAsyncException = t;
+ }
return t;
}
@@ -2164,4 +2354,5 @@ protected Throwable setLastAsyncException(Throwable t) {
public void clearLastException() {
lastException = lastAsyncException = null;
}
+
}
diff --git a/server/php/java/bridge/JavaBridgeFactory.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeFactory.java
similarity index 86%
rename from server/php/java/bridge/JavaBridgeFactory.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridgeFactory.java
index e0fe441..5b057ee 100644
--- a/server/php/java/bridge/JavaBridgeFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeFactory.java
@@ -1,11 +1,11 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
import java.io.IOException;
import java.io.InputStream;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.http.IContext;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -34,12 +34,12 @@
* Create new JavaBridge instances
*
* @author jostb
- * @see php.java.bridge.Session
- * @see php.java.bridge.http.Context
- * @see php.java.servlet.HttpContext
- * @see php.java.bridge.http.ContextFactory
- * @see php.java.servlet.ServletContextFactory
- * @see php.java.script.PhpScriptContextFactory
+ * @see io.soluble.pjb.bridge.Session
+ * @see io.soluble.pjb.bridge.http.Context
+ * @see io.soluble.pjb.servlet.HttpContext
+ * @see io.soluble.pjb.bridge.http.ContextFactory
+ * @see io.soluble.pjb.servlet.ServletContextFactory
+ * @see io.soluble.pjb.script.PhpScriptContextFactory
*/
public abstract class JavaBridgeFactory implements IJavaBridgeFactory {
@@ -52,7 +52,7 @@ public abstract class JavaBridgeFactory implements IJavaBridgeFactory {
* @param clientIsNew one of {@link ISession#SESSION_CREATE_NEW} {@link ISession#SESSION_GET_OR_CREATE} or {@link ISession#SESSION_GET}
* @param timeout timeout in seconds. If 0 the session does not expire.
* @return The session
- * @see php.java.bridge.ISession
+ * @see io.soluble.pjb.bridge.ISession
*/
public abstract ISession getSession(String name, short clientIsNew, int timeout);
@@ -60,7 +60,7 @@ public abstract class JavaBridgeFactory implements IJavaBridgeFactory {
* Return the associated JSR223 context
*
* @return Always null
- * @see php.java.bridge.http.ContextFactory#getContext()
+ * @see io.soluble.pjb.bridge.http.ContextFactory#getContext()
*/
public abstract IContext getContext();
diff --git a/server/php/java/bridge/JavaBridgeIllegalArgumentException.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalArgumentException.java
similarity index 96%
rename from server/php/java/bridge/JavaBridgeIllegalArgumentException.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalArgumentException.java
index 6d1c244..53df3c9 100644
--- a/server/php/java/bridge/JavaBridgeIllegalArgumentException.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalArgumentException.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
/**
* This class is needed for backward compatibility with JDK 1.4
*/
diff --git a/server/php/java/bridge/JavaBridgeIllegalStateException.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalStateException.java
similarity index 96%
rename from server/php/java/bridge/JavaBridgeIllegalStateException.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalStateException.java
index c0807b6..b71ed25 100644
--- a/server/php/java/bridge/JavaBridgeIllegalStateException.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeIllegalStateException.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
/**
* This class is needed for backward compatibility with JDK 1.4
*/
diff --git a/server/php/java/bridge/JavaBridgeRunner.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java
similarity index 66%
rename from server/php/java/bridge/JavaBridgeRunner.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java
index 36168d8..dc20637 100644
--- a/server/php/java/bridge/JavaBridgeRunner.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -38,14 +36,14 @@
import java.util.Iterator;
import java.util.List;
-import php.java.bridge.http.ChunkedInputStream;
-import php.java.bridge.http.ChunkedOutputStream;
-import php.java.bridge.http.ContextFactory;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.HttpRequest;
-import php.java.bridge.http.HttpResponse;
-import php.java.bridge.http.HttpServer;
-import php.java.bridge.http.RemoteHttpContextFactory;
+import io.soluble.pjb.bridge.http.ChunkedInputStream;
+import io.soluble.pjb.bridge.http.ChunkedOutputStream;
+import io.soluble.pjb.bridge.http.ContextFactory;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.HttpRequest;
+import io.soluble.pjb.bridge.http.HttpResponse;
+import io.soluble.pjb.bridge.http.HttpServer;
+import io.soluble.pjb.bridge.http.RemoteHttpContextFactory;
/**
* This is the main entry point for the PHP/Java Bridge library.
@@ -59,7 +57,7 @@
* }
*
* @author jostb
- * @see php.java.script.PhpScriptContext
+ * @see io.soluble.pjb.script.PhpScriptContext
*/
public class JavaBridgeRunner extends HttpServer {
@@ -175,6 +173,7 @@ public static synchronized JavaBridgeRunner getRequiredInstance() throws IOExcep
* @return The server socket.
* @throws IOException
*/
+ @Override
public ISocketFactory bind(String addr) throws IOException {
socket = JavaBridge.bind(addr);
return socket;
@@ -187,6 +186,7 @@ public ISocketFactory bind(String addr) throws IOException {
* @return The server socket.
* @throws IOException
*/
+ @Override
public ISocketFactory bindSecure(String addr) throws IOException {
boolean isLocal = true;
if (addr.startsWith("INET_LOCAL:")) {
@@ -207,12 +207,16 @@ private static String getHeader(String key, HttpRequest req) {
/**
* Handles both, override-redirect and redirect, see
- * see php.java.servlet.PhpJavaServlet#handleSocketConnection(HttpServletRequest, HttpServletResponse, String, boolean)
- * see php.java.servlet.PhpJavaServlet#handleRedirectConnection(HttpServletRequest, HttpServletResponse)
+ * see io.soluble.pjb.servlet.PhpJavaServlet#handleSocketConnection(HttpServletRequest, HttpServletResponse, String, boolean)
+ * see io.soluble.pjb.servlet.PhpJavaServlet#handleRedirectConnection(HttpServletRequest, HttpServletResponse)
+ * @param req
+ * @param res
+ * @throws java.io.IOException
*/
+ @Override
protected void doPut(HttpRequest req, HttpResponse res) throws IOException {
- ChunkedInputStream sin = null;
- ChunkedOutputStream sout = null;
+ ChunkedInputStream sin;
+ ChunkedOutputStream sout;
String transferEncoding = getHeader("Transfer-Encoding", req);
boolean isChunked = "chunked".equals(transferEncoding);
if (!isChunked) throw new IllegalStateException("Please use a JEE server or servlet engine.");
@@ -246,102 +250,101 @@ protected void doPut(HttpRequest req, HttpResponse res) throws IOException {
protected boolean showDirectory(String fullName, File f, int length, HttpRequest req, HttpResponse res) throws IOException {
if (!f.isDirectory()) return false;
ByteArrayOutputStream xout = new ByteArrayOutputStream();
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(xout, Util.UTF8)));
- out.println("");
- out.println("");
- out.println("Directory Listing for " + fullName + " - Up To " + parentName + "
");
- out.println("
");
+ out.println("");
- out.println(" ");
- File[] dir = f.listFiles();
- int count = 0;
- StringBuffer b = new StringBuffer();
- for (int i = 0; i < dir.length; i++) {
- File file = dir[i];
- if (file.isHidden()) continue;
- boolean even = count++ % 2 == 0;
- if (even)
- out.println("Filename ");
- out.println("Type ");
- out.println("Size ");
- out.println("Last Modified ");
- out.println("");
- out.println("");
- else
- out.println(" ");
-
- // mozilla replaces everything after the last slash:
- // foo/bar baz becomes foo/baz and foo/bar/ baz becomes foo/bar/baz
- if (fullName.length() != 0 && !fullName.endsWith("/")) {
- b.append(f.getName());
- b.append("/");
- }
- b.append(file.getName());
- if (file.isDirectory()) b.append("/");
-
- out.println(" ");
-
- if (file.isDirectory()) {
- out.println("" + file.getName() + "/ ");
- out.println(" ");
- out.println("directory ");
- } else {
- out.println("" + file.getName() + "");
- out.println(" ");
- out.println("file ");
- }
- out.println("" + file.length() + " ");
- out.println("" + Util.formatDateTime(file.lastModified()) + " ");
+ try (PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(xout, Util.UTF8)))) {
+ out.println("");
+ out.println("");
+ out.println("Directory Listing for " + fullName + " - Up To " + parentName + "
");
+ out.println("
");
- out.println("");
+ out.println(" ");
- b.setLength(0);
- }
- out.println("Filename ");
+ out.println("Type ");
+ out.println("Size ");
+ out.println("Last Modified ");
+ out.println("");
out.println("Simple JSR 223 enabled web server version 0.0.1
");
- out.println("Available script engines
");
- try {
- Class c = Class.forName("javax.script.ScriptEngineManager");
- Object o = c.newInstance();
- Method ex = c.getMethod("getEngineByExtension", new Class[]{String.class});
- if (ex.invoke(o, (Object[]) new String[]{"php"}) == null) {
- out.println("Warning: php-script.jar not found. Please copy it to the directory containing JavaBridge.jar before starting JavaBridge.
");
+ File[] dir = f.listFiles();
+ int count = 0;
+ StringBuilder b = new StringBuilder();
+ for (File file : dir) {
+ if (file.isHidden()) continue;
+ boolean even = count++ % 2 == 0;
+ if (even)
+ out.println("");
+ else
+ out.println(" ");
+
+ // mozilla replaces everything after the last slash:
+ // foo/bar baz becomes foo/baz and foo/bar/ baz becomes foo/bar/baz
+ if (fullName.length() != 0 && !fullName.endsWith("/")) {
+ b.append(f.getName());
+ b.append("/");
+ }
+ b.append(file.getName());
+ if (file.isDirectory()) b.append("/");
+
+ out.println(" ");
+ b.setLength(0);
}
-
- Method e = c.getMethod("getEngineFactories", new Class[]{});
- List factories = (List) e.invoke(o, new Object[]{});
- StringBuffer buf = new StringBuffer();
- for (Iterator ii = factories.iterator(); ii.hasNext(); ) {
- o = ii.next();
- Method getName = o.getClass().getMethod("getEngineName", new Class[]{});
- Method getVersion = o.getClass().getMethod("getEngineVersion", new Class[]{});
- Method getNames = o.getClass().getMethod("getNames", new Class[]{});
- Method getExtensions = o.getClass().getMethod("getExtensions", new Class[]{});
- buf.append(" ");
+
+ if (file.isDirectory()) {
+ out.println("" + file.getName() + "/ ");
+ out.println(" ");
+ out.println("directory ");
+ } else {
+ out.println("" + file.getName() + "");
+ out.println(" ");
+ out.println("file ");
+ }
+ out.println("" + file.length() + " ");
+ out.println("" + Util.formatDateTime(file.lastModified()) + " ");
+ out.println("Simple JSR 223 enabled web server version 0.0.1
");
+ out.println("Available script engines
");
+ try {
+ Class c = Class.forName("javax.script.ScriptEngineManager");
+ Object o = c.newInstance();
+ Method ex = c.getMethod("getEngineByExtension", new Class[]{String.class});
+ if (ex.invoke(o, (Object[]) new String[]{"php"}) == null) {
+ out.println("Warning: php-script.jar not found. Please copy it to the directory containing JavaBridge.jar before starting JavaBridge.
");
+ out.println("");
+ out.println("");
+ res.addHeader("Content-Type", "text/html; charset=UTF-8");
+ res.addHeader("Last-Modified", Util.formatDateTime(f.lastModified()));
}
- out.println("");
- out.println("");
- out.println("");
- res.addHeader("Content-Type", "text/html; charset=UTF-8");
- res.addHeader("Last-Modified", Util.formatDateTime(f.lastModified()));
- out.close();
int outLength = xout.size();
res.setContentLength(outLength);
xout.writeTo(res.getOutputStream());
@@ -353,6 +356,7 @@ protected boolean showDirectory(String fullName, File f, int length, HttpRequest
* JSR223 script engine to the java ext dirs (usually /usr/share/java/ext or /usr/java/packages/lib/ext) and start the HTTP server:
* java -jar JavaBridge.jar HTTP_LOCAL:8080. Browse to http://localhost:8080/test.php.
*
+ * @param name
* @param f The full name as a file
* @param params The request parameter
* @param length The length of the file
@@ -368,11 +372,13 @@ protected boolean handleScriptContent(String name, String params, File f, int le
/**
* Display a simple text file
*
+ * @param name
* @param f The full name as a file
* @param params The request parameter
* @param length The length of the file
* @param req The HTTP request object
* @param res The HTTP response object
+ * @param show
* @throws IOException
*/
protected void showTextFile(String name, String params, File f, int length, HttpRequest req, HttpResponse res, boolean show) throws IOException {
@@ -383,11 +389,11 @@ protected void showTextFile(String name, String params, File f, int length, Http
res.addHeader("Last-Modified", Util.formatDateTime(f.lastModified()));
if (show) res.addHeader("Content-Type", "text/plain");
res.setContentLength(length);
- InputStream in = new FileInputStream(f);
- buf = new byte[Util.BUF_SIZE];
- out = res.getOutputStream();
- while ((c = in.read(buf)) != -1) out.write(buf, 0, c);
- in.close();
+ try (InputStream in = new FileInputStream(f)) {
+ buf = new byte[Util.BUF_SIZE];
+ out = res.getOutputStream();
+ while ((c = in.read(buf)) != -1) out.write(buf, 0, c);
+ }
}
/**
@@ -398,7 +404,9 @@ protected void showTextFile(String name, String params, File f, int length, Http
*
* @param req The HttpRequest
* @param res The HttpResponse
+ * @throws java.io.IOException
*/
+ @Override
protected void doGet(HttpRequest req, HttpResponse res) throws IOException {
handleDoGet(req, res);
}
@@ -410,6 +418,7 @@ protected void doGet(HttpRequest req, HttpResponse res) throws IOException {
*
* @param req The HttpRequest
* @param res The HttpResponse
+ * @throws java.io.IOException
*/
protected void handleDoGet(HttpRequest req, HttpResponse res) throws IOException {
@@ -432,7 +441,7 @@ protected void handleDoGet(HttpRequest req, HttpResponse res) throws IOException
}
File f = Standalone.getCanonicalWindowsFile(name);
if (f == null || !f.exists()) f = new File(Util.HOME_DIR, name);
- if (f == null || !f.exists()) return;
+ if (!f.exists()) return;
if (f.isHidden()) return;
long l = f.length();
if (l >= Integer.MAX_VALUE) throw new IOException("file " + name + " too large");
diff --git a/server/php/java/bridge/JavaBridgeSecurityManager.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeSecurityManager.java
similarity index 88%
rename from server/php/java/bridge/JavaBridgeSecurityManager.java
rename to src/main/java/io/soluble/pjb/bridge/JavaBridgeSecurityManager.java
index 644ab5d..a33ed60 100644
--- a/server/php/java/bridge/JavaBridgeSecurityManager.java
+++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeSecurityManager.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -30,11 +30,11 @@
* A custom security manager for the PHP/Java Bridge.
*
");
+ }
+
+ Method e = c.getMethod("getEngineFactories", new Class[]{});
+ List factories = (List) e.invoke(o, new Object[]{});
+ StringBuffer buf = new StringBuffer();
+ for (Iterator ii = factories.iterator(); ii.hasNext(); ) {
+ o = ii.next();
+ Method getName = o.getClass().getMethod("getEngineName", new Class[]{});
+ Method getVersion = o.getClass().getMethod("getEngineVersion", new Class[]{});
+ Method getNames = o.getClass().getMethod("getNames", new Class[]{});
+ Method getExtensions = o.getClass().getMethod("getExtensions", new Class[]{});
+ buf.append("
- * PHP_HOME=/usr/lib/php/modules java -Dphp.java.bridge.base=${PHP_HOME} -Djava.security.policy=${PHP_HOME}/javabridge.policy -jar ${PHP_HOME}/JavaBridge.jar
+ * PHP_HOME=/usr/lib/php/modules java -Dio.soluble.pjb.bridge.base=${PHP_HOME} -Djava.security.policy=${PHP_HOME}/javabridge.policy -jar ${PHP_HOME}/JavaBridge.jar
*
* Example options for eclipse:
*
- * -Dphp.java.bridge.base=${workspace_loc}${project_path}/
+ * -Dio.soluble.pjb.bridge.base=${workspace_loc}${project_path}/
* -Djava.security.policy=${workspace_loc}${project_path}/javabridge.policy
*
*
@@ -45,8 +45,10 @@ public class JavaBridgeSecurityManager extends SecurityManager {
protected static final Permission MODIFY_THREAD_PERMISSION = new RuntimePermission("modifyThread");
/**
- * @inheritDoc Internal groups may pass, user groups are checked against the javabridge.policy file.
+ * {@inheritDoc}
+ * Internal groups may pass, user groups are checked against the javabridge.policy file.
*/
+ @Override
public void checkAccess(ThreadGroup g) {
if (g == null) {
throw new NullPointerException("thread group can't be null");
@@ -77,6 +79,7 @@ else if (g instanceof AppThreadPool.AppGroup)
*
* @return The current thread group
*/
+ @Override
public ThreadGroup getThreadGroup() {
try {
AppThreadPool.Delegate delegate = (AppThreadPool.Delegate) Thread.currentThread();
@@ -88,10 +91,12 @@ public ThreadGroup getThreadGroup() {
}
/**
- * @inheritDoc System.exit(...) can by switched off by removing
+ * {@inheritDoc}
+ * System.exit(...) can by switched off by removing
* permission java.lang.RuntimePermission "exitVM";
* from the policy file.
*/
+ @Override
public void checkExit(int status) {
//super.checkExit(status);
diff --git a/src/main/java/io/soluble/pjb/bridge/JavaInc.java b/src/main/java/io/soluble/pjb/bridge/JavaInc.java
new file mode 100644
index 0000000..665b343
--- /dev/null
+++ b/src/main/java/io/soluble/pjb/bridge/JavaInc.java
@@ -0,0 +1,2089 @@
+package io.soluble.pjb.bridge;
+public class JavaInc {
+ private static final String data = "0) {\n"+
+"$thiz=$ar[$arLen-1];\n"+
+"return dirname($thiz);\n"+
+"} else {\n"+
+"return \"java\";\n"+
+"}\n"+
+"}\n"+
+"function java_truncate($str) {\n"+
+"if (strlen($str)>955)\n"+
+"return substr($str,0,475).'[...]'.substr($str,-475);\n"+
+"return $str;\n"+
+"}\n"+
+"class java_JavaException extends Exception {\n"+
+"function __toString() {return $this->getMessage();}\n"+
+"};\n"+
+"class java_RuntimeException extends java_JavaException {};\n"+
+"class java_IOException extends java_JavaException {};\n"+
+"class java_ConnectException extends java_IOException {};\n"+
+"class java_IllegalStateException extends java_RuntimeException {};\n"+
+"class java_IllegalArgumentException extends java_RuntimeException {\n"+
+"function __construct($ob) {\n"+
+"parent::__construct(\"illegal argument: \".gettype($ob));\n"+
+"}\n"+
+"};\n"+
+"function java_autoload_function5($x) {\n"+
+"$s=str_replace(\"_\",\".\",$x);\n"+
+"$c=__javaproxy_Client_getClient();\n"+
+"if(!($c->invokeMethod(0,\"typeExists\",array($s)))) return false;\n"+
+"$i=\"class ${x} extends Java {\".\n"+
+"\"static function type(\\$sub=null){if(\\$sub) \\$sub='\\$'.\\$sub; return java('${s}'.\\\"\\$sub\\\");}\".\n"+
+"'function __construct() {$args=func_get_args();'.\n"+
+"'array_unshift($args,'.\"'$s'\".'); parent::__construct($args);}}';\n"+
+"eval (\"$i\");\n"+
+"return true;\n"+
+"}\n"+
+"function java_autoload_function($x) {\n"+
+"$idx=strrpos($x,\"\\\\\"); if (!$idx) return java_autoload_function5($x);\n"+
+"$str=str_replace(\"\\\\\",\".\",$x);\n"+
+"$client=__javaproxy_Client_getClient();\n"+
+"if(!($client->invokeMethod(0,\"typeExists\",array($str)))) return false;\n"+
+"$package=substr($x,0,$idx);\n"+
+"$name=substr($x,1+$idx);\n"+
+"$instance=\"namespace $package; class ${name} extends \\\\Java {\".\n"+
+"\"static function type(\\$sub=null){if(\\$sub) \\$sub='\\$'.\\$sub;return \\\\java('${str}'.\\\"\\$sub\\\");}\".\n"+
+"\"static function __callStatic(\\$procedure,\\$args) {return \\\\java_invoke(\\\\java('${str}'),\\$procedure,\\$args);}\".\n"+
+"'function __construct() {$args=func_get_args();'.\n"+
+"'array_unshift($args,'.\"'$str'\".'); parent::__construct($args);}}';\n"+
+"eval (\"$instance\");\n"+
+"return true;\n"+
+"}\n"+
+"if(!defined(\"JAVA_DISABLE_AUTOLOAD\") && function_exists(\"spl_autoload_register\")) spl_autoload_register(\"java_autoload_function\");\n"+
+"function java_autoload($libs=null) {\n"+
+"trigger_error('Please use tomcat or jee hot deployment instead',E_USER_WARNING);\n"+
+"}\n"+
+"function java_virtual($path,$return=false) {\n"+
+"$req=java_context()->getHttpServletRequest();\n"+
+"$req=new java(\"io.soluble.pjb.servlet.VoidInputHttpServletRequest\",$req);\n"+
+"$res=java_context()->getHttpServletResponse();\n"+
+"$res=new java(\"io.soluble.pjb.servlet.RemoteHttpServletResponse\",$res);\n"+
+"$req->getRequestDispatcher($path)->include($req,$res);\n"+
+"if ($return) return $res->getBufferContents();\n"+
+"echo $res->getBufferContents();\n"+
+"return true;\n"+
+"}\n"+
+"function Java($name) {\n"+
+"static $classMap=array();\n"+
+"if(array_key_exists($name,$classMap)) return $classMap[$name];\n"+
+"return $classMap[$name]=new JavaClass($name);\n"+
+"}\n"+
+"function java_get_closure() {return java_closure_array(func_get_args());}\n"+
+"function java_wrap() {return java_closure_array(func_get_args());}\n"+
+"function java_get_values($arg) { return java_values($arg); }\n"+
+"function java_get_session() {return java_session_array(func_get_args());}\n"+
+"function java_get_context() {return java_context(); }\n"+
+"function java_get_server_name() { return java_server_name(); }\n"+
+"function java_isnull($value) { return is_null (java_values ($value)); }\n"+
+"function java_is_null($value) { return is_null (java_values ($value)); }\n"+
+"function java_istrue($value) { return (boolean)(java_values ($value)); }\n"+
+"function java_is_true($value) { return (boolean)(java_values ($value)); }\n"+
+"function java_isfalse($value) { return !(java_values ($value)); }\n"+
+"function java_is_false($value) { return !(java_values ($value)); }\n"+
+"function java_set_encoding($enc) { return java_set_file_encoding ($enc); }\n"+
+"function java_call_with_continuation($kontinuation=null) {\n"+
+"if (java_getHeader(\"X_JAVABRIDGE_INCLUDE\",$_SERVER) && !java_getHeader(\"X_JAVABRIDGE_INCLUDE_ONLY\",$_SERVER)) {\n"+
+"if (is_null($kontinuation))\n"+
+"java_context()->call(java_closure());\n"+
+"elseif (is_string($kontinuation))\n"+
+"java_context()->call(call_user_func($kontinuation));\n"+
+"elseif ($kontinuation instanceof java_JavaType)\n"+
+"java_context()->call($kontinuation);\n"+
+"else\n"+
+"java_context()->call(java_closure($kontinuation));\n"+
+"}\n"+
+"}\n"+
+"function java_defineHostFromInitialQuery($java_base) {\n"+
+"if($java_base!=\"java\") {\n"+
+"$url=parse_url($java_base);\n"+
+"if(isset($url[\"scheme\"]) && ($url[\"scheme\"]==\"http\" || $url[\"scheme\"]==\"https\")) {\n"+
+"$scheme=$url[\"scheme\"]==\"https\" ? \"ssl://\" : \"\";\n"+
+"$host=$url[\"host\"];\n"+
+"$port=$url[\"port\"];\n"+
+"$path=$url[\"path\"];\n"+
+"define (\"JAVA_HOSTS\",\"${scheme}${host}:${port}\");\n"+
+"$dir=dirname($path);\n"+
+"define (\"JAVA_SERVLET\",\"$dir/servlet.phpjavabridge\");\n"+
+"return true;\n"+
+"}\n"+
+"}\n"+
+"return false;\n"+
+"}\n"+
+"define(\"JAVA_PEAR_VERSION\",\"6.2.11\");\n"+
+"if(!defined(\"JAVA_SEND_SIZE\"))\n"+
+"define(\"JAVA_SEND_SIZE\",8192);\n"+
+"if(!defined(\"JAVA_RECV_SIZE\"))\n"+
+"define(\"JAVA_RECV_SIZE\",8192);\n"+
+"if(!defined(\"JAVA_HOSTS\")) {\n"+
+"if(!java_defineHostFromInitialQuery(java_get_base())) {\n"+
+"if ($java_ini=get_cfg_var(\"java.hosts\")) define(\"JAVA_HOSTS\",$java_ini);\n"+
+"else define(\"JAVA_HOSTS\",\"127.0.0.1:8080\");\n"+
+"}\n"+
+"}\n"+
+"if(!defined(\"JAVA_SERVLET\")) {\n"+
+"if (!(($java_ini=get_cfg_var(\"java.servlet\"))===false)) define(\"JAVA_SERVLET\",$java_ini);\n"+
+"else define(\"JAVA_SERVLET\",1);\n"+
+"}\n"+
+"if(!defined(\"JAVA_LOG_LEVEL\"))\n"+
+"if (!(($java_ini=get_cfg_var(\"java.log_level\"))===false)) define(\"JAVA_LOG_LEVEL\",(int)$java_ini);\n"+
+"else define(\"JAVA_LOG_LEVEL\",null);\n"+
+"if (!defined(\"JAVA_PREFER_VALUES\"))\n"+
+"if ($java_ini=get_cfg_var(\"java.prefer_values\")) define(\"JAVA_PREFER_VALUES\",$java_ini);\n"+
+"else define(\"JAVA_PREFER_VALUES\",0);\n"+
+"class java_SimpleFactory {\n"+
+"public $client;\n"+
+"function java_SimpleFactory($client) {\n"+
+"$this->client=$client;\n"+
+"}\n"+
+"function getProxy($result,$signature,$exception,$wrap) {\n"+
+"return $result;\n"+
+"}\n"+
+"function checkResult($result) {\n"+
+"}\n"+
+"}\n"+
+"class java_ProxyFactory extends java_SimpleFactory {\n"+
+"function create($result,$signature) {\n"+
+"return new java_JavaProxy($result,$signature);\n"+
+"}\n"+
+"function createInternal($proxy) {\n"+
+"return new java_InternalJava($proxy);\n"+
+"}\n"+
+"function getProxy($result,$signature,$exception,$wrap) {\n"+
+"$proxy=$this->create($result,$signature);\n"+
+"if($wrap) $proxy=$this->createInternal($proxy);\n"+
+"return $proxy;\n"+
+"}\n"+
+"}\n"+
+"class java_ArrayProxyFactory extends java_ProxyFactory {\n"+
+"function create($result,$signature) {\n"+
+"return new java_ArrayProxy($result,$signature);\n"+
+"}\n"+
+"}\n"+
+"class java_IteratorProxyFactory extends java_ProxyFactory {\n"+
+"function create($result,$signature) {\n"+
+"return new java_IteratorProxy($result,$signature);\n"+
+"}\n"+
+"}\n"+
+"class java_ExceptionProxyFactory extends java_SimpleFactory {\n"+
+"function create($result,$signature) {\n"+
+"return new java_ExceptionProxy($result,$signature);\n"+
+"}\n"+
+"function getProxy($result,$signature,$exception,$wrap) {\n"+
+"$proxy=$this->create($result,$signature);\n"+
+"if($wrap) $proxy=new java_InternalException($proxy,$exception);\n"+
+"return $proxy;\n"+
+"}\n"+
+"}\n"+
+"class java_ThrowExceptionProxyFactory extends java_ExceptionProxyFactory {\n"+
+"function getProxy($result,$signature,$exception,$wrap) {\n"+
+"$proxy=$this->create($result,$signature);\n"+
+"$proxy=new java_InternalException($proxy,$exception);\n"+
+"return $proxy;\n"+
+"}\n"+
+"function checkResult($result) {\n"+
+"if (JAVA_PREFER_VALUES || ($result->__hasDeclaredExceptions=='T'))\n"+
+"throw $result;\n"+
+"else {\n"+
+"trigger_error(\"Unchecked exception detected: \".java_truncate($result->__toString()),E_USER_WARNING);\n"+
+"}\n"+
+"}\n"+
+"}\n"+
+"class java_CacheEntry {\n"+
+"public $fmt,$signature,$factory,$java;\n"+
+"public $resultVoid;\n"+
+"function java_CacheEntry($fmt,$signature,$factory,$resultVoid) {\n"+
+"$this->fmt=$fmt;\n"+
+"$this->signature=$signature;\n"+
+"$this->factory=$factory;\n"+
+"$this->resultVoid=$resultVoid;\n"+
+"}\n"+
+"}\n"+
+"class java_Arg {\n"+
+"public $client;\n"+
+"public $exception;\n"+
+"public $factory,$val;\n"+
+"public $signature;\n"+
+"function java_Arg($client) {\n"+
+"$this->client=$client;\n"+
+"$this->factory=$client->simpleFactory;\n"+
+"}\n"+
+"function linkResult(&$val) {\n"+
+"$this->val=&$val;\n"+
+"}\n"+
+"function setResult($val) {\n"+
+"$this->val=&$val;\n"+
+"}\n"+
+"function getResult($wrap) {\n"+
+"$rc=$this->factory->getProxy($this->val,$this->signature,$this->exception,$wrap);\n"+
+"$factory=$this->factory;\n"+
+"$this->factory=$this->client->simpleFactory;\n"+
+"$factory->checkResult($rc);\n"+
+"return $rc;\n"+
+"}\n"+
+"function setFactory($factory) {\n"+
+"$this->factory=$factory;\n"+
+"}\n"+
+"function setException($string) {\n"+
+"$this->exception=$string;\n"+
+"}\n"+
+"function setVoidSignature() {\n"+
+"$this->signature=\"@V\";\n"+
+"$key=$this->client->currentCacheKey;\n"+
+"if($key && $key[0]!='~') {\n"+
+"$this->client->currentArgumentsFormat[6]=\"3\";\n"+
+"$cacheEntry=new java_CacheEntry($this->client->currentArgumentsFormat,$this->signature,$this->factory,true);\n"+
+"$this->client->methodCache[$key]=$cacheEntry;\n"+
+"}\n"+
+"}\n"+
+"function setSignature($signature) {\n"+
+"$this->signature=$signature;\n"+
+"$key=$this->client->currentCacheKey;\n"+
+"if($key && $key[0]!='~') {\n"+
+"$cacheEntry=new java_CacheEntry($this->client->currentArgumentsFormat,$this->signature,$this->factory,false);\n"+
+"$this->client->methodCache[$key]=$cacheEntry;\n"+
+"}\n"+
+"}\n"+
+"}\n"+
+"class java_CompositeArg extends java_Arg {\n"+
+"public $parentArg;\n"+
+"public $idx;\n"+
+"public $type;\n"+
+"public $counter;\n"+
+"function java_CompositeArg($client,$type) {\n"+
+"parent::java_Arg($client);\n"+
+"$this->type=$type;\n"+
+"$this->val=array();\n"+
+"$this->counter=0;\n"+
+"}\n"+
+"function setNextIndex() {\n"+
+"$this->idx=$this->counter++;\n"+
+"}\n"+
+"function setIndex($val) {\n"+
+"$this->idx=$val;\n"+
+"}\n"+
+"function linkResult(&$val) {\n"+
+"$this->val[$this->idx]=&$val;\n"+
+"}\n"+
+"function setResult($val) {\n"+
+"$this->val[$this->idx]=$this->factory->getProxy($val,$this->signature,$this->exception,true);\n"+
+"$this->factory=$this->client->simpleFactory;\n"+
+"}\n"+
+"}\n"+
+"class java_ApplyArg extends java_CompositeArg {\n"+
+"public $m,$p,$v,$n;\n"+
+"function java_ApplyArg($client,$type,$m,$p,$v,$n) {\n"+
+"parent::java_CompositeArg($client,$type);\n"+
+"$this->m=$m;\n"+
+"$this->p=$p;\n"+
+"$this->v=$v;\n"+
+"$this->n=$n;\n"+
+"}\n"+
+"}\n"+
+"class java_Client {\n"+
+"public $RUNTIME;\n"+
+"public $result,$exception;\n"+
+"public $parser;\n"+
+"public $simpleArg,$compositeArg;\n"+
+"public $simpleFactory,\n"+
+"$proxyFactory,$iteratorProxyFacroty,\n"+
+"$arrayProxyFactory,$exceptionProxyFactory,$throwExceptionProxyFactory;\n"+
+"public $arg;\n"+
+"public $asyncCtx,$cancelProxyCreationCounter;\n"+
+"public $globalRef;\n"+
+"public $stack;\n"+
+"public $defaultCache=array(),$asyncCache=array(),$methodCache;\n"+
+"public $isAsync=0;\n"+
+"public $currentCacheKey,$currentArgumentsFormat;\n"+
+"public $cachedJavaPrototype;\n"+
+"public $sendBuffer,$preparedToSendBuffer;\n"+
+"public $inArgs;\n"+
+"function java_Client() {\n"+
+"$this->RUNTIME=array();\n"+
+"$this->RUNTIME[\"NOTICE\"]='***USE echo java_inspect(jVal) OR print_r(java_values(jVal)) TO SEE THE CONTENTS OF THIS JAVA OBJECT!***';\n"+
+"$this->parser=new java_Parser($this);\n"+
+"$this->protocol=new java_Protocol($this);\n"+
+"$this->simpleFactory=new java_SimpleFactory($this);\n"+
+"$this->proxyFactory=new java_ProxyFactory($this);\n"+
+"$this->arrayProxyFactory=new java_ArrayProxyFactory($this);\n"+
+"$this->iteratorProxyFactory=new java_IteratorProxyFactory($this);\n"+
+"$this->exceptionProxyFactory=new java_ExceptionProxyFactory($this);\n"+
+"$this->throwExceptionProxyFactory=new java_ThrowExceptionProxyFactory($this);\n"+
+"$this->cachedJavaPrototype=new java_JavaProxyProxy($this);\n"+
+"$this->simpleArg=new java_Arg($this);\n"+
+"$this->globalRef=new java_GlobalRef();\n"+
+"$this->asyncCtx=$this->cancelProxyCreationCounter=0;\n"+
+"$this->methodCache=$this->defaultCache;\n"+
+"$this->inArgs=false;\n"+
+"}\n"+
+"function read($size) {\n"+
+"return $this->protocol->read($size);\n"+
+"}\n"+
+"function setDefaultHandler() {\n"+
+"$this->methodCache=$this->defaultCache;\n"+
+"}\n"+
+"function setAsyncHandler() {\n"+
+"$this->methodCache=$this->asyncCache;\n"+
+"}\n"+
+"function handleRequests() {\n"+
+"$tail_call=false;\n"+
+"do {\n"+
+"$this->stack=array($this->arg=$this->simpleArg);\n"+
+"$this->idx=0;\n"+
+"$this->parser->parse();\n"+
+"if((count($this->stack)) > 1) {\n"+
+"$arg=array_pop($this->stack);\n"+
+"$this->apply($arg);\n"+
+"$tail_call=true;\n"+
+"} else {\n"+
+"$tail_call=false;\n"+
+"}\n"+
+"$this->stack=null;\n"+
+"} while($tail_call);\n"+
+"return 1;\n"+
+"}\n"+
+"function getWrappedResult($wrap) {\n"+
+"return $this->simpleArg->getResult($wrap);\n"+
+"}\n"+
+"function getInternalResult() {\n"+
+"return $this->getWrappedResult(false);\n"+
+"}\n"+
+"function getResult() {\n"+
+"return $this->getWrappedResult(true);\n"+
+"}\n"+
+"function getProxyFactory($type) {\n"+
+"switch($type[0]) {\n"+
+"case 'E':\n"+
+"$factory=$this->exceptionProxyFactory;\n"+
+"break;\n"+
+"case 'C':\n"+
+"$factory=$this->iteratorProxyFactory;\n"+
+"break;\n"+
+"case 'A':\n"+
+"$factory=$this->arrayProxyFactory;\n"+
+"break;\n"+
+"default:\n"+
+"case 'O':\n"+
+"$factory=$this->proxyFactory;\n"+
+"}\n"+
+"return $factory;\n"+
+"}\n"+
+"function link(&$arg,&$newArg) {\n"+
+"$arg->linkResult($newArg->val);\n"+
+"$newArg->parentArg=$arg;\n"+
+"}\n"+
+"function getExact($str) {\n"+
+"return hexdec($str);\n"+
+"}\n"+
+"function getInexact($str) {\n"+
+"$val=null;\n"+
+"sscanf($str,\"%e\",$val);\n"+
+"return $val;\n"+
+"}\n"+
+"function begin($name,$st) {\n"+
+"$arg=$this->arg;\n"+
+"switch($name[0]) {\n"+
+"case 'A':\n"+
+"$object=$this->globalRef->get($this->getExact($st['v']));\n"+
+"$newArg=new java_ApplyArg($this,'A',\n"+
+"$this->parser->getData($st['m']),\n"+
+"$this->parser->getData($st['p']),\n"+
+"$object,\n"+
+"$this->getExact($st['n']));\n"+
+"$this->link($arg,$newArg);\n"+
+"array_push($this->stack,$this->arg=$newArg);\n"+
+"break;\n"+
+"case 'X':\n"+
+"$newArg=new java_CompositeArg($this,$st['t']);\n"+
+"$this->link($arg,$newArg);\n"+
+"array_push($this->stack,$this->arg=$newArg);\n"+
+"break;\n"+
+"case 'P':\n"+
+"if($arg->type=='H') {\n"+
+"$s=$st['t'];\n"+
+"if($s[0]=='N') {\n"+
+"$arg->setIndex($this->getExact($st['v']));\n"+
+"} else {\n"+
+"$arg->setIndex($this->parser->getData($st['v']));\n"+
+"}\n"+
+"} else {\n"+
+"$arg->setNextIndex();\n"+
+"}\n"+
+"break;\n"+
+"case 'S':\n"+
+"$arg->setResult($this->parser->getData($st['v']));\n"+
+"break;\n"+
+"case 'B':\n"+
+"$s=$st['v'];\n"+
+"$arg->setResult($s[0]=='T');\n"+
+"break;\n"+
+"case 'L':\n"+
+"$sign=$st['p'];\n"+
+"$val=$this->getExact($st['v']);\n"+
+"if($sign[0]=='A') $val*=-1;\n"+
+"$arg->setResult($val);\n"+
+"break;\n"+
+"case 'D':\n"+
+"$arg->setResult($this->getInexact($st['v']));\n"+
+"break;\n"+
+"case 'V':\n"+
+"if ($st['n']!='T') {\n"+
+"$arg->setVoidSignature();\n"+
+"}\n"+
+"case 'N':\n"+
+"$arg->setResult(null);\n"+
+"break;\n"+
+"case 'F':\n"+
+"break;\n"+
+"case 'O':\n"+
+"$arg->setFactory($this->getProxyFactory($st['p']));\n"+
+"$arg->setResult($this->asyncCtx=$this->getExact($st['v']));\n"+
+"if($st['n']!='T') $arg->setSignature($st['m']);\n"+
+"break;\n"+
+"case 'E':\n"+
+"$arg->setFactory($this->throwExceptionProxyFactory);\n"+
+"$arg->setException($st['m']);\n"+
+"$arg->setResult($this->asyncCtx=$this->getExact($st['v']));\n"+
+"break;\n"+
+"default:\n"+
+"$this->parser->parserError();\n"+
+"}\n"+
+"}\n"+
+"function end($name) {\n"+
+"switch($name[0]) {\n"+
+"case 'X':\n"+
+"$frame=array_pop($this->stack);\n"+
+"$this->arg=$frame->parentArg;\n"+
+"break;\n"+
+"}\n"+
+"}\n"+
+"function createParserString() {\n"+
+"return new java_ParserString();\n"+
+"}\n"+
+"function writeArg($arg) {\n"+
+"if(is_string($arg)) {\n"+
+"$this->protocol->writeString($arg);\n"+
+"} else if(is_object($arg)) {\n"+
+"if ((!$arg instanceof java_JavaType)) {\n"+
+"error_log((string)new java_IllegalArgumentException($arg));\n"+
+"trigger_error(\"argument '\".get_class($arg).\"' is not a Java object,using NULL instead\",E_USER_WARNING);\n"+
+"$this->protocol->writeObject(null);\n"+
+"} else {\n"+
+"$this->protocol->writeObject($arg->__java);\n"+
+"}\n"+
+"} else if(is_null($arg)) {\n"+
+"$this->protocol->writeObject(null);\n"+
+"} else if(is_bool($arg)) {\n"+
+"$this->protocol->writeBoolean($arg);\n"+
+"} else if(is_integer($arg)) {\n"+
+"$this->protocol->writeLong($arg);\n"+
+"} else if(is_float($arg)) {\n"+
+"$this->protocol->writeDouble($arg);\n"+
+"} else if(is_array($arg)) {\n"+
+"$wrote_begin=false;\n"+
+"foreach($arg as $key=>$val) {\n"+
+"if(is_string($key)) {\n"+
+"if(!$wrote_begin) {\n"+
+"$wrote_begin=1;\n"+
+"$this->protocol->writeCompositeBegin_h();\n"+
+"}\n"+
+"$this->protocol->writePairBegin_s($key);\n"+
+"$this->writeArg($val);\n"+
+"$this->protocol->writePairEnd();\n"+
+"} else {\n"+
+"if(!$wrote_begin) {\n"+
+"$wrote_begin=1;\n"+
+"$this->protocol->writeCompositeBegin_h();\n"+
+"}\n"+
+"$this->protocol->writePairBegin_n($key);\n"+
+"$this->writeArg($val);\n"+
+"$this->protocol->writePairEnd();\n"+
+"}\n"+
+"}\n"+
+"if(!$wrote_begin) {\n"+
+"$this->protocol->writeCompositeBegin_a();\n"+
+"}\n"+
+"$this->protocol->writeCompositeEnd();\n"+
+"}\n"+
+"}\n"+
+"function writeArgs($args) {\n"+
+"$this->inArgs=true;\n"+
+"$n=count($args);\n"+
+"for($i=0; $i<$n; $i++) {\n"+
+"$this->writeArg($args[$i]);\n"+
+"}\n"+
+"$this->inArgs=false;\n"+
+"}\n"+
+"function createObject($name,$args) {\n"+
+"$this->protocol->createObjectBegin($name);\n"+
+"$this->writeArgs($args);\n"+
+"$this->protocol->createObjectEnd();\n"+
+"$val=$this->getInternalResult();\n"+
+"return $val;\n"+
+"}\n"+
+"function referenceObject($name,$args) {\n"+
+"$this->protocol->referenceBegin($name);\n"+
+"$this->writeArgs($args);\n"+
+"$this->protocol->referenceEnd();\n"+
+"$val=$this->getInternalResult();\n"+
+"return $val;\n"+
+"}\n"+
+"function getProperty($object,$property) {\n"+
+"$this->protocol->propertyAccessBegin($object,$property);\n"+
+"$this->protocol->propertyAccessEnd();\n"+
+"return $this->getResult();\n"+
+"}\n"+
+"function setProperty($object,$property,$arg) {\n"+
+"$this->protocol->propertyAccessBegin($object,$property);\n"+
+"$this->writeArg($arg);\n"+
+"$this->protocol->propertyAccessEnd();\n"+
+"$this->getResult();\n"+
+"}\n"+
+"function invokeMethod($object,$method,$args) {\n"+
+"$this->protocol->invokeBegin($object,$method);\n"+
+"$this->writeArgs($args);\n"+
+"$this->protocol->invokeEnd();\n"+
+"$val=$this->getResult();\n"+
+"return $val;\n"+
+"}\n"+
+"function unref($object) {\n"+
+"if (isset($this->protocol)) $this->protocol->writeUnref($object);\n"+
+"}\n"+
+"function apply($arg) {\n"+
+"$name=$arg->p;\n"+
+"$object=$arg->v;\n"+
+"$ob=($object==null) ? $name : array(&$object,$name);\n"+
+"$isAsync=$this->isAsync;\n"+
+"$methodCache=$this->methodCache;\n"+
+"$currentArgumentsFormat=$this->currentArgumentsFormat;\n"+
+"try {\n"+
+"$res=$arg->getResult(true);\n"+
+"if((($object==null) && !function_exists($name)) || (!($object==null) && !method_exists($object,$name))) throw new JavaException(\"java.lang.NoSuchMethodError\",\"$name\");\n"+
+"$res=call_user_func_array($ob,$res);\n"+
+"if (is_object($res) && (!($res instanceof java_JavaType))) {\n"+
+"trigger_error(\"object returned from $name() is not a Java object\",E_USER_WARNING);\n"+
+"$this->protocol->invokeBegin(0,\"makeClosure\");\n"+
+"$this->protocol->writeULong($this->globalRef->add($res));\n"+
+"$this->protocol->invokeEnd();\n"+
+"$res=$this->getResult();\n"+
+"}\n"+
+"$this->protocol->resultBegin();\n"+
+"$this->writeArg($res);\n"+
+"$this->protocol->resultEnd();\n"+
+"} catch (JavaException $e) {\n"+
+"$trace=$e->getTraceAsString();\n"+
+"$this->protocol->resultBegin();\n"+
+"$this->protocol->writeException($e->__java,$trace);\n"+
+"$this->protocol->resultEnd();\n"+
+"} catch(Exception $ex) {\n"+
+"error_log($ex->__toString());\n"+
+"trigger_error(\"Unchecked exception detected in callback\",E_USER_ERROR);\n"+
+"die (1);\n"+
+"}\n"+
+"$this->isAsync=$isAsync;\n"+
+"$this->methodCache=$methodCache;\n"+
+"$this->currentArgumentsFormat=$currentArgumentsFormat;\n"+
+"}\n"+
+"function cast($object,$type) {\n"+
+"switch($type[0]) {\n"+
+"case 'S': case 's':\n"+
+"return $this->invokeMethod(0,\"castToString\",array($object));\n"+
+"case 'B': case 'b':\n"+
+"return $this->invokeMethod(0,\"castToBoolean\",array($object));\n"+
+"case 'L': case 'I': case 'l': case 'i':\n"+
+"return $this->invokeMethod(0,\"castToExact\",array($object));\n"+
+"case 'D': case 'd': case 'F': case 'f':\n"+
+"return $this->invokeMethod(0,\"castToInExact\",array($object));\n"+
+"case 'N': case 'n':\n"+
+"return null;\n"+
+"case 'A': case 'a':\n"+
+"return $this->invokeMethod(0,\"castToArray\",array($object));\n"+
+"case 'O': case 'o':\n"+
+"return $object;\n"+
+"default:\n"+
+"throw new java_RuntimeException(\"$type illegal\");\n"+
+"}\n"+
+"}\n"+
+"function getContext() {\n"+
+"static $cache=null;\n"+
+"if (!is_null($cache)) return $cache;\n"+
+"return $cache=$this->invokeMethod(0,\"getContext\",array());\n"+
+"}\n"+
+"function getSession($args) {\n"+
+"return $this->invokeMethod(0,\"getSession\",$args);\n"+
+"}\n"+
+"function getServerName() {\n"+
+"static $cache=null;\n"+
+"if (!is_null($cache)) return $cache;\n"+
+"return $cache=$this->protocol->getServerName();\n"+
+"}\n"+
+"}\n"+
+"function java_shutdown() {\n"+
+"global $java_initialized;\n"+
+"if (!$java_initialized) return;\n"+
+"if (session_id()) session_write_close();\n"+
+"$client=__javaproxy_Client_getClient();\n"+
+"if (!isset($client->protocol) || $client->inArgs) return;\n"+
+"if ($client->preparedToSendBuffer)\n"+
+"$client->sendBuffer.=$client->preparedToSendBuffer;\n"+
+"$client->sendBuffer.=$client->protocol->getKeepAlive();\n"+
+"$client->protocol->flush();\n"+
+"$client->protocol->keepAlive();\n"+
+"}\n"+
+"register_shutdown_function(\"java_shutdown\");\n"+
+"class java_GlobalRef {\n"+
+"public $map;\n"+
+"function java_GlobalRef() {\n"+
+"$this->map=array();\n"+
+"}\n"+
+"function add($object) {\n"+
+"if(is_null($object)) return 0;\n"+
+"return array_push($this->map,$object);\n"+
+"}\n"+
+"function get($id) {\n"+
+"if(!$id) return 0;\n"+
+"return $this->map[--$id];\n"+
+"}\n"+
+"}\n"+
+"class java_NativeParser {\n"+
+"public $parser,$handler;\n"+
+"public $level,$event;\n"+
+"public $buf;\n"+
+"function java_NativeParser($handler) {\n"+
+"$this->handler=$handler;\n"+
+"$this->parser=xml_parser_create();\n"+
+"xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0);\n"+
+"xml_set_object($this->parser,$this);\n"+
+"xml_set_element_handler($this->parser,\"begin\",\"end\");\n"+
+"xml_parse($this->parser,\"\";\n"+
+"$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT)));\n"+
+"}\n"+
+"function writeBoolean($boolean) {\n"+
+"$this->client->currentArgumentsFormat.=$format=\"response.reset() or response.flush() must be called at the end of each packet.
+ */
+ Response response = null;
+
protected Object getGlobalRef(int i) {
Object ref = bridge.globalRef.get(i);
@@ -55,30 +60,6 @@ protected Object getGlobalRef(int i) {
return ref;
}
- static final Object[] ZERO_ARGS = new Object[0];
-
- private class SimpleContext {
- public void parseID(ParserString string) {
- }
-
- public void setID(Response response) {
- }
- }
-
- private class Context extends SimpleContext {
- protected long id;
-
- public void parseID(ParserString string) {
- this.id = string.getLongValue();
- }
-
- public void setID(Response response) {
- response.setID(id);
- }
- }
-
- private SimpleContext contextCache;
-
SimpleContext getContext() {
if (contextCache != null) return contextCache;
if (bridge.options.passContext()) {
@@ -87,94 +68,6 @@ SimpleContext getContext() {
return contextCache = new SimpleContext();
}
- private abstract class Arg {
- protected byte type;
- protected Object callObject;
- protected String method;
- protected SimpleContext id = getContext();
- protected byte predicate;
- protected Object key;
- protected byte composite;
-
- public abstract void add(Object val);
-
- public abstract Object[] getArgs();
-
- public abstract void reset();
- }
-
- private final class SimpleArg extends Arg {
- private LinkedList list;
-
- public void add(Object val) {
- if (list == null) list = new LinkedList();
- list.add(val);
- }
-
- public Object[] getArgs() {
- return (list == null) ? Request.ZERO_ARGS : list.toArray();
- }
-
- public void reset() {
- list = null;
- composite = 0;
- type = 0;
- callObject = null;
- method = null;
- key = null;
- }
- }
-
- private final class CompositeArg extends Arg {
- private PhpArray ht = null;
- private int count = 0;
- private Arg parent;
-
- public CompositeArg(Arg parent) {
- this.parent = parent;
- }
-
- public void add(Object val) {
- if (ht == null) ht = new PhpArray();
- if (key != null) {
- ht.put(key, val);
- } else {
- ht.put(new Integer(count++), val);
- }
-
- }
-
- protected Arg pop() {
- if (ht == null) ht = new PhpArray();
- parent.add(ht);
- return parent;
- }
-
- /* (non-Javadoc)
- * @see php.java.bridge.Request.Arg#getArgs()
- */
- public Object[] getArgs() {
- bridge.logError("Protocol error: getArgs");
- return ZERO_ARGS;
- }
-
- /* (non-Javadoc)
- * @see php.java.bridge.Request.Arg#reset()
- */
- public void reset() {
- bridge.logError("Protocol error: reset");
- }
- }
-
- private Arg arg;
-
- /**
- * The current response handle or null.
- * There is only one response handle for each request object.
- * response.reset() or response.flush() must be called at the end of each packet.
- */
- Response response = null;
-
/**
* Creates an empty request object.
*
@@ -186,9 +79,6 @@ public Request(JavaBridge bridge) {
this.parser = new Parser(bridge, this);
}
- static final byte[] ZERO = {0};
- static final Object ZERO_OBJECT = new Object();
-
/**
* This method must be called with the current header option byte.
* It initializes the request object.
@@ -210,7 +100,6 @@ public void init(byte ch) {
*/
public boolean init(InputStream in, OutputStream out) throws IOException {
switch (parser.initOptions(in, out)) {
-
case Parser.PING:
bridge.logDebug("PING - PONG - Closing Request");
out.write(ZERO, 0, 1);
@@ -230,7 +119,7 @@ private long getClassicPhpLong(ParserString st[]) {
}
private Object createClassicExact(ParserString st[]) {
- return new Integer(st[0].getClassicIntValue());
+ return st[0].getClassicIntValue();
}
private long getPhpLong(ParserString st[]) {
@@ -245,13 +134,14 @@ private Object createExact(ParserString st[]) {
int val = st[0].getIntValue();
if (st[1].string[st[1].off] != 'O')
val *= -1;
- return (new Integer(val));
+ return (val);
}
}
/**
* {@inheritDoc}
*/
+ @Override
public boolean begin(ParserTag[] tag) {
boolean reply = true;
ParserString[] st = tag[2].strings;
@@ -395,6 +285,7 @@ public boolean begin(ParserTag[] tag) {
/**
* {@inheritDoc}
*/
+ @Override
public void end(ParserString[] string) {
switch (string[0].string[0]) {
case 'X': {
@@ -569,8 +460,7 @@ private int handleRequest() throws IOException {
public void handleRequests() throws IOException {
if (response == null) response = bridge.createResponse();
this.arg = new SimpleArg();
- while (Parser.OK == handleRequest())
- ;
+ while (Parser.OK == handleRequest()) {}
}
/**
@@ -764,7 +654,7 @@ public void reset() {
* associated session-/contextFactory will be automatically destroyed when the request is done.
*
* @param bridge The fresh bridge and its ContextFactory
- * @see php.java.bridge.http.IContextFactory#recycle(String)
+ * @see io.soluble.pjb.bridge.http.IContextFactory#recycle(String)
*/
public void setBridge(JavaBridge bridge) {
defaultBridge = this.bridge;
@@ -802,4 +692,112 @@ public void recycle() {
public void parseHeader(InputStream in) throws IOException {
bridge.getFactory().parseHeader(this, in);
}
+
+ // Only used when the async. protocol is enabled.
+ protected static final class PhpNull {
+ @Override
+ public String toString() {
+ return ""; //evaluates to false
+ }
+ }
+
+ private class SimpleContext {
+ public void parseID(ParserString string) {
+ }
+
+ public void setID(Response response) {
+ }
+ }
+
+ private class Context extends SimpleContext {
+ protected long id;
+
+ @Override
+ public void parseID(ParserString string) {
+ this.id = string.getLongValue();
+ }
+
+ @Override
+ public void setID(Response response) {
+ response.setID(id);
+ }
+ }
+
+ private abstract class Arg {
+ protected byte type;
+ protected Object callObject;
+ protected String method;
+ protected SimpleContext id = getContext();
+ protected byte predicate;
+ protected Object key;
+ protected byte composite;
+
+ public abstract void add(Object val);
+ public abstract Object[] getArgs();
+ public abstract void reset();
+ }
+
+ private final class SimpleArg extends Arg {
+ private LinkedList list;
+
+ public void add(Object val) {
+ if (list == null) list = new LinkedList();
+ list.add(val);
+ }
+
+ public Object[] getArgs() {
+ return (list == null) ? Request.ZERO_ARGS : list.toArray();
+ }
+
+ public void reset() {
+ list = null;
+ composite = 0;
+ type = 0;
+ callObject = null;
+ method = null;
+ key = null;
+ }
+ }
+
+ private final class CompositeArg extends Arg {
+ private PhpArray ht = null;
+ private int count = 0;
+ private Arg parent;
+
+ public CompositeArg(Arg parent) {
+ this.parent = parent;
+ }
+
+ public void add(Object val) {
+ if (ht == null) ht = new PhpArray();
+ if (key != null) {
+ ht.put(key, val);
+ } else {
+ ht.put(new Integer(count++), val);
+ }
+
+ }
+
+ protected Arg pop() {
+ if (ht == null) ht = new PhpArray();
+ parent.add(ht);
+ return parent;
+ }
+
+ /* (non-Javadoc)
+ * @see io.soluble.pjb.Request.Arg#getArgs()
+ */
+ public Object[] getArgs() {
+ bridge.logError("Protocol error: getArgs");
+ return ZERO_ARGS;
+ }
+
+ /* (non-Javadoc)
+ * @see io.soluble.pjb.Request.Arg#reset()
+ */
+ public void reset() {
+ bridge.logError("Protocol error: reset");
+ }
+ }
+
}
diff --git a/server/php/java/bridge/Response.java b/src/main/java/io/soluble/pjb/bridge/Response.java
similarity index 98%
rename from server/php/java/bridge/Response.java
rename to src/main/java/io/soluble/pjb/bridge/Response.java
index 00c1c77..469697a 100644
--- a/server/php/java/bridge/Response.java
+++ b/src/main/java/io/soluble/pjb/bridge/Response.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -356,8 +356,8 @@ private boolean setResultArray(Object value) {
}
/**
- * Writer used by the async protocol. It always returns
java
* -Djava.awt.headless=true -jar JavaBridge.jar INET_LOCAL:9676 5
- * bridge.log &
*
* @author jostb
- * @see php.java.script.IPhpScriptContext
+ * @see io.soluble.pjb.script.IPhpScriptContext
* @see javax.script.ScriptContext
- * @see php.java.script.PhpScriptContext
+ * @see io.soluble.pjb.script.PhpScriptContext
*/
public class Context implements IManaged, Invocable, IContext {
@@ -251,7 +251,7 @@ protected Map getEngineScope() {
* Used when scripts are running outside of a servlet environment:
* Either the Standalone or the JSR223 Standalone (see PhpScriptContext).
telnet localhost 9676
<CreateInstance
+ * bridge.log
telnet localhost 9676
<CreateInstance
* value="java.lang.Long" predicate="Instance" id="0">
<Long
* value="6"/>
</CreateInstance>
<Invoke
* value="1" method="toString" predicate="Invoke" id="0"/>
@@ -93,8 +92,8 @@ protected void javaUsage() {
System.err.println("The certificate for example 3 can be created with e.g.: jdk1.6.0/bin/keytool -keystore mySrvKeystore -genkey -keyalg RSA");
System.err.println("");
System.err.println("Influential system properties: threads, daemon, php_exec, default_log_file, default_log_level, base.");
- System.err.println("Example: java -Djava.awt.headless=\"true\" -Dphp.java.bridge.threads=50 -Dphp.java.bridge.base=/usr/lib/php/modules -Dphp.java.bridge.php_exec=/usr/local/bin/php-cgi -Dphp.java.bridge.default_log_file= -Dphp.java.bridge.default_log_level=5 -jar JavaBridge.jar");
- System.err.println("Example: java -Dphp.java.bridge.daemon=\"true\" -jar JavaBridge.jar");
+ System.err.println("Example: java -Djava.awt.headless=\"true\" -Dio.soluble.pjb.bridge.threads=50 -Dio.soluble.pjb.bridge.base=/usr/lib/php/modules -Dio.soluble.pjb.bridge.php_exec=/usr/local/bin/php-cgi -Dio.soluble.pjb.bridge.default_log_file= -Dio.soluble.pjb.bridge.default_log_level=5 -jar JavaBridge.jar");
+ System.err.println("Example: java -Dio.soluble.pjb.bridge.daemon=\"true\" -jar JavaBridge.jar");
}
protected void usage() {
@@ -183,7 +182,7 @@ protected void init(String s[]) {
ISocketFactory socket = bind(logLevel, sockname);
- if ("true".equals(System.getProperty("php.java.bridge.test.startup"))) System.exit(0);
+ if ("true".equals(System.getProperty("io.soluble.pjb.bridge.test.startup"))) System.exit(0);
JavaBridge.initLog(String.valueOf(socket), logLevel, s);
JavaBridge.init(socket, logLevel, s);
} catch (Exception e) {
@@ -209,10 +208,10 @@ private static boolean checkServlet(int logLevel, String sockname, String[] s) t
if (sockname == null) return false;
if (sockname.startsWith("SERVLET_LOCAL:") || sockname.startsWith("HTTP_LOCAL:") || sockname.startsWith("HTTPS_LOCAL:")) {
Util.JAVABRIDGE_PROMISCUOUS = false;
- System.setProperty("php.java.bridge.promiscuous", "false");
+ System.setProperty("io.soluble.pjb.bridge.promiscuous", "false");
} else if (sockname.startsWith("SERVLET:") || sockname.startsWith("HTTP:") || sockname.startsWith("HTTPS:")) {
Util.JAVABRIDGE_PROMISCUOUS = true;
- System.setProperty("php.java.bridge.promiscuous", "true");
+ System.setProperty("io.soluble.pjb.bridge.promiscuous", "true");
} else
return false;
@@ -225,7 +224,7 @@ private static boolean checkServlet(int logLevel, String sockname, String[] s) t
Class runner = JavaBridgeRunner.class;
JavaBridgeRunner r;
try {
- runner = Util.classForName("php.java.script.JavaBridgeScriptRunner");
+ runner = Util.classForName("io.soluble.pjb.script.JavaBridgeScriptRunner");
Method m = runner.getMethod("getRequiredInstance", new Class[]{String.class, Boolean.TYPE});
r = (JavaBridgeRunner) m.invoke(runner, new Object[]{serverPort, new Boolean(isSecure)});
} catch (Throwable e) {
@@ -256,22 +255,20 @@ private static final boolean checkGNUVM() {
* @param s an array of [socketname, level, logFile]
*/
public static void main(String s[]) {
- // check for -Dphp.java.bridge.daemon=true
- if (!(System.getProperty("php.java.bridge.daemon", "false").equals("false"))) {
+ // check for -Dio.soluble.pjb.bridge.daemon=true
+ if (!(System.getProperty("io.soluble.pjb.bridge.daemon", "false").equals("false"))) {
final String[] args = new String[s.length + 8];
- args[0] = System.getProperty("php.java.bridge.daemon");
+ args[0] = System.getProperty("io.soluble.pjb.bridge.daemon");
if ("true".equals(args[0])) args[0] = "java";
args[1] = "-Djava.library.path=" + System.getProperty("java.library.path", ".");
args[2] = "-Djava.ext.dirs=" + System.getProperty("java.ext.dirs", ".");
args[3] = "-Djava.awt.headless=" + System.getProperty("java.awt.headless", "true");
- args[4] = "-Dphp.java.bridge.asDaemon=true";
+ args[4] = "-Dio.soluble.pjb.bridge.asDaemon=true";
args[5] = "-classpath";
args[6] = System.getProperty("java.class.path", ".");
- args[7] = "php.java.bridge.Standalone";
-
- for (int j = 0; j < s.length; j++) {
- args[j + 8] = s[j];
- }
+ args[7] = "io.soluble.pjb.bridge.Standalone";
+ System.arraycopy(s, 0, args, 8, s.length);
+
try {
System.in.close();
System.out.close();
@@ -281,6 +278,7 @@ public static void main(String s[]) {
}
new Util.Thread(new Runnable() {
+ @Override
public void run() {
try {
Runtime.getRuntime().exec(args);
@@ -289,9 +287,10 @@ public void run() {
}
}
}).start();
+
try {
Thread.sleep(20000);
- } catch (Throwable t) {
+ } catch (InterruptedException t) {
}
System.exit(0);
}
@@ -312,9 +311,13 @@ public void run() {
String javaExec = sunJavaInstalled ? "/usr/java/default/bin/java" : "java";
if (s.length == 0 &&
- (System.getProperty("php.java.bridge.exec_sun_vm", "true").equals("true")) &&
+ (System.getProperty("io.soluble.pjb.bridge.exec_sun_vm", "true").equals("true")) &&
((sunJavaInstalled && checkGNUVM()) || isExecutableJavaBridgeJar)) {
- Process p = Runtime.getRuntime().exec(new String[]{javaExec, "-Dphp.java.bridge.exec_sun_vm=false", "-classpath", cp, "php.java.bridge.Standalone"}, null, wd);
+ Process p = Runtime.getRuntime().exec(new String[]{
+ javaExec,
+ "-Dio.soluble.pjb.bridge.exec_sun_vm=false",
+ "-classpath", cp,
+ "io.soluble.pjb.bridge.Standalone"}, null, wd);
if (p != null) System.exit(p.waitFor());
}
} catch (Throwable t) {/*ignore*/}
diff --git a/server/php/java/bridge/StringCache.java b/src/main/java/io/soluble/pjb/bridge/StringCache.java
similarity index 99%
rename from server/php/java/bridge/StringCache.java
rename to src/main/java/io/soluble/pjb/bridge/StringCache.java
index 564d9c3..c1669e0 100644
--- a/server/php/java/bridge/StringCache.java
+++ b/src/main/java/io/soluble/pjb/bridge/StringCache.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/TCPServerSocket.java b/src/main/java/io/soluble/pjb/bridge/TCPServerSocket.java
similarity index 97%
rename from server/php/java/bridge/TCPServerSocket.java
rename to src/main/java/io/soluble/pjb/bridge/TCPServerSocket.java
index 85b24d1..de7f986 100644
--- a/server/php/java/bridge/TCPServerSocket.java
+++ b/src/main/java/io/soluble/pjb/bridge/TCPServerSocket.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
@@ -69,7 +67,6 @@ private void findFreePort(int start, int backlog) {
this.port = port;
return;
} catch (IOException e) {
- continue;
}
}
@@ -85,20 +82,24 @@ private TCPServerSocket(int port, int backlog, boolean local) throws IOException
}
}
+ @Override
public void close() throws IOException {
sock.close();
}
+ @Override
public Socket accept() throws IOException {
Socket s = sock.accept();
s.setTcpNoDelay(true);
return s;
}
+ @Override
public String getSocketName() {
return String.valueOf(port);
}
+ @Override
public String toString() {
return (local ? "INET_LOCAL:" : "INET:") + getSocketName();
}
diff --git a/server/php/java/bridge/ThreadPool.java b/src/main/java/io/soluble/pjb/bridge/ThreadPool.java
similarity index 99%
rename from server/php/java/bridge/ThreadPool.java
rename to src/main/java/io/soluble/pjb/bridge/ThreadPool.java
index ac30097..7a06d8e 100644
--- a/server/php/java/bridge/ThreadPool.java
+++ b/src/main/java/io/soluble/pjb/bridge/ThreadPool.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge;
+package io.soluble.pjb.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -150,7 +150,7 @@ public void destroy() {
* Creates a new thread pool.
*
* @param name - The name of the pool threads.
- * @param poolMaxSize - The max. number of threads, must be >= 1.
+ * @param poolMaxSize - The max. number of threads, must be >= 1.
*/
public ThreadPool(String name, int poolMaxSize) {
if (poolMaxSize < 1) throw new IllegalArgumentException("poolMaxSize must be >0");
diff --git a/server/php/java/bridge/Util.java b/src/main/java/io/soluble/pjb/bridge/Util.java
similarity index 91%
rename from server/php/java/bridge/Util.java
rename to src/main/java/io/soluble/pjb/bridge/Util.java
index c4951fc..7d8d9a1 100644
--- a/server/php/java/bridge/Util.java
+++ b/src/main/java/io/soluble/pjb/bridge/Util.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.bridge;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.bridge;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -46,10 +44,10 @@
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.TimeZone;
-import java.util.Vector;
import java.util.Map.Entry;
-import php.java.bridge.http.FCGIConnectionPool;
+import io.soluble.pjb.bridge.http.FCGIConnectionPool;
+import java.util.ArrayList;
/**
@@ -63,17 +61,7 @@ public final class Util {
initGlobals();
}
- /**
- * Script engines are started from this pool.
- * Use pool.destroy() to destroy the thread pool upon JVM or servlet shutdown
- */
- public static final ThreadPool PHP_SCRIPT_ENGINE_THREAD_POOL = new ThreadPool("JavaBridgeStandaloneScriptEngineProxy", Integer.parseInt(Util.THREAD_POOL_MAX_SIZE)) {
- protected Delegate createDelegate(String name) {
- Delegate d = super.createDelegate(name);
- d.setDaemon(true);
- return d;
- }
- };
+ private Util() {}
/**
* Only for internal use. The library standalone ScriptEngine FastCGI connection pool, if any
@@ -83,7 +71,7 @@ protected Delegate createDelegate(String name) {
/**
* Used by the watchdog. After MAX_WAIT (default 1500ms) the ContextRunner times out. Raise this value if you want to debug the bridge.
- * See also system property php.java.bridge.max_wait
+ * See also system property io.soluble.pjb.bridge.max_wait
*/
public static int MAX_WAIT;
@@ -140,97 +128,8 @@ protected Delegate createDelegate(String name) {
public static final String X_JAVABRIDGE_INCLUDE_ONLY = "X_JAVABRIDGE_INCLUDE_ONLY";
- private Util() {
- }
-
- /**
- * Only for internal use. Use Util.getLogger() instread.
- * php.java.bridge.threads
+ * @see System property io.soluble.pjb.bridge.threads
*/
public static String THREAD_POOL_MAX_SIZE;
@@ -307,7 +207,7 @@ public void warn(String msg) {
* overrides. Default is 3, if started via java -jar
* JavaBridge.jar or 2, if started as a sub-process of Apache/IIS.
*
- * @see System property php.java.bridge.default_log_level
+ * @see System property io.soluble.pjb.bridge.default_log_level
*/
public static int DEFAULT_LOG_LEVEL;
@@ -338,7 +238,7 @@ public void warn(String msg) {
*/
public static String VM_NAME;
/**
- * Set to true, if the Java VM has been started with -Dphp.java.bridge.promiscuous=true;
+ * Set to true, if the Java VM has been started with -Dio.soluble.pjb.bridge.promiscuous=true;
*/
public static boolean JAVABRIDGE_PROMISCUOUS;
@@ -347,7 +247,7 @@ public void warn(String msg) {
* sub-process of Apache/IIS or EXTENSION_NAME.log,
* if started via java -jar JavaBridge.jar.
*
- * @see System property php.java.bridge.default_log_file
+ * @see System property io.soluble.pjb.bridge.default_log_file
*/
public static String DEFAULT_LOG_FILE;
@@ -358,14 +258,6 @@ public void warn(String msg) {
*/
public static String JAVABRIDGE_BASE;
- private static String getProperty(Properties p, String key, String defaultValue) {
- String s = null;
- if (p != null) s = p.getProperty(key);
- if (s == null) s = System.getProperty("php.java.bridge." + String.valueOf(key).toLowerCase());
- if (s == null) s = defaultValue;
- return s;
- }
-
/**
* Only for internal use
*/
@@ -389,37 +281,59 @@ private static String getProperty(Properties p, String key, String defaultValue)
private static String sessionSavePath;
+ /**
+ * Script engines are started from this pool.
+ * Use pool.destroy() to destroy the thread pool upon JVM or servlet shutdown
+ */
+ public static final ThreadPool PHP_SCRIPT_ENGINE_THREAD_POOL =
+ new ThreadPool("JavaBridgeStandaloneScriptEngineProxy", Integer.parseInt(Util.THREAD_POOL_MAX_SIZE)) {
+ @Override
+ protected ThreadPool.Delegate createDelegate(String name) {
+ ThreadPool.Delegate d = super.createDelegate(name);
+ d.setDaemon(true);
+ return d;
+ }
+ };
+
+ private static String getProperty(Properties p, String key, String defaultValue) {
+ String s = null;
+ if (p != null) s = p.getProperty(key);
+ if (s == null) s = System.getProperty("io.soluble.pjb.bridge." + String.valueOf(key).toLowerCase());
+ if (s == null) s = defaultValue;
+ return s;
+ }
+
private static void initGlobals() {
try {
- JAVA_INC = Class.forName("php.java.bridge.JavaInc");
- } catch (Exception e) {/*ignore*/}
+ JAVA_INC = Class.forName("io.soluble.pjb.bridge.JavaInc");
+ } catch (ClassNotFoundException e) {/*ignore*/}
try {
- PHPDEBUGGER_PHP = Class.forName("php.java.bridge.PhpDebuggerPHP");
- } catch (Exception e) {/*ignore*/}
+ PHPDEBUGGER_PHP = Class.forName("io.soluble.pjb.bridge.PhpDebuggerPHP");
+ } catch (ClassNotFoundException e) {/*ignore*/}
try {
- JAVA_PROXY = Class.forName("php.java.bridge.JavaProxy");
- } catch (Exception e) {/*ignore*/}
+ JAVA_PROXY = Class.forName("io.soluble.pjb.bridge.JavaProxy");
+ } catch (ClassNotFoundException e) {/*ignore*/}
try {
- LAUNCHER_UNIX = Class.forName("php.java.bridge.LauncherUnix");
- } catch (Exception e) {/*ignore*/}
+ LAUNCHER_UNIX = Class.forName("io.soluble.pjb.bridge.LauncherUnix");
+ } catch (ClassNotFoundException e) {/*ignore*/}
try {
- LAUNCHER_WINDOWS = Class.forName("php.java.bridge.LauncherWindows");
- LAUNCHER_WINDOWS2 = Class.forName("php.java.bridge.LauncherWindows2");
- LAUNCHER_WINDOWS3 = Class.forName("php.java.bridge.LauncherWindows3");
- LAUNCHER_WINDOWS4 = Class.forName("php.java.bridge.LauncherWindows4");
- } catch (Exception e) {/*ignore*/}
+ LAUNCHER_WINDOWS = Class.forName("io.soluble.pjb.bridge.LauncherWindows");
+ LAUNCHER_WINDOWS2 = Class.forName("io.soluble.pjb.bridge.LauncherWindows2");
+ LAUNCHER_WINDOWS3 = Class.forName("io.soluble.pjb.bridge.LauncherWindows3");
+ LAUNCHER_WINDOWS4 = Class.forName("io.soluble.pjb.bridge.LauncherWindows4");
+ } catch (ClassNotFoundException e) {/*ignore*/}
Properties p = new Properties();
try {
InputStream in = Util.class.getResourceAsStream("global.properties");
p.load(in);
VERSION = p.getProperty("BACKEND_VERSION");
- } catch (Throwable t) {
+ } catch (IOException t) {
VERSION = "unknown";
//t.printStackTrace();
}
- ;
+
ENVIRONMENT_BLACKLIST = getEnvironmentBlacklist(p);
COMMON_ENVIRONMENT = getCommonEnvironment(ENVIRONMENT_BLACKLIST);
DEFAULT_CGI_LOCATIONS = new String[]{"/usr/bin/php-cgi", "c:/Program Files/PHP/php-cgi.exe"};
@@ -453,8 +367,8 @@ private static void initGlobals() {
} catch (Exception e) { /*ignore*/ }
} catch (Throwable xe) {/*ignore*/}
try {
- MAX_WAIT = Integer.parseInt(getProperty(p, "php.java.bridge.max_wait", "15000"));
- } catch (Exception e) {
+ MAX_WAIT = Integer.parseInt(getProperty(p, "io.soluble.pjb.bridge.max_wait", "15000"));
+ } catch (NumberFormatException e) {
MAX_WAIT = 15000;
}
try {
@@ -463,7 +377,7 @@ private static void initGlobals() {
HOME_DIR = null;
}
try {
- JAVABRIDGE_BASE = getProperty(p, "php.java.bridge.base", System.getProperty("user.home"));
+ JAVABRIDGE_BASE = getProperty(p, "io.soluble.pjb.bridge.base", System.getProperty("user.home"));
} catch (Exception e) {
JAVABRIDGE_BASE = ".";
}
@@ -473,7 +387,7 @@ private static void initGlobals() {
} catch (Exception e) {/*ignore*/}
try {
JAVABRIDGE_PROMISCUOUS = false;
- JAVABRIDGE_PROMISCUOUS = getProperty(p, "php.java.bridge.promiscuous", "false").toLowerCase().equals("true");
+ JAVABRIDGE_PROMISCUOUS = getProperty(p, "io.soluble.pjb.bridge.promiscuous", "false").toLowerCase().equals("true");
} catch (Exception e) {/*ignore*/}
try {
@@ -482,7 +396,6 @@ private static void initGlobals() {
} catch (Throwable t) {
//t.printStackTrace();
}
- ;
// resolve java.io.tmpdir for windows; PHP doesn't like dos short file names like foo~1\bar~2\...
TMPDIR = new File(System.getProperty("java.io.tmpdir", "/tmp"));
@@ -511,14 +424,14 @@ private static void initGlobals() {
} catch (Throwable t) {
//t.printStackTrace();
}
- ;
+
try {
EXTENSION_NAME = "JavaBridge";
EXTENSION_NAME = getProperty(p, "EXTENSION_DISPLAY_NAME", "JavaBridge");
} catch (Throwable t) {
//t.printStackTrace();
}
- ;
+
try {
PHP_EXEC = getProperty(p, "PHP_EXEC", null);
} catch (Throwable t) {
@@ -528,11 +441,11 @@ private static void initGlobals() {
String s = getProperty(p, "DEFAULT_LOG_LEVEL", "3");
DEFAULT_LOG_LEVEL = Integer.parseInt(s);
Util.logLevel = Util.DEFAULT_LOG_LEVEL; /* java.log_level in php.ini overrides */
- } catch (Throwable t) {/*ignore*/}
+ } catch (NumberFormatException t) {/*ignore*/}
try {
DEFAULT_LOG_FILE_SET = false;
DEFAULT_LOG_FILE = getProperty(p, "DEFAULT_LOG_FILE", Util.EXTENSION_NAME + ".log");
- DEFAULT_LOG_FILE_SET = System.getProperty("php.java.bridge.default_log_file") != null;
+ DEFAULT_LOG_FILE_SET = System.getProperty("io.soluble.pjb.bridge.default_log_file") != null;
} catch (Throwable t) {/*ignore*/}
String separator = "/-+.,;: ";
@@ -590,7 +503,7 @@ public static void warn(String msg) {
}
/**
- * Display a stack trace if logLevel >= 1
+ * Display a stack trace if logLevel >= 1
*
* @param t The Throwable
*/
@@ -847,20 +760,16 @@ public static byte[] toBytes(String s) {
/**
* Create a string array from a hashtable.
*
- * @param h The hashtable
+ * @param map The hashtable
* @return The String
* @throws NullPointerException
*/
- public static String[] hashToStringArray(Map h) {
- Vector v = new Vector();
- Iterator e = h.keySet().iterator();
- while (e.hasNext()) {
- String k = e.next().toString();
- v.add(k + "=" + h.get(k));
+ public static String[] hashToStringArray(Mapobject may be a dynamic proxy:
+ * String.valueOf(object) returns null, if object is a proxy and returns null.
+ *
+ * @param object The object or dynamic proxy
+ * @return The string representation of object
+ */
+ public static String stringValueOf(Object object) {
+ String s = String.valueOf(object);
+ if (s == null) s = String.valueOf(s);
+ return s;
+ }
+
+ /**
+ * Create a new AppThreadPool.
+ *
+ * @param name The pool name
+ * @return A new AppThreadPool for up to {@link #THREAD_POOL_MAX_SIZE} runnables
+ */
+ public static AppThreadPool createThreadPool(String name) {
+ AppThreadPool pool = null;
+ int maxSize = 20;
+ try {
+ maxSize = Integer.parseInt(Util.THREAD_POOL_MAX_SIZE);
+ } catch (Throwable t) {
+ Util.printStackTrace(t);
+ }
+ if (maxSize > 0) {
+ pool = new AppThreadPool(name, maxSize);
+ }
+ return pool;
+ }
+
+
+ /**
+ * parse java.log_file=@HOST:PORT
+ *
+ * @param logFile The log file from the PHP .ini file
+ * @return true, if we can use the log4j logger, false otherwise.
+ */
+ static boolean setConfiguredLogger(String logFile) {
+ try {
+ return tryConfiguredChainsawLogger(logFile);
+ } catch (Exception e) {
+ printStackTrace(e);
+ Util.setDefaultLogger(new FileLogger());
+ }
+ return true;
+ }
+
+ /**
+ * parse java.log_file=@HOST:PORT
+ *
+ * @param logFile The log file from the PHP .ini file
+ * @return true, if we can use the log4j logger, false otherwise.
+ * @throws Exception
+ */
+ private static boolean tryConfiguredChainsawLogger(String logFile) throws Exception {
+ if (logFile != null && logFile.length() > 0 && logFile.charAt(0) == '@') {
+ logFile = logFile.substring(1, logFile.length());
+ int idx = logFile.indexOf(':');
+ int port = -1;
+ String host = null;
+ if (idx != -1) {
+ String p = logFile.substring(idx + 1, logFile.length());
+ if (p.length() > 0) port = Integer.parseInt(p);
+ host = logFile.substring(0, idx);
+ } else {
+ if (logFile.length() > 0) host = logFile;
+ }
+ ILogger logger = ConfiguredChainsawLogger.createLogger(host, port);
+ Util.setDefaultLogger(logger);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the time in GMT
+ *
+ * @param ms the time in milliseconds
+ * @return The formatted date string
+ */
+ public static String formatDateTime(long ms) {
+ java.sql.Timestamp t = new java.sql.Timestamp(ms);
+ DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, Locale.ENGLISH);
+ formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
+ String str = formatter.format(t);
+ return str;
+ }
+
+ static final boolean checkVM() {
+ try {
+ return "libgcj".equals(System.getProperty("gnu.classpath.vm.shortname"));
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+
+ /**
+ * Return the thread context class loader
+ *
+ * @return The context class loader
+ */
+ public static ClassLoader getContextClassLoader() {
+ ClassLoader loader = null;
+ try {
+ loader = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) {/*ignore*/}
+ if (loader == null) loader = JavaBridge.class.getClassLoader();
+ return loader;
+ }
+
+ public static Class classForName(String name) throws ClassNotFoundException {
+ return Class.forName(name, true, getContextClassLoader());
+ }
+
+ public static String getSimpleRedirectString(String webPath, String socketName, boolean isSecure) {
+ try {
+ StringBuilder buf = new StringBuilder();
+ buf.append(socketName);
+ buf.append("/");
+ buf.append(webPath);
+ URI uri = new URI(isSecure ? "s:127.0.0.1" : "h:127.0.0.1", buf.toString(), null);
+ return (uri.toASCIIString() + ".phpjavabridge");
+ } catch (URISyntaxException e) {
+ Util.printStackTrace(e);
+ }
+ StringBuilder buf = new StringBuilder(isSecure ? "s:127.0.0.1" : "h:127.0.0.1:");
+ buf.append(socketName);
+ buf.append('/');
+ buf.append(webPath);
+ buf.append(".phpjavabridge");
+ return buf.toString();
+ }
+
+ /**
+ * Destroy the thread associated with util.
+ */
+ public static void destroy() {
+ try {
+ PHP_SCRIPT_ENGINE_THREAD_POOL.destroy();
+ } catch (Exception e) {
+ Util.printStackTrace(e);
+ }
+ try {
+ if (fcgiConnectionPool != null) fcgiConnectionPool.destroy();
+ } catch (Exception e) {
+ Util.printStackTrace(e);
+ }
+ try {
+ JavaBridgeRunner.destroyRunner();
+ } catch (Exception e) {
+ Util.printStackTrace(e);
+ }
+ }
+
+ /**
+ * Convenience daemon thread class
+ */
+ public static class Thread extends java.lang.Thread {
+ /**
+ * Create a new thread
+ */
+ public Thread() {
+ super();
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param name
+ */
+ public Thread(String name) {
+ super(name);
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param target
+ */
+ public Thread(Runnable target) {
+ super(target);
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param group
+ * @param target
+ */
+ public Thread(ThreadGroup group, Runnable target) {
+ super(group, target);
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param group
+ * @param name
+ */
+ public Thread(ThreadGroup group, String name) {
+ super(group, name);
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param target
+ * @param name
+ */
+ public Thread(Runnable target, String name) {
+ super(target, name);
+ initThread();
+ }
+
+ /**
+ * Create a new thread
+ *
+ * @param group
* @param target
* @param name
*/
@@ -1042,6 +1219,94 @@ private void initThread() {
}
}
+ /**
+ * Only for internal use. Use Util.getLogger() instread.
+ * object may be a dynamic proxy:
- * String.valueOf(object) returns null, if object is a proxy and returns null.
- *
- * @param object The object or dynamic proxy
- * @return The string representation of object
- */
- public static String stringValueOf(Object object) {
- String s = String.valueOf(object);
- if (s == null) s = String.valueOf(s);
- return s;
- }
-
- /**
- * Create a new AppThreadPool.
- *
- * @param name The pool name
- * @return A new AppThreadPool for up to {@link #THREAD_POOL_MAX_SIZE} runnables
- */
- public static AppThreadPool createThreadPool(String name) {
- AppThreadPool pool = null;
- int maxSize = 20;
- try {
- maxSize = Integer.parseInt(Util.THREAD_POOL_MAX_SIZE);
- } catch (Throwable t) {
- Util.printStackTrace(t);
- }
- if (maxSize > 0) {
- pool = new AppThreadPool(name, maxSize);
- }
- return pool;
- }
-
-
- /**
- * parse java.log_file=@HOST:PORT
- *
- * @param logFile The log file from the PHP .ini file
- * @return true, if we can use the log4j logger, false otherwise.
- */
- static boolean setConfiguredLogger(String logFile) {
- try {
- return tryConfiguredChainsawLogger(logFile);
- } catch (Exception e) {
- printStackTrace(e);
- Util.setDefaultLogger(new FileLogger());
- }
- return true;
- }
-
private static final class ConfiguredChainsawLogger extends ChainsawLogger {
- private String host;
- private int port;
+ private final String host;
+ private final int port;
private ConfiguredChainsawLogger(String host, int port) {
super();
@@ -1676,6 +1795,7 @@ public static ConfiguredChainsawLogger createLogger(String host, int port) throw
return logger;
}
+ @Override
public void configure(String host, int port) throws Exception {
host = this.host != null ? this.host : host;
port = this.port > 0 ? this.port : port;
@@ -1683,110 +1803,4 @@ public void configure(String host, int port) throws Exception {
}
}
- /**
- * parse java.log_file=@HOST:PORT
- *
- * @param logFile The log file from the PHP .ini file
- * @return true, if we can use the log4j logger, false otherwise.
- * @throws Exception
- */
- private static boolean tryConfiguredChainsawLogger(String logFile) throws Exception {
- if (logFile != null && logFile.length() > 0 && logFile.charAt(0) == '@') {
- logFile = logFile.substring(1, logFile.length());
- int idx = logFile.indexOf(':');
- int port = -1;
- String host = null;
- if (idx != -1) {
- String p = logFile.substring(idx + 1, logFile.length());
- if (p.length() > 0) port = Integer.parseInt(p);
- host = logFile.substring(0, idx);
- } else {
- if (logFile.length() > 0) host = logFile;
- }
- ILogger logger = ConfiguredChainsawLogger.createLogger(host, port);
- Util.setDefaultLogger(logger);
- return true;
- }
- return false;
- }
-
- /**
- * Return the time in GMT
- *
- * @param ms the time in milliseconds
- * @return The formatted date string
- */
- public static String formatDateTime(long ms) {
- java.sql.Timestamp t = new java.sql.Timestamp(ms);
- DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, Locale.ENGLISH);
- formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
- String str = formatter.format(t);
- return str;
- }
-
- static final boolean checkVM() {
- try {
- return "libgcj".equals(System.getProperty("gnu.classpath.vm.shortname"));
- } catch (Throwable t) {
- return false;
- }
- }
-
- /**
- * Return the thread context class loader
- *
- * @return The context class loader
- */
- public static final ClassLoader getContextClassLoader() {
- ClassLoader loader = null;
- try {
- loader = Thread.currentThread().getContextClassLoader();
- } catch (SecurityException ex) {/*ignore*/}
- if (loader == null) loader = JavaBridge.class.getClassLoader();
- return loader;
- }
-
- public static final Class classForName(String name) throws ClassNotFoundException {
- return Class.forName(name, true, getContextClassLoader());
- }
-
- public static String getSimpleRedirectString(String webPath, String socketName, boolean isSecure) {
- try {
- StringBuffer buf = new StringBuffer();
- buf.append(socketName);
- buf.append("/");
- buf.append(webPath);
- URI uri = new URI(isSecure ? "s:127.0.0.1" : "h:127.0.0.1", buf.toString(), null);
- return (uri.toASCIIString() + ".phpjavabridge");
- } catch (URISyntaxException e) {
- Util.printStackTrace(e);
- }
- StringBuffer buf = new StringBuffer(isSecure ? "s:127.0.0.1" : "h:127.0.0.1:");
- buf.append(socketName);
- buf.append('/');
- buf.append(webPath);
- buf.append(".phpjavabridge");
- return buf.toString();
- }
-
- /**
- * Destroy the thread associated with util.
- */
- public static void destroy() {
- try {
- PHP_SCRIPT_ENGINE_THREAD_POOL.destroy();
- } catch (Exception e) {
- Util.printStackTrace(e);
- }
- try {
- if (fcgiConnectionPool != null) fcgiConnectionPool.destroy();
- } catch (Exception e) {
- Util.printStackTrace(e);
- }
- try {
- JavaBridgeRunner.destroyRunner();
- } catch (Exception e) {
- Util.printStackTrace(e);
- }
- }
}
diff --git a/server/php/java/bridge/http/AbstractChannel.java b/src/main/java/io/soluble/pjb/bridge/http/AbstractChannel.java
similarity index 92%
rename from server/php/java/bridge/http/AbstractChannel.java
rename to src/main/java/io/soluble/pjb/bridge/http/AbstractChannel.java
index 489ee3a..e1af38b 100644
--- a/server/php/java/bridge/http/AbstractChannel.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/AbstractChannel.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -38,7 +38,7 @@ public abstract class AbstractChannel {
* Returns the channel's input stream.
*
* @return The InputStream
- * @throws FileNotFoundException
+ * @throws IOException
*/
public abstract InputStream getInputStream() throws IOException;
@@ -46,7 +46,7 @@ public abstract class AbstractChannel {
* Returns the channel's output stream.
*
* @return The OutputStream.
- * @throws FileNotFoundException
+ * @throws IOException
*/
public abstract OutputStream getOuptutStream() throws IOException;
@@ -59,7 +59,7 @@ public abstract class AbstractChannel {
* Returns the name of the channel, for example the socket # or the pipe name.
*
* @return the name of the channel.
- * @see php.java.bridge.http.AbstractChannelName#getName()
+ * @see io.soluble.pjb.bridge.http.AbstractChannelName#getName()
*/
public abstract String getName();
}
diff --git a/server/php/java/bridge/http/AbstractChannelName.java b/src/main/java/io/soluble/pjb/bridge/http/AbstractChannelName.java
similarity index 97%
rename from server/php/java/bridge/http/AbstractChannelName.java
rename to src/main/java/io/soluble/pjb/bridge/http/AbstractChannelName.java
index bef8f7b..c6d1e0c 100644
--- a/server/php/java/bridge/http/AbstractChannelName.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/AbstractChannelName.java
@@ -1,8 +1,8 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
-import php.java.bridge.ILogger;
+import io.soluble.pjb.bridge.ILogger;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/http/ChunkedInputStream.java b/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java
similarity index 98%
rename from server/php/java/bridge/http/ChunkedInputStream.java
rename to src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java
index b73fcf6..14d115f 100644
--- a/server/php/java/bridge/http/ChunkedInputStream.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,7 +29,7 @@
import java.io.IOException;
import java.io.InputStream;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/**
* An output stream which reads data in HTTP chunks.
diff --git a/server/php/java/bridge/http/ChunkedOutputStream.java b/src/main/java/io/soluble/pjb/bridge/http/ChunkedOutputStream.java
similarity index 97%
rename from server/php/java/bridge/http/ChunkedOutputStream.java
rename to src/main/java/io/soluble/pjb/bridge/http/ChunkedOutputStream.java
index b823e48..d3237f9 100644
--- a/server/php/java/bridge/http/ChunkedOutputStream.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/ChunkedOutputStream.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,7 +29,7 @@
import java.io.IOException;
import java.io.OutputStream;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/**
* An output stream which writes data in HTTP chunks.
diff --git a/server/php/java/bridge/http/Context.java b/src/main/java/io/soluble/pjb/bridge/http/Context.java
similarity index 95%
rename from server/php/java/bridge/http/Context.java
rename to src/main/java/io/soluble/pjb/bridge/http/Context.java
index dd34d95..f861009 100644
--- a/server/php/java/bridge/http/Context.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/Context.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -35,10 +35,10 @@
import java.util.LinkedList;
import java.util.Map;
-import php.java.bridge.IManaged;
-import php.java.bridge.Invocable;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.IManaged;
+import io.soluble.pjb.bridge.Invocable;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
/**
@@ -50,9 +50,9 @@
*
* Within a servlet environment use the ContextLoaderListener instead:
- * Either php.java.servlet.Context or the JSR223 Context (see PhpSimpleHttpScriptContext).
+ * Either io.soluble.pjb.servlet.Context or the JSR223 Context (see PhpSimpleHttpScriptContext).
*
* @param closeable The procedure close(), will be called before the VM terminates
*/
@@ -310,7 +310,7 @@ public Object init(Object callable) throws Exception {
* {@inheritDoc}
*/
public void onShutdown(Object closeable) {
- php.java.bridge.http.Context.handleManaged(closeable);
+ io.soluble.pjb.bridge.http.Context.handleManaged(closeable);
}
/**
diff --git a/server/php/java/bridge/http/ContextFactory.java b/src/main/java/io/soluble/pjb/bridge/http/ContextFactory.java
similarity index 95%
rename from server/php/java/bridge/http/ContextFactory.java
rename to src/main/java/io/soluble/pjb/bridge/http/ContextFactory.java
index 5596b0d..41baa50 100644
--- a/server/php/java/bridge/http/ContextFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/ContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -31,11 +31,11 @@
import java.util.HashMap;
import java.util.Iterator;
-import php.java.bridge.ISession;
-import php.java.bridge.JavaBridge;
-import php.java.bridge.Request;
-import php.java.bridge.SessionFactory;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.JavaBridge;
+import io.soluble.pjb.bridge.Request;
+import io.soluble.pjb.bridge.SessionFactory;
+import io.soluble.pjb.bridge.Util;
/**
@@ -79,9 +79,9 @@
* belongs to the same ContextServer.
*
diff --git a/server/php/java/bridge/http/FCGIIOFactory.java b/src/main/java/io/soluble/pjb/bridge/http/FCGIIOFactory.java
similarity index 98%
rename from server/php/java/bridge/http/FCGIIOFactory.java
rename to src/main/java/io/soluble/pjb/bridge/http/FCGIIOFactory.java
index f819126..bae4d11 100644
--- a/server/php/java/bridge/http/FCGIIOFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/FCGIIOFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/http/FCGIInputStream.java b/src/main/java/io/soluble/pjb/bridge/http/FCGIInputStream.java
similarity index 98%
rename from server/php/java/bridge/http/FCGIInputStream.java
rename to src/main/java/io/soluble/pjb/bridge/http/FCGIInputStream.java
index 4e80430..dcdc0a7 100644
--- a/server/php/java/bridge/http/FCGIInputStream.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/FCGIInputStream.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -26,7 +26,7 @@
import java.io.IOException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/**
* A FastCGI input stream
diff --git a/server/php/java/bridge/http/FCGIOutputStream.java b/src/main/java/io/soluble/pjb/bridge/http/FCGIOutputStream.java
similarity index 97%
rename from server/php/java/bridge/http/FCGIOutputStream.java
rename to src/main/java/io/soluble/pjb/bridge/http/FCGIOutputStream.java
index 8cf0ca9..ecfc53a 100644
--- a/server/php/java/bridge/http/FCGIOutputStream.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/FCGIOutputStream.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,8 +29,8 @@
import java.util.Iterator;
import java.util.Map;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
/**
* A FastCGI OutputStream
diff --git a/server/php/java/bridge/http/FCGIUtil.java b/src/main/java/io/soluble/pjb/bridge/http/FCGIUtil.java
similarity index 97%
rename from server/php/java/bridge/http/FCGIUtil.java
rename to src/main/java/io/soluble/pjb/bridge/http/FCGIUtil.java
index 4a308e2..8526242 100644
--- a/server/php/java/bridge/http/FCGIUtil.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/FCGIUtil.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -117,7 +117,7 @@ public class FCGIUtil {
* This controls how many child processes the PHP process spawns.
* Default is 5. The value should be less than THREAD_POOL_MAX_SIZE
*
- * @see php.java.bridge.Util#THREAD_POOL_MAX_SIZE
+ * @see io.soluble.pjb.bridge.Util#THREAD_POOL_MAX_SIZE
*/
public static final String PHP_FCGI_CONNECTION_POOL_SIZE = "5"; // should be less than Util.THREAD_POOL_MAX_SIZE;
diff --git a/server/php/java/bridge/http/HeaderParser.java b/src/main/java/io/soluble/pjb/bridge/http/HeaderParser.java
similarity index 98%
rename from server/php/java/bridge/http/HeaderParser.java
rename to src/main/java/io/soluble/pjb/bridge/http/HeaderParser.java
index 9b226e9..a34ce79 100644
--- a/server/php/java/bridge/http/HeaderParser.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/HeaderParser.java
@@ -1,12 +1,12 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/bridge/http/HttpRequest.java b/src/main/java/io/soluble/pjb/bridge/http/HttpRequest.java
similarity index 98%
rename from server/php/java/bridge/http/HttpRequest.java
rename to src/main/java/io/soluble/pjb/bridge/http/HttpRequest.java
index c3cc2ac..d20937f 100644
--- a/server/php/java/bridge/http/HttpRequest.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/HttpRequest.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,7 +29,7 @@
import java.io.InputStream;
import java.util.HashMap;
-import php.java.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.NotImplementedException;
/**
* A simple HTTP request implementation.
diff --git a/server/php/java/bridge/http/HttpResponse.java b/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java
similarity index 97%
rename from server/php/java/bridge/http/HttpResponse.java
rename to src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java
index f3993b6..67afdb5 100644
--- a/server/php/java/bridge/http/HttpResponse.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -31,8 +31,8 @@
import java.util.HashMap;
import java.util.Iterator;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
/**
* A simple HTTP response implementation.
diff --git a/server/php/java/bridge/http/HttpServer.java b/src/main/java/io/soluble/pjb/bridge/http/HttpServer.java
similarity index 93%
rename from server/php/java/bridge/http/HttpServer.java
rename to src/main/java/io/soluble/pjb/bridge/http/HttpServer.java
index a0c6826..5b37e23 100644
--- a/server/php/java/bridge/http/HttpServer.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/HttpServer.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -30,9 +30,9 @@
import java.io.UnsupportedEncodingException;
import java.net.Socket;
-import php.java.bridge.ISocketFactory;
-import php.java.bridge.AppThreadPool;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.ISocketFactory;
+import io.soluble.pjb.bridge.AppThreadPool;
+import io.soluble.pjb.bridge.Util;
/**
@@ -42,11 +42,11 @@
* scripts use a HttpProxy and URLReader instead.
*
* @author jostb
- * @see php.java.bridge.http.HttpRequest
- * @see php.java.bridge.http.HttpResponse
- * @see php.java.script.Continuation
- * @see php.java.script.URLReader
- * @see php.java.script.Continuation
+ * @see io.soluble.pjb.bridge.http.HttpRequest
+ * @see io.soluble.pjb.bridge.http.HttpResponse
+ * @see io.soluble.pjb.script.Continuation
+ * @see io.soluble.pjb.script.URLReader
+ * @see io.soluble.pjb.script.Continuation
*/
public abstract class HttpServer implements Runnable {
/**
@@ -120,7 +120,6 @@ protected HttpServer(String serverPort, boolean isSecure) throws IOException {
* Create a new HTTP Server.
*
* @param serverPort The port# as a string. Prefix may be INET: or INET_LOCAL:
- * @param isSecure
* @throws IOException
* @see HttpServer#destroy()
*/
@@ -314,20 +313,34 @@ protected void doPut(HttpRequest req, HttpResponse res) throws IOException {
/**
* Sets the content length but leaves the rest of the body untouched.
+ * @param req
+ * @param res
+ * @throws java.io.IOException
*/
protected void service(HttpRequest req, HttpResponse res) throws IOException {
String contentLength = req.getHeader("Content-Length");
if (contentLength == null) req.setContentLength(-1);
else req.setContentLength(Integer.parseInt(contentLength));
String method = req.getMethod();
- if (method == PUT) doPut(req, res);
- else if (method == GET) doGet(req, res);
- else if (method == POST) doPost(req, res);
+ if (null != method) switch (method) {
+ case PUT:
+ doPut(req, res);
+ break;
+ case GET:
+ doGet(req, res);
+ break;
+ case POST:
+ doPost(req, res);
+ break;
+ default:
+ break;
+ }
}
/**
* {@inheritDoc}
*/
+ @Override
public void run() {
try {
doRun();
diff --git a/server/php/java/bridge/http/IContext.java b/src/main/java/io/soluble/pjb/bridge/http/IContext.java
similarity index 83%
rename from server/php/java/bridge/http/IContext.java
rename to src/main/java/io/soluble/pjb/bridge/http/IContext.java
index bfa044b..a35a551 100644
--- a/server/php/java/bridge/http/IContext.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/IContext.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -51,39 +51,39 @@ public interface IContext {
/**
* This key can be used to get the current continuation.
- * Example: java_context->getAttribute("php.java.bridge.PhpProcedure");
+ * Example: java_context->getAttribute("io.soluble.pjb.bridge.PhpProcedure");
*/
- public static final String PHP_PROCEDURE = "php.java.bridge.PhpProcedure";
+ public static final String PHP_PROCEDURE = "io.soluble.pjb.bridge.PhpProcedure";
/**
* This key can be used to get the current JavaBridge instance.
- * Example: java_context->getAttribute("php.java.bridge.JavaBridge");
+ * Example: java_context->getAttribute("io.soluble.pjb.bridge.JavaBridge");
*/
- public static final String JAVA_BRIDGE = "php.java.bridge.JavaBridge";
+ public static final String JAVA_BRIDGE = "io.soluble.pjb.bridge.JavaBridge";
/**
* This key can be used to get the current ServletContext instance.
- * Example: java_context->getAttribute("php.java.servlet.ServletContext");
+ * Example: java_context->getAttribute("io.soluble.pjb.servlet.ServletContext");
*/
- public static final String SERVLET_CONTEXT = "php.java.servlet.ServletContext";
+ public static final String SERVLET_CONTEXT = "io.soluble.pjb.servlet.ServletContext";
/**
* This key can be used to get the current ServletConfig instance.
- * Example: java_context->getAttribute("php.java.servlet.ServletConfig");
+ * Example: java_context->getAttribute("io.soluble.pjb.servlet.ServletConfig");
*/
- public static final String SERVLET_CONFIG = "php.java.servlet.ServletConfig";
+ public static final String SERVLET_CONFIG = "io.soluble.pjb.servlet.ServletConfig";
/**
* This key can be used to get the current Servlet instance.
- * Example: java_context->getAttribute("php.java.servlet.Servlet");
+ * Example: java_context->getAttribute("io.soluble.pjb.servlet.Servlet");
*/
- public static final String SERVLET = "php.java.servlet.Servlet";
+ public static final String SERVLET = "io.soluble.pjb.servlet.Servlet";
/**
* This key can be used to get the current HttpServletRequest instance.
- * Example: java_context->getAttribute("php.java.servlet.HttpServletRequest");
+ * Example: java_context->getAttribute("io.soluble.pjb.servlet.HttpServletRequest");
*/
- public static final String SERVLET_REQUEST = "php.java.servlet.HttpServletRequest";
+ public static final String SERVLET_REQUEST = "io.soluble.pjb.servlet.HttpServletRequest";
/**
* This key can be used to get the current HttpServletResponse instance.
- * Example: java_context->getAttribute("php.java.servlet.HttpServletResponse");
+ * Example: java_context->getAttribute("io.soluble.pjb.servlet.HttpServletResponse");
*/
- public static final String SERVLET_RESPONSE = "php.java.servlet.HttpServletResponse";
+ public static final String SERVLET_RESPONSE = "io.soluble.pjb.servlet.HttpServletResponse";
/**
* Retrieves the value for getAttribute(String, int) for the
diff --git a/server/php/java/bridge/http/IContextFactory.java b/src/main/java/io/soluble/pjb/bridge/http/IContextFactory.java
similarity index 84%
rename from server/php/java/bridge/http/IContextFactory.java
rename to src/main/java/io/soluble/pjb/bridge/http/IContextFactory.java
index 48a28ce..a943aa8 100644
--- a/server/php/java/bridge/http/IContextFactory.java
+++ b/src/main/java/io/soluble/pjb/bridge/http/IContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.bridge.http;
+package io.soluble.pjb.bridge.http;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -24,8 +24,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-import php.java.bridge.IJavaBridgeFactory;
-import php.java.bridge.ISession;
+import io.soluble.pjb.bridge.IJavaBridgeFactory;
+import io.soluble.pjb.bridge.ISession;
/**
* Interface that the ContextFactories must implement.
@@ -40,9 +40,9 @@ public interface IContextFactory extends IJavaBridgeFactory {
*
*
@@ -128,7 +129,7 @@ protected Object invoke(String methodName, Object[] args)
}
try {
return invoke(scriptClosure, methodName, args);
- } catch (php.java.bridge.Request.AbortException e) {
+ } catch (Request.AbortException e) {
release();
throw new ScriptException(e);
} catch (NoSuchMethodError e) { // conform to jsr223
diff --git a/server/php/java/script/InvocablePhpScriptEngineFactory.java b/src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngineFactory.java
similarity index 98%
rename from server/php/java/script/InvocablePhpScriptEngineFactory.java
rename to src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngineFactory.java
index 8bbfc68..27ae1b8 100644
--- a/server/php/java/script/InvocablePhpScriptEngineFactory.java
+++ b/src/main/java/io/soluble/pjb/script/InvocablePhpScriptEngineFactory.java
@@ -1,5 +1,5 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/JavaBridgeScriptRunner.java b/src/main/java/io/soluble/pjb/script/JavaBridgeScriptRunner.java
similarity index 96%
rename from server/php/java/script/JavaBridgeScriptRunner.java
rename to src/main/java/io/soluble/pjb/script/JavaBridgeScriptRunner.java
index 4f4019f..065dea8 100644
--- a/server/php/java/script/JavaBridgeScriptRunner.java
+++ b/src/main/java/io/soluble/pjb/script/JavaBridgeScriptRunner.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -37,10 +37,10 @@
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
-import php.java.bridge.JavaBridgeRunner;
-import php.java.bridge.Util;
-import php.java.bridge.http.HttpRequest;
-import php.java.bridge.http.HttpResponse;
+import io.soluble.pjb.bridge.JavaBridgeRunner;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.HttpRequest;
+import io.soluble.pjb.bridge.http.HttpResponse;
/**
* This is the main entry point for the PHP/Java Bridge library.
@@ -54,7 +54,7 @@
* }
* ScriptEngine e = (new ScriptEngineManager()).getEngineByName("php-invocable");
*
- * e.eval(new php.java.script.URLReader(new URL("http://localhost/hello.php")));
- * System.out.println(((Invocable)e).invokeMethod(e.get("php.java.bridge.PhpProcedure"), "f", new Object[]{}));
+ * e.eval(new io.soluble.pjb.script.URLReader(new URL("http://localhost/hello.php")));
+ * System.out.println(((Invocable)e).invokeMethod(e.get("io.soluble.pjb.PhpProcedure"), "f", new Object[]{}));
* ((Closeable)e).close();
*
*
* @author jostb
- * @see php.java.script.PhpScriptContext
+ * @see io.soluble.pjb.script.PhpScriptContext
*/
public class JavaBridgeScriptRunner extends JavaBridgeRunner {
private ScriptEngineManager m = new ScriptEngineManager();
diff --git a/server/php/java/script/PhpCompiledScriptContext.java b/src/main/java/io/soluble/pjb/script/PhpCompiledScriptContext.java
similarity index 95%
rename from server/php/java/script/PhpCompiledScriptContext.java
rename to src/main/java/io/soluble/pjb/script/PhpCompiledScriptContext.java
index c0dd066..22a7745 100644
--- a/server/php/java/script/PhpCompiledScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/PhpCompiledScriptContext.java
@@ -1,13 +1,13 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
import java.io.OutputStream;
import java.io.Reader;
import java.util.Map;
-import php.java.bridge.ILogger;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.http.HeaderParser;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/PhpJavaBridgeRunnerScriptContext.java b/src/main/java/io/soluble/pjb/script/PhpJavaBridgeRunnerScriptContext.java
similarity index 94%
rename from server/php/java/script/PhpJavaBridgeRunnerScriptContext.java
rename to src/main/java/io/soluble/pjb/script/PhpJavaBridgeRunnerScriptContext.java
index 97afad0..459b895 100644
--- a/server/php/java/script/PhpJavaBridgeRunnerScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/PhpJavaBridgeRunnerScriptContext.java
@@ -1,11 +1,11 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
import javax.script.ScriptContext;
-import php.java.bridge.JavaBridgeRunner;
-import php.java.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.JavaBridgeRunner;
+import io.soluble.pjb.bridge.http.ContextServer;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
diff --git a/server/php/java/script/PhpScriptContext.java b/src/main/java/io/soluble/pjb/script/PhpScriptContext.java
similarity index 82%
rename from server/php/java/script/PhpScriptContext.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptContext.java
index c438a2d..1b3cef3 100644
--- a/server/php/java/script/PhpScriptContext.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptContext.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -32,23 +32,23 @@
import javax.script.ScriptContext;
-import php.java.bridge.ILogger;
-import php.java.bridge.JavaBridgeRunner;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.HeaderParser;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.JavaBridgeRunner;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.http.IContext;
/**
* This class implements a simple script context for PHP. It starts a standalone
* JavaBridgeRunner which listens for requests from php instances.php.java.script.http.PhpSimpleHttpScriptContext instead.
+ * In a servlet environment please use a io.soluble.pjb.script.http.PhpSimpleHttpScriptContext instead.
*
* @author jostb
- * @see php.java.script.PhpScriptContext
- * @see php.java.bridge.JavaBridgeRunner
+ * @see io.soluble.pjb.script.PhpScriptContext
+ * @see io.soluble.pjb.bridge.JavaBridgeRunner
*/
public final class PhpScriptContext extends AbstractPhpScriptContext {
@@ -59,15 +59,17 @@ public PhpScriptContext(ScriptContext ctx) {
/**
* {@inheritDoc}
*/
+ @Override
public Object init(Object callable) throws Exception {
- return php.java.bridge.http.Context.getManageable(callable);
+ return io.soluble.pjb.bridge.http.Context.getManageable(callable);
}
/**
* {@inheritDoc}
*/
+ @Override
public void onShutdown(Object closeable) {
- php.java.bridge.http.Context.handleManaged(closeable);
+ io.soluble.pjb.bridge.http.Context.handleManaged(closeable);
}
/**
@@ -75,6 +77,7 @@ public void onShutdown(Object closeable) {
*
* @return none
*/
+ @Override
public Object getHttpServletRequest() {
throw new IllegalStateException("PHP not running in a servlet environment");
}
@@ -84,6 +87,7 @@ public Object getHttpServletRequest() {
*
* @return none
*/
+ @Override
public Object getServletContext() {
throw new IllegalStateException("PHP not running in a servlet environment");
}
@@ -93,6 +97,7 @@ public Object getServletContext() {
*
* @return none
*/
+ @Override
public Object getHttpServletResponse() {
throw new IllegalStateException("PHP not running in a servlet environment");
}
@@ -102,6 +107,7 @@ public Object getHttpServletResponse() {
*
* @return none
*/
+ @Override
public Object getServlet() {
throw new IllegalStateException("PHP not running in a servlet environment");
}
@@ -111,6 +117,7 @@ public Object getServlet() {
*
* @return none
*/
+ @Override
public Object getServletConfig() {
throw new IllegalStateException("PHP not running in a servlet environment");
}
@@ -118,13 +125,15 @@ public Object getServletConfig() {
/**
* {@inheritDoc}
*/
+ @Override
public String getRealPath(String path) {
- return php.java.bridge.http.Context.getRealPathInternal(path);
+ return io.soluble.pjb.bridge.http.Context.getRealPathInternal(path);
}
/**
* {@inheritDoc}
*/
+ @Override
public Object get(String key) {
return getBindings(IContext.ENGINE_SCOPE).get(key);
}
@@ -132,6 +141,7 @@ public Object get(String key) {
/**
* {@inheritDoc}
*/
+ @Override
public void put(String key, Object val) {
getBindings(IContext.ENGINE_SCOPE).put(key, val);
}
@@ -139,6 +149,7 @@ public void put(String key, Object val) {
/**
* {@inheritDoc}
*/
+ @Override
public void remove(String key) {
getBindings(IContext.ENGINE_SCOPE).remove(key);
}
@@ -146,6 +157,7 @@ public void remove(String key) {
/**
* {@inheritDoc}
*/
+ @Override
public void putAll(Map map) {
getBindings(IContext.ENGINE_SCOPE).putAll(map);
}
@@ -153,6 +165,7 @@ public void putAll(Map map) {
/**
* {@inheritDoc}
*/
+ @Override
public Map getAll() {
return Collections.unmodifiableMap(getBindings(IContext.ENGINE_SCOPE));
}
@@ -160,6 +173,7 @@ public Map getAll() {
/**
* {@inheritDoc}
*/
+ @Override
public Continuation createContinuation(Reader reader, Map env,
OutputStream out, OutputStream err, HeaderParser headerParser, ResultProxy result,
ILogger logger, boolean isCompiled) {
@@ -175,7 +189,7 @@ public Continuation createContinuation(Reader reader, Map env,
private static JavaBridgeRunner httpServer;
- private static synchronized final JavaBridgeRunner getHttpServer() {
+ private static synchronized JavaBridgeRunner getHttpServer() {
if (httpServer != null) return httpServer;
try {
return httpServer = JavaBridgeRunner.getRequiredInstance();
@@ -188,20 +202,26 @@ private static synchronized final JavaBridgeRunner getHttpServer() {
/**
* {@inheritDoc}
*/
+ @Override
public String getSocketName() {
return getHttpServer().getSocket().getSocketName();
}
/**
+ * @return
* @deprecated
*/
+ @Override
public String getRedirectString() {
throw new NotImplementedException();
}
/**
+ * @param webPath
+ * @return
* @deprecated
*/
+ @Override
public String getRedirectString(String webPath) {
throw new NotImplementedException();
}
@@ -209,6 +229,7 @@ public String getRedirectString(String webPath) {
/**
* {@inheritDoc}
*/
+ @Override
public String getRedirectURL(String webPath) {
return "http://127.0.0.1:" + getSocketName() + webPath;
}
@@ -216,6 +237,7 @@ public String getRedirectURL(String webPath) {
/**
* {@inheritDoc}
*/
+ @Override
public ContextServer getContextServer() {
return getHttpServer().getContextServer();
}
diff --git a/server/php/java/script/PhpScriptContextDecorator.java b/src/main/java/io/soluble/pjb/script/PhpScriptContextDecorator.java
similarity index 97%
rename from server/php/java/script/PhpScriptContextDecorator.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptContextDecorator.java
index db08a2d..99e28dc 100644
--- a/server/php/java/script/PhpScriptContextDecorator.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptContextDecorator.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -32,10 +32,10 @@
import javax.script.Bindings;
-import php.java.bridge.ILogger;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.HeaderParser;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.HeaderParser;
/**
* Abstract class for IPhpScriptContexts. The abstract class itself provides default methods that pass
diff --git a/server/php/java/script/PhpScriptContextFactory.java b/src/main/java/io/soluble/pjb/script/PhpScriptContextFactory.java
similarity index 86%
rename from server/php/java/script/PhpScriptContextFactory.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptContextFactory.java
index 7b2d595..fd8f2aa 100644
--- a/server/php/java/script/PhpScriptContextFactory.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptContextFactory.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -24,16 +24,16 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-import php.java.bridge.http.ContextFactory;
-import php.java.bridge.http.IContext;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.http.ContextFactory;
+import io.soluble.pjb.bridge.http.IContext;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* A custom context factory, creates a ContextFactory for JSR223 contexts.
*
* @author jostb
*/
-public class PhpScriptContextFactory extends php.java.bridge.http.SimpleContextFactory {
+public class PhpScriptContextFactory extends io.soluble.pjb.bridge.http.SimpleContextFactory {
/**
* Add the PhpScriptContext
diff --git a/server/php/java/script/PhpScriptEngine.java b/src/main/java/io/soluble/pjb/script/PhpScriptEngine.java
similarity index 98%
rename from server/php/java/script/PhpScriptEngine.java
rename to src/main/java/io/soluble/pjb/script/PhpScriptEngine.java
index e9851ba..a6ea00b 100644
--- a/server/php/java/script/PhpScriptEngine.java
+++ b/src/main/java/io/soluble/pjb/script/PhpScriptEngine.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script;
+package io.soluble.pjb.script;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -37,8 +37,8 @@
import javax.script.ScriptContext;
import javax.script.ScriptException;
-import php.java.bridge.Util;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IContext;
/**
* This class implements the ScriptEngine.
*
*
@@ -75,6 +73,10 @@ public class PhpHttpScriptContext extends PhpScriptContextDecorator {
* PhpScriptContext
*
* @param ctx the script context to be decorated
+ * @param servlet
+ * @param context
+ * @param request
+ * @param response
*/
public PhpHttpScriptContext(ScriptContext ctx, Servlet servlet, ServletContext context, HttpServletRequest request, HttpServletResponse response) {
super((IPhpScriptContext) ctx);
@@ -87,6 +89,7 @@ public PhpHttpScriptContext(ScriptContext ctx, Servlet servlet, ServletContext c
/**
* {@inheritDoc}
*/
+ @Override
public Continuation createContinuation(Reader reader, Map env,
OutputStream out, OutputStream err, HeaderParser headerParser, ResultProxy result,
ILogger logger, boolean isCompiled) {
@@ -100,6 +103,7 @@ public Continuation createContinuation(Reader reader, Map env,
return cont;
}
+ @Override
public void startContinuation() {
ContextLoaderListener listener = ContextLoaderListener.getContextLoaderListener((ServletContext) getServletContext());
listener.getThreadPool().start(getContinuation());
@@ -129,21 +133,24 @@ public void startContinuation() {
/**
* {@inheritDoc}
*/
+ @Override
public Object getAttribute(String key, int scope) {
- if (scope == REQUEST_SCOPE) {
- return request.getAttribute(key);
- } else if (scope == SESSION_SCOPE) {
- return request.getSession().getAttribute(key);
- } else if (scope == APPLICATION_SCOPE) {
- return context.getAttribute(key);
- } else {
- return super.getAttribute(key, scope);
+ switch (scope) {
+ case REQUEST_SCOPE:
+ return request.getAttribute(key);
+ case SESSION_SCOPE:
+ return request.getSession().getAttribute(key);
+ case APPLICATION_SCOPE:
+ return context.getAttribute(key);
+ default:
+ return super.getAttribute(key, scope);
}
}
/**
* {@inheritDoc}
*/
+ @Override
public Object getAttribute(String name) throws IllegalArgumentException {
Object result;
if (name == null) {
@@ -164,16 +171,22 @@ public Object getAttribute(String name) throws IllegalArgumentException {
/**
* {@inheritDoc}
*/
+ @Override
public void setAttribute(String key, Object value, int scope)
throws IllegalArgumentException {
- if (scope == REQUEST_SCOPE) {
- request.setAttribute(key, value);
- } else if (scope == SESSION_SCOPE) {
- request.getSession().setAttribute(key, value);
- } else if (scope == APPLICATION_SCOPE) {
- context.setAttribute(key, value);
- } else {
- super.setAttribute(key, value, scope);
+ switch (scope) {
+ case REQUEST_SCOPE:
+ request.setAttribute(key, value);
+ break;
+ case SESSION_SCOPE:
+ request.getSession().setAttribute(key, value);
+ break;
+ case APPLICATION_SCOPE:
+ context.setAttribute(key, value);
+ break;
+ default:
+ super.setAttribute(key, value, scope);
+ break;
}
}
@@ -209,6 +222,7 @@ public ServletContext getContext() {
/**
* {@inheritDoc}
*/
+ @Override
public Writer getWriter() {
if (writer == null) {
try {
@@ -223,6 +237,7 @@ public Writer getWriter() {
/**
* {@inheritDoc}
*/
+ @Override
public void setWriter(Writer writer) {
if (!(writer instanceof PhpScriptWriter)) {
writer = new PhpScriptWriter(new WriterOutputStream(writer));
@@ -235,9 +250,10 @@ public void setWriter(Writer writer) {
/**
* {@inheritDoc}
*/
+ @Override
public Writer getErrorWriter() {
if (errorWriter == null) {
- setErrorWriter(PhpScriptLogWriter.getWriter(new php.java.servlet.Logger()));
+ setErrorWriter(PhpScriptLogWriter.getWriter(new io.soluble.pjb.servlet.Logger()));
}
return errorWriter;
}
@@ -245,6 +261,7 @@ public Writer getErrorWriter() {
/**
* {@inheritDoc}
*/
+ @Override
public void setErrorWriter(Writer errorWriter) {
if (!(errorWriter instanceof PhpScriptWriter)) {
errorWriter = new PhpScriptWriter(new WriterOutputStream(errorWriter));
@@ -257,6 +274,7 @@ public void setErrorWriter(Writer errorWriter) {
/**
* {@inheritDoc}
*/
+ @Override
public Reader getReader() {
if (reader == null) {
try {
@@ -268,6 +286,7 @@ public Reader getReader() {
return reader;
}
+ @Override
public void setReader(Reader reader) {
super.setReader(this.reader = reader);
}
@@ -275,15 +294,17 @@ public void setReader(Reader reader) {
/**
* {@inheritDoc}
*/
+ @Override
public Object init(Object callable) throws Exception {
- return php.java.bridge.http.Context.getManageable(callable);
+ return io.soluble.pjb.bridge.http.Context.getManageable(callable);
}
/**
* {@inheritDoc}
*/
+ @Override
public void onShutdown(Object closeable) {
- php.java.servlet.HttpContext.handleManaged(closeable, context);
+ io.soluble.pjb.servlet.HttpContext.handleManaged(closeable, context);
}
/**
@@ -291,6 +312,7 @@ public void onShutdown(Object closeable) {
*
* @return The http servlet reponse
*/
+ @Override
public Object getHttpServletResponse() {
return response;
}
@@ -300,6 +322,7 @@ public Object getHttpServletResponse() {
*
* @return The http servlet request
*/
+ @Override
public Object getHttpServletRequest() {
return request;
}
@@ -309,6 +332,7 @@ public Object getHttpServletRequest() {
*
* @return The http servlet
*/
+ @Override
public Object getServlet() {
return servlet;
}
@@ -318,6 +342,7 @@ public Object getServlet() {
*
* @return The servlet config
*/
+ @Override
public Object getServletConfig() {
return servlet.getServletConfig();
}
@@ -327,6 +352,7 @@ public Object getServletConfig() {
*
* @return The servlet context
*/
+ @Override
public Object getServletContext() {
return context;
}
@@ -334,6 +360,7 @@ public Object getServletContext() {
/**
* {@inheritDoc}
*/
+ @Override
public String getRealPath(String path) {
return ServletUtil.getRealPath(context, path);
}
@@ -341,6 +368,7 @@ public String getRealPath(String path) {
/**
* @deprecated
*/
+ @Override
public String getRedirectString(String webPath) {
throw new NotImplementedException();
}
@@ -348,6 +376,7 @@ public String getRedirectString(String webPath) {
/**
* @deprecated
*/
+ @Override
public String getRedirectString() {
throw new NotImplementedException();
}
@@ -355,8 +384,9 @@ public String getRedirectString() {
/**
* {@inheritDoc}
*/
+ @Override
public String getRedirectURL(String webPath) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append(getSocketName());
buf.append("/");
buf.append(webPath);
@@ -372,6 +402,7 @@ public String getRedirectURL(String webPath) {
/**
* {@inheritDoc}
*/
+ @Override
public String getSocketName() {
return String.valueOf(ServletUtil.getLocalPort(request));
}
@@ -379,6 +410,7 @@ public String getSocketName() {
/**
* {@inheritDoc}
*/
+ @Override
public ContextServer getContextServer() {
return ContextLoaderListener.getContextLoaderListener(context).getContextServer();
}
diff --git a/server/php/java/script/servlet/PhpScriptLogWriter.java b/src/main/java/io/soluble/pjb/script/servlet/PhpScriptLogWriter.java
similarity index 92%
rename from server/php/java/script/servlet/PhpScriptLogWriter.java
rename to src/main/java/io/soluble/pjb/script/servlet/PhpScriptLogWriter.java
index d159299..5127304 100644
--- a/server/php/java/script/servlet/PhpScriptLogWriter.java
+++ b/src/main/java/io/soluble/pjb/script/servlet/PhpScriptLogWriter.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.script.servlet;
+package io.soluble.pjb.script.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -27,9 +27,9 @@
import java.io.IOException;
import java.io.OutputStream;
-import php.java.bridge.ILogger;
-import php.java.bridge.NotImplementedException;
-import php.java.script.PhpScriptWriter;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.script.PhpScriptWriter;
/**
* A PrintWriter which uses the JavaBridge logger.
diff --git a/server/php/java/script/servlet/package.html b/src/main/java/io/soluble/pjb/script/servlet/package.html
similarity index 100%
rename from server/php/java/script/servlet/package.html
rename to src/main/java/io/soluble/pjb/script/servlet/package.html
diff --git a/server/php/java/servlet/BufferedResponse.java b/src/main/java/io/soluble/pjb/servlet/BufferedResponse.java
similarity index 97%
rename from server/php/java/servlet/BufferedResponse.java
rename to src/main/java/io/soluble/pjb/servlet/BufferedResponse.java
index edcc34a..ab5e320 100644
--- a/server/php/java/servlet/BufferedResponse.java
+++ b/src/main/java/io/soluble/pjb/servlet/BufferedResponse.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import java.io.IOException;
diff --git a/server/php/java/servlet/ContextLoaderListener.java b/src/main/java/io/soluble/pjb/servlet/ContextLoaderListener.java
similarity index 94%
rename from server/php/java/servlet/ContextLoaderListener.java
rename to src/main/java/io/soluble/pjb/servlet/ContextLoaderListener.java
index 5816637..c3ac740 100644
--- a/server/php/java/servlet/ContextLoaderListener.java
+++ b/src/main/java/io/soluble/pjb/servlet/ContextLoaderListener.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import java.io.File;
import java.io.FileOutputStream;
@@ -18,21 +18,21 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import php.java.bridge.ILogger;
-import php.java.bridge.ThreadPool;
-import php.java.bridge.Util;
-import php.java.bridge.http.ContextServer;
-import php.java.bridge.http.FCGIConnectException;
-import php.java.bridge.http.FCGIConnection;
-import php.java.bridge.http.FCGIConnectionFactory;
-import php.java.bridge.http.FCGIConnectionPool;
-import php.java.bridge.http.FCGIIOFactory;
-import php.java.bridge.http.FCGIInputStream;
-import php.java.bridge.http.FCGIOutputStream;
-import php.java.bridge.http.FCGIUtil;
-import php.java.bridge.http.IFCGIProcess;
-import php.java.bridge.http.IFCGIProcessFactory;
-import php.java.servlet.fastcgi.FCGIProcess;
+import io.soluble.pjb.bridge.ILogger;
+import io.soluble.pjb.bridge.ThreadPool;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.http.FCGIConnectException;
+import io.soluble.pjb.bridge.http.FCGIConnection;
+import io.soluble.pjb.bridge.http.FCGIConnectionFactory;
+import io.soluble.pjb.bridge.http.FCGIConnectionPool;
+import io.soluble.pjb.bridge.http.FCGIIOFactory;
+import io.soluble.pjb.bridge.http.FCGIInputStream;
+import io.soluble.pjb.bridge.http.FCGIOutputStream;
+import io.soluble.pjb.bridge.http.FCGIUtil;
+import io.soluble.pjb.bridge.http.IFCGIProcess;
+import io.soluble.pjb.bridge.http.IFCGIProcessFactory;
+import io.soluble.pjb.servlet.fastcgi.FCGIProcess;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -57,12 +57,12 @@
*/
/**
- * Register the PHP/Java Bridge when the web context starts. Used by java_context()->onShutdown(proc). The
+ * Register the PHP/Java Bridge when the web context starts. Used by java_context()->onShutdown(proc). The
* WEB-INF/web.xml contains a listener attribute:
*
- * static final CompiledScript script = ((Compilable)(new ScriptEngineManager().getEngineByName("php-invocable"))).compile("");
*
+ * static final CompiledScript script = ((Compilable)(new ScriptEngineManager().getEngineByName("php-invocable"))).compile("<?php ...?>");
*
- * script.eval(new php.java.script.servlet.PhpCompiledHttpScriptContext(script.getEngine().getContext(),this,application,request,response));
+ * script.eval(new io.soluble.pjb.script.servlet.PhpCompiledHttpScriptContext(script.getEngine().getContext(),this,application,request,response));
*
*
@@ -218,9 +218,9 @@ private void init() {
try {
val = context.getInitParameter("php_fcgi_children");
if (val == null) val = context.getInitParameter("PHP_FCGI_CHILDREN");
- if (val == null) val = System.getProperty("php.java.bridge.php_fcgi_children");
+ if (val == null) val = System.getProperty("io.soluble.pjb.bridge.php_fcgi_children");
if (val == null) val = context.getInitParameter("php_fcgi_connection_pool_size");
- if (val == null) val = System.getProperty("php.java.bridge.php_fcgi_connection_pool_size");
+ if (val == null) val = System.getProperty("io.soluble.pjb.bridge.php_fcgi_connection_pool_size");
if (val != null) php_fcgi_connection_pool_size_number = Integer.parseInt(val);
} catch (Throwable t) {/*ignore*/}
if (val != null) php_fcgi_connection_pool_size = val;
@@ -228,7 +228,7 @@ private void init() {
val = null;
try {
val = context.getInitParameter("php_fcgi_connection_pool_timeout");
- if (val == null) val = System.getProperty("php.java.bridge.php_fcgi_connection_pool_timeout");
+ if (val == null) val = System.getProperty("io.soluble.pjb.bridge.php_fcgi_connection_pool_timeout");
if (val != null) php_fcgi_connection_pool_timeout_number = Integer.parseInt(val);
} catch (Throwable t) {/*ignore*/}
if (val != null) php_fcgi_connection_pool_timeout = val;
@@ -238,7 +238,7 @@ private void init() {
try {
val = context.getInitParameter("php_include_java");
if (val == null) val = context.getInitParameter("PHP_INCLUDE_JAVA");
- if (val == null) val = System.getProperty("php.java.bridge.php_include_java");
+ if (val == null) val = System.getProperty("io.soluble.pjb.bridge.php_include_java");
if (val != null && (val.equalsIgnoreCase("on") || val.equalsIgnoreCase("true")))
php_include_java = true;
} catch (Throwable t) {/*ignore*/}
@@ -246,7 +246,7 @@ private void init() {
val = null;
try {
val = context.getInitParameter("php_fcgi_max_requests");
- if (val == null) val = System.getProperty("php.java.bridge.php_fcgi_max_requests");
+ if (val == null) val = System.getProperty("io.soluble.pjb.bridge.php_fcgi_max_requests");
if (val != null) {
php_fcgi_max_requests_number = Integer.parseInt(val);
php_fcgi_max_requests = val;
@@ -278,7 +278,7 @@ private void checkCgiBinary() {
try {
value = context.getInitParameter("use_fast_cgi");
if (value == null) try {
- value = System.getProperty("php.java.bridge.use_fast_cgi");
+ value = System.getProperty("io.soluble.pjb.bridge.use_fast_cgi");
} catch (Exception e) {/*ignore*/}
if ("false".equalsIgnoreCase(value) || "off".equalsIgnoreCase(value)) fcgiIsConfigured = false;
else {
diff --git a/server/php/java/servlet/HttpContext.java b/src/main/java/io/soluble/pjb/servlet/HttpContext.java
similarity index 91%
rename from server/php/java/servlet/HttpContext.java
rename to src/main/java/io/soluble/pjb/servlet/HttpContext.java
index 4fb0e89..cbfc43f 100644
--- a/server/php/java/servlet/HttpContext.java
+++ b/src/main/java/io/soluble/pjb/servlet/HttpContext.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
import java.io.IOException;
import java.io.Writer;
@@ -10,9 +10,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.NotImplementedException;
-import php.java.bridge.Util;
-import php.java.bridge.http.IContext;
+import io.soluble.pjb.bridge.NotImplementedException;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.IContext;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -42,7 +42,7 @@
*
* @author jostb
*/
-public class HttpContext extends php.java.bridge.http.Context {
+public class HttpContext extends io.soluble.pjb.bridge.http.Context {
protected HttpServletResponse response;
protected ServletContext context;
protected HttpServletRequest request;
@@ -138,7 +138,7 @@ public Object getServletContext() {
/**
* Only for internal use.
* <listener>
- * <listener-class>php.java.servlet.ContextLoaderListener</listener-class>
+ * <listener-class>io.soluble.pjb.servlet.ContextLoaderListener</listener-class>
* </listener>
*
*
* Used when scripts are running within of a servlet environment:
- * Either php.java.servlet.Context or the JSR223 Context (see PhpSimpleHttpScriptContext).
+ * Either io.soluble.pjb.servlet.Context or the JSR223 Context (see PhpSimpleHttpScriptContext).
* Outside of a servlet environment use the ContextLoaderListener instead:
* Either the Standalone or the JSR223 Standalone (see PhpScriptContext).
*
@@ -155,7 +155,7 @@ public static void handleManaged(Object closeable, ServletContext ctx) {
*/
public Object init(Object callable) throws Exception {
if (Util.logLevel > 3) Util.logDebug("calling servlet context init");
- return php.java.bridge.http.Context.getManageable(callable);
+ return io.soluble.pjb.bridge.http.Context.getManageable(callable);
}
/**
@@ -172,7 +172,7 @@ public void onShutdown(Object closeable) {
* @param path the path
* @param ctx the servlet context
* @return the real path
- * @deprecated Use {@link php.java.servlet.ServletUtil#getRealPath(ServletContext, String)}
+ * @deprecated Use {@link io.soluble.pjb.servlet.ServletUtil#getRealPath(ServletContext, String)}
*/
public static String getRealPathInternal(String path, ServletContext ctx) {
return ServletUtil.getRealPath(ctx, path);
diff --git a/server/php/java/servlet/HttpContextRunner.java b/src/main/java/io/soluble/pjb/servlet/HttpContextRunner.java
similarity index 94%
rename from server/php/java/servlet/HttpContextRunner.java
rename to src/main/java/io/soluble/pjb/servlet/HttpContextRunner.java
index 111c3b2..4b4b501 100644
--- a/server/php/java/servlet/HttpContextRunner.java
+++ b/src/main/java/io/soluble/pjb/servlet/HttpContextRunner.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -29,11 +29,11 @@
import java.io.OutputStream;
import java.io.Serializable;
-import php.java.bridge.JavaBridge;
-import php.java.bridge.Request;
-import php.java.bridge.Util;
-import php.java.bridge.http.AbstractChannel;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.JavaBridge;
+import io.soluble.pjb.bridge.Request;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.AbstractChannel;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* @author jostb
diff --git a/server/php/java/servlet/HttpSessionFacade.java b/src/main/java/io/soluble/pjb/servlet/HttpSessionFacade.java
similarity index 98%
rename from server/php/java/servlet/HttpSessionFacade.java
rename to src/main/java/io/soluble/pjb/servlet/HttpSessionFacade.java
index 4d8194d..5265451 100644
--- a/server/php/java/servlet/HttpSessionFacade.java
+++ b/src/main/java/io/soluble/pjb/servlet/HttpSessionFacade.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -34,8 +34,8 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import php.java.bridge.ISession;
-import php.java.bridge.http.IContextFactory;
+import io.soluble.pjb.bridge.ISession;
+import io.soluble.pjb.bridge.http.IContextFactory;
/**
* Wraps the J2EE session interface
diff --git a/server/php/java/servlet/Logger.java b/src/main/java/io/soluble/pjb/servlet/Logger.java
similarity index 95%
rename from server/php/java/servlet/Logger.java
rename to src/main/java/io/soluble/pjb/servlet/Logger.java
index 3929424..df9c2b6 100644
--- a/server/php/java/servlet/Logger.java
+++ b/src/main/java/io/soluble/pjb/servlet/Logger.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
@@ -24,7 +24,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-import php.java.bridge.ILogger;
+import io.soluble.pjb.bridge.ILogger;
/**
* A logger class, uses log4j if possible
diff --git a/server/php/java/servlet/PhpCGIFilter.java b/src/main/java/io/soluble/pjb/servlet/PhpCGIFilter.java
similarity index 96%
rename from server/php/java/servlet/PhpCGIFilter.java
rename to src/main/java/io/soluble/pjb/servlet/PhpCGIFilter.java
index 1843f99..877eb20 100644
--- a/server/php/java/servlet/PhpCGIFilter.java
+++ b/src/main/java/io/soluble/pjb/servlet/PhpCGIFilter.java
@@ -1,6 +1,6 @@
/*-*- mode: Java; tab-width:8 -*-*/
-package php.java.servlet;
+package io.soluble.pjb.servlet;
/*
* Copyright (C) 2003-2010 Jost Boekemeier
@@ -37,7 +37,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
-import php.java.bridge.Util;
+import io.soluble.pjb.bridge.Util;
/**
* Handles /foo/bar.php/baz?param=value requests.
@@ -48,7 +48,7 @@
*
* <filter>
*
*
- * @see php.java.servlet.fastcgi.FastCGIServlet
+ * @see io.soluble.pjb.servlet.fastcgi.FastCGIServlet
*/
public class PhpCGIFilter implements Filter {
diff --git a/server/php/java/servlet/PhpJavaServlet.java b/src/main/java/io/soluble/pjb/servlet/PhpJavaServlet.java
similarity index 92%
rename from server/php/java/servlet/PhpJavaServlet.java
rename to src/main/java/io/soluble/pjb/servlet/PhpJavaServlet.java
index ee8b709..f71ed99 100644
--- a/server/php/java/servlet/PhpJavaServlet.java
+++ b/src/main/java/io/soluble/pjb/servlet/PhpJavaServlet.java
@@ -1,7 +1,3 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package php.java.servlet;
-
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
@@ -24,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+package io.soluble.pjb.servlet;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -36,12 +34,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import php.java.bridge.JavaBridge;
-import php.java.bridge.Request;
-import php.java.bridge.Util;
-import php.java.bridge.http.AbstractChannelName;
-import php.java.bridge.http.ContextFactory;
-import php.java.bridge.http.ContextServer;
+import io.soluble.pjb.bridge.JavaBridge;
+import io.soluble.pjb.bridge.Request;
+import io.soluble.pjb.bridge.Util;
+import io.soluble.pjb.bridge.http.AbstractChannelName;
+import io.soluble.pjb.bridge.http.ContextFactory;
+import io.soluble.pjb.bridge.http.ContextServer;
/**
* Handles requests from PHP clients.
* <filter-name>PhpCGIFilter</filter-name>
- * <filter-class>php.java.servlet.PhpCGIFilter</filter-class>
+ * <filter-class>io.soluble.pjb.servlet.PhpCGIFilter</filter-class>
* </filter>
* <filter-mapping>
* <filter-name>PhpCGIFilter</filter-name>
@@ -57,7 +57,7 @@
* java -Dphp.java.bridge.default_log_level=6 -jar /opt/jakarta-tomcat-5.5.9/bin/bootstrap.jar
+ * To enable fcg/servlet debug code start the servlet engine with -Dio.soluble.pjb.default_log_level=6.
+ * For example: java -Dio.soluble.pjb.default_log_level=6 -jar /opt/jakarta-tomcat-5.5.9/bin/bootstrap.jar
* launcher.exe -a "path_to_php-cgi.exe" -b 9667.";
+$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT)));
+}
+function writeBoolean($boolean) {
+$this->client->currentArgumentsFormat.=$format="PhpJavaBridge Home
+
+
diff --git a/security/module/php-java-bridge-tomcat.fc.in b/src/main/webapp/java/.gitkeep
similarity index 100%
rename from security/module/php-java-bridge-tomcat.fc.in
rename to src/main/webapp/java/.gitkeep
diff --git a/src/main/webapp/java/Java.inc b/src/main/webapp/java/Java.inc
new file mode 100644
index 0000000..58aa375
--- /dev/null
+++ b/src/main/webapp/java/Java.inc
@@ -0,0 +1,2084 @@
+0) {
+$thiz=$ar[$arLen-1];
+return dirname($thiz);
+} else {
+return "java";
+}
+}
+function java_truncate($str) {
+if (strlen($str)>955)
+return substr($str,0,475).'[...]'.substr($str,-475);
+return $str;
+}
+class java_JavaException extends Exception {
+function __toString() {return $this->getMessage();}
+};
+class java_RuntimeException extends java_JavaException {};
+class java_IOException extends java_JavaException {};
+class java_ConnectException extends java_IOException {};
+class java_IllegalStateException extends java_RuntimeException {};
+class java_IllegalArgumentException extends java_RuntimeException {
+function __construct($ob) {
+parent::__construct("illegal argument: ".gettype($ob));
+}
+};
+function java_autoload_function5($x) {
+$s=str_replace("_",".",$x);
+$c=__javaproxy_Client_getClient();
+if(!($c->invokeMethod(0,"typeExists",array($s)))) return false;
+$i="class ${x} extends Java {".
+"static function type(\$sub=null){if(\$sub) \$sub='\$'.\$sub; return java('${s}'.\"\$sub\");}".
+'function __construct() {$args=func_get_args();'.
+'array_unshift($args,'."'$s'".'); parent::__construct($args);}}';
+eval ("$i");
+return true;
+}
+function java_autoload_function($x) {
+$idx=strrpos($x,"\\"); if (!$idx) return java_autoload_function5($x);
+$str=str_replace("\\",".",$x);
+$client=__javaproxy_Client_getClient();
+if(!($client->invokeMethod(0,"typeExists",array($str)))) return false;
+$package=substr($x,0,$idx);
+$name=substr($x,1+$idx);
+$instance="namespace $package; class ${name} extends \\Java {".
+"static function type(\$sub=null){if(\$sub) \$sub='\$'.\$sub;return \\java('${str}'.\"\$sub\");}".
+"static function __callStatic(\$procedure,\$args) {return \\java_invoke(\\java('${str}'),\$procedure,\$args);}".
+'function __construct() {$args=func_get_args();'.
+'array_unshift($args,'."'$str'".'); parent::__construct($args);}}';
+eval ("$instance");
+return true;
+}
+if(!defined("JAVA_DISABLE_AUTOLOAD") && function_exists("spl_autoload_register")) spl_autoload_register("java_autoload_function");
+function java_autoload($libs=null) {
+trigger_error('Please use getHttpServletResponse();
+$res=new java("io.soluble.pjb.servlet.RemoteHttpServletResponse",$res);
+$req->getRequestDispatcher($path)->include($req,$res);
+if ($return) return $res->getBufferContents();
+echo $res->getBufferContents();
+return true;
+}
+function Java($name) {
+static $classMap=array();
+if(array_key_exists($name,$classMap)) return $classMap[$name];
+return $classMap[$name]=new JavaClass($name);
+}
+function java_get_closure() {return java_closure_array(func_get_args());}
+function java_wrap() {return java_closure_array(func_get_args());}
+function java_get_values($arg) { return java_values($arg); }
+function java_get_session() {return java_session_array(func_get_args());}
+function java_get_context() {return java_context(); }
+function java_get_server_name() { return java_server_name(); }
+function java_isnull($value) { return is_null (java_values ($value)); }
+function java_is_null($value) { return is_null (java_values ($value)); }
+function java_istrue($value) { return (boolean)(java_values ($value)); }
+function java_is_true($value) { return (boolean)(java_values ($value)); }
+function java_isfalse($value) { return !(java_values ($value)); }
+function java_is_false($value) { return !(java_values ($value)); }
+function java_set_encoding($enc) { return java_set_file_encoding ($enc); }
+function java_call_with_continuation($kontinuation=null) {
+if (java_getHeader("X_JAVABRIDGE_INCLUDE",$_SERVER) && !java_getHeader("X_JAVABRIDGE_INCLUDE_ONLY",$_SERVER)) {
+if (is_null($kontinuation))
+java_context()->call(java_closure());
+elseif (is_string($kontinuation))
+java_context()->call(call_user_func($kontinuation));
+elseif ($kontinuation instanceof java_JavaType)
+java_context()->call($kontinuation);
+else
+java_context()->call(java_closure($kontinuation));
+}
+}
+function java_defineHostFromInitialQuery($java_base) {
+if($java_base!="java") {
+$url=parse_url($java_base);
+if(isset($url["scheme"]) && ($url["scheme"]=="http" || $url["scheme"]=="https")) {
+$scheme=$url["scheme"]=="https" ? "ssl://" : "";
+$host=$url["host"];
+$port=$url["port"];
+$path=$url["path"];
+define ("JAVA_HOSTS","${scheme}${host}:${port}");
+$dir=dirname($path);
+define ("JAVA_SERVLET","$dir/servlet.phpjavabridge");
+return true;
+}
+}
+return false;
+}
+define("JAVA_PEAR_VERSION","6.2.11");
+if(!defined("JAVA_SEND_SIZE"))
+define("JAVA_SEND_SIZE",8192);
+if(!defined("JAVA_RECV_SIZE"))
+define("JAVA_RECV_SIZE",8192);
+if(!defined("JAVA_HOSTS")) {
+if(!java_defineHostFromInitialQuery(java_get_base())) {
+if ($java_ini=get_cfg_var("java.hosts")) define("JAVA_HOSTS",$java_ini);
+else define("JAVA_HOSTS","127.0.0.1:8080");
+}
+}
+if(!defined("JAVA_SERVLET")) {
+if (!(($java_ini=get_cfg_var("java.servlet"))===false)) define("JAVA_SERVLET",$java_ini);
+else define("JAVA_SERVLET",1);
+}
+if(!defined("JAVA_LOG_LEVEL"))
+if (!(($java_ini=get_cfg_var("java.log_level"))===false)) define("JAVA_LOG_LEVEL",(int)$java_ini);
+else define("JAVA_LOG_LEVEL",null);
+if (!defined("JAVA_PREFER_VALUES"))
+if ($java_ini=get_cfg_var("java.prefer_values")) define("JAVA_PREFER_VALUES",$java_ini);
+else define("JAVA_PREFER_VALUES",0);
+class java_SimpleFactory {
+public $client;
+function java_SimpleFactory($client) {
+$this->client=$client;
+}
+function getProxy($result,$signature,$exception,$wrap) {
+return $result;
+}
+function checkResult($result) {
+}
+}
+class java_ProxyFactory extends java_SimpleFactory {
+function create($result,$signature) {
+return new java_JavaProxy($result,$signature);
+}
+function createInternal($proxy) {
+return new java_InternalJava($proxy);
+}
+function getProxy($result,$signature,$exception,$wrap) {
+$proxy=$this->create($result,$signature);
+if($wrap) $proxy=$this->createInternal($proxy);
+return $proxy;
+}
+}
+class java_ArrayProxyFactory extends java_ProxyFactory {
+function create($result,$signature) {
+return new java_ArrayProxy($result,$signature);
+}
+}
+class java_IteratorProxyFactory extends java_ProxyFactory {
+function create($result,$signature) {
+return new java_IteratorProxy($result,$signature);
+}
+}
+class java_ExceptionProxyFactory extends java_SimpleFactory {
+function create($result,$signature) {
+return new java_ExceptionProxy($result,$signature);
+}
+function getProxy($result,$signature,$exception,$wrap) {
+$proxy=$this->create($result,$signature);
+if($wrap) $proxy=new java_InternalException($proxy,$exception);
+return $proxy;
+}
+}
+class java_ThrowExceptionProxyFactory extends java_ExceptionProxyFactory {
+function getProxy($result,$signature,$exception,$wrap) {
+$proxy=$this->create($result,$signature);
+$proxy=new java_InternalException($proxy,$exception);
+return $proxy;
+}
+function checkResult($result) {
+if (JAVA_PREFER_VALUES || ($result->__hasDeclaredExceptions=='T'))
+throw $result;
+else {
+trigger_error("Unchecked exception detected: ".java_truncate($result->__toString()),E_USER_WARNING);
+}
+}
+}
+class java_CacheEntry {
+public $fmt,$signature,$factory,$java;
+public $resultVoid;
+function java_CacheEntry($fmt,$signature,$factory,$resultVoid) {
+$this->fmt=$fmt;
+$this->signature=$signature;
+$this->factory=$factory;
+$this->resultVoid=$resultVoid;
+}
+}
+class java_Arg {
+public $client;
+public $exception;
+public $factory,$val;
+public $signature;
+function java_Arg($client) {
+$this->client=$client;
+$this->factory=$client->simpleFactory;
+}
+function linkResult(&$val) {
+$this->val=&$val;
+}
+function setResult($val) {
+$this->val=&$val;
+}
+function getResult($wrap) {
+$rc=$this->factory->getProxy($this->val,$this->signature,$this->exception,$wrap);
+$factory=$this->factory;
+$this->factory=$this->client->simpleFactory;
+$factory->checkResult($rc);
+return $rc;
+}
+function setFactory($factory) {
+$this->factory=$factory;
+}
+function setException($string) {
+$this->exception=$string;
+}
+function setVoidSignature() {
+$this->signature="@V";
+$key=$this->client->currentCacheKey;
+if($key && $key[0]!='~') {
+$this->client->currentArgumentsFormat[6]="3";
+$cacheEntry=new java_CacheEntry($this->client->currentArgumentsFormat,$this->signature,$this->factory,true);
+$this->client->methodCache[$key]=$cacheEntry;
+}
+}
+function setSignature($signature) {
+$this->signature=$signature;
+$key=$this->client->currentCacheKey;
+if($key && $key[0]!='~') {
+$cacheEntry=new java_CacheEntry($this->client->currentArgumentsFormat,$this->signature,$this->factory,false);
+$this->client->methodCache[$key]=$cacheEntry;
+}
+}
+}
+class java_CompositeArg extends java_Arg {
+public $parentArg;
+public $idx;
+public $type;
+public $counter;
+function java_CompositeArg($client,$type) {
+parent::java_Arg($client);
+$this->type=$type;
+$this->val=array();
+$this->counter=0;
+}
+function setNextIndex() {
+$this->idx=$this->counter++;
+}
+function setIndex($val) {
+$this->idx=$val;
+}
+function linkResult(&$val) {
+$this->val[$this->idx]=&$val;
+}
+function setResult($val) {
+$this->val[$this->idx]=$this->factory->getProxy($val,$this->signature,$this->exception,true);
+$this->factory=$this->client->simpleFactory;
+}
+}
+class java_ApplyArg extends java_CompositeArg {
+public $m,$p,$v,$n;
+function java_ApplyArg($client,$type,$m,$p,$v,$n) {
+parent::java_CompositeArg($client,$type);
+$this->m=$m;
+$this->p=$p;
+$this->v=$v;
+$this->n=$n;
+}
+}
+class java_Client {
+public $RUNTIME;
+public $result,$exception;
+public $parser;
+public $simpleArg,$compositeArg;
+public $simpleFactory,
+$proxyFactory,$iteratorProxyFacroty,
+$arrayProxyFactory,$exceptionProxyFactory,$throwExceptionProxyFactory;
+public $arg;
+public $asyncCtx,$cancelProxyCreationCounter;
+public $globalRef;
+public $stack;
+public $defaultCache=array(),$asyncCache=array(),$methodCache;
+public $isAsync=0;
+public $currentCacheKey,$currentArgumentsFormat;
+public $cachedJavaPrototype;
+public $sendBuffer,$preparedToSendBuffer;
+public $inArgs;
+function java_Client() {
+$this->RUNTIME=array();
+$this->RUNTIME["NOTICE"]='***USE echo java_inspect(jVal) OR print_r(java_values(jVal)) TO SEE THE CONTENTS OF THIS JAVA OBJECT!***';
+$this->parser=new java_Parser($this);
+$this->protocol=new java_Protocol($this);
+$this->simpleFactory=new java_SimpleFactory($this);
+$this->proxyFactory=new java_ProxyFactory($this);
+$this->arrayProxyFactory=new java_ArrayProxyFactory($this);
+$this->iteratorProxyFactory=new java_IteratorProxyFactory($this);
+$this->exceptionProxyFactory=new java_ExceptionProxyFactory($this);
+$this->throwExceptionProxyFactory=new java_ThrowExceptionProxyFactory($this);
+$this->cachedJavaPrototype=new java_JavaProxyProxy($this);
+$this->simpleArg=new java_Arg($this);
+$this->globalRef=new java_GlobalRef();
+$this->asyncCtx=$this->cancelProxyCreationCounter=0;
+$this->methodCache=$this->defaultCache;
+$this->inArgs=false;
+}
+function read($size) {
+return $this->protocol->read($size);
+}
+function setDefaultHandler() {
+$this->methodCache=$this->defaultCache;
+}
+function setAsyncHandler() {
+$this->methodCache=$this->asyncCache;
+}
+function handleRequests() {
+$tail_call=false;
+do {
+$this->stack=array($this->arg=$this->simpleArg);
+$this->idx=0;
+$this->parser->parse();
+if((count($this->stack)) > 1) {
+$arg=array_pop($this->stack);
+$this->apply($arg);
+$tail_call=true;
+} else {
+$tail_call=false;
+}
+$this->stack=null;
+} while($tail_call);
+return 1;
+}
+function getWrappedResult($wrap) {
+return $this->simpleArg->getResult($wrap);
+}
+function getInternalResult() {
+return $this->getWrappedResult(false);
+}
+function getResult() {
+return $this->getWrappedResult(true);
+}
+function getProxyFactory($type) {
+switch($type[0]) {
+case 'E':
+$factory=$this->exceptionProxyFactory;
+break;
+case 'C':
+$factory=$this->iteratorProxyFactory;
+break;
+case 'A':
+$factory=$this->arrayProxyFactory;
+break;
+default:
+case 'O':
+$factory=$this->proxyFactory;
+}
+return $factory;
+}
+function link(&$arg,&$newArg) {
+$arg->linkResult($newArg->val);
+$newArg->parentArg=$arg;
+}
+function getExact($str) {
+return hexdec($str);
+}
+function getInexact($str) {
+$val=null;
+sscanf($str,"%e",$val);
+return $val;
+}
+function begin($name,$st) {
+$arg=$this->arg;
+switch($name[0]) {
+case 'A':
+$object=$this->globalRef->get($this->getExact($st['v']));
+$newArg=new java_ApplyArg($this,'A',
+$this->parser->getData($st['m']),
+$this->parser->getData($st['p']),
+$object,
+$this->getExact($st['n']));
+$this->link($arg,$newArg);
+array_push($this->stack,$this->arg=$newArg);
+break;
+case 'X':
+$newArg=new java_CompositeArg($this,$st['t']);
+$this->link($arg,$newArg);
+array_push($this->stack,$this->arg=$newArg);
+break;
+case 'P':
+if($arg->type=='H') {
+$s=$st['t'];
+if($s[0]=='N') {
+$arg->setIndex($this->getExact($st['v']));
+} else {
+$arg->setIndex($this->parser->getData($st['v']));
+}
+} else {
+$arg->setNextIndex();
+}
+break;
+case 'S':
+$arg->setResult($this->parser->getData($st['v']));
+break;
+case 'B':
+$s=$st['v'];
+$arg->setResult($s[0]=='T');
+break;
+case 'L':
+$sign=$st['p'];
+$val=$this->getExact($st['v']);
+if($sign[0]=='A') $val*=-1;
+$arg->setResult($val);
+break;
+case 'D':
+$arg->setResult($this->getInexact($st['v']));
+break;
+case 'V':
+if ($st['n']!='T') {
+$arg->setVoidSignature();
+}
+case 'N':
+$arg->setResult(null);
+break;
+case 'F':
+break;
+case 'O':
+$arg->setFactory($this->getProxyFactory($st['p']));
+$arg->setResult($this->asyncCtx=$this->getExact($st['v']));
+if($st['n']!='T') $arg->setSignature($st['m']);
+break;
+case 'E':
+$arg->setFactory($this->throwExceptionProxyFactory);
+$arg->setException($st['m']);
+$arg->setResult($this->asyncCtx=$this->getExact($st['v']));
+break;
+default:
+$this->parser->parserError();
+}
+}
+function end($name) {
+switch($name[0]) {
+case 'X':
+$frame=array_pop($this->stack);
+$this->arg=$frame->parentArg;
+break;
+}
+}
+function createParserString() {
+return new java_ParserString();
+}
+function writeArg($arg) {
+if(is_string($arg)) {
+$this->protocol->writeString($arg);
+} else if(is_object($arg)) {
+if ((!$arg instanceof java_JavaType)) {
+error_log((string)new java_IllegalArgumentException($arg));
+trigger_error("argument '".get_class($arg)."' is not a Java object,using NULL instead",E_USER_WARNING);
+$this->protocol->writeObject(null);
+} else {
+$this->protocol->writeObject($arg->__java);
+}
+} else if(is_null($arg)) {
+$this->protocol->writeObject(null);
+} else if(is_bool($arg)) {
+$this->protocol->writeBoolean($arg);
+} else if(is_integer($arg)) {
+$this->protocol->writeLong($arg);
+} else if(is_float($arg)) {
+$this->protocol->writeDouble($arg);
+} else if(is_array($arg)) {
+$wrote_begin=false;
+foreach($arg as $key=>$val) {
+if(is_string($key)) {
+if(!$wrote_begin) {
+$wrote_begin=1;
+$this->protocol->writeCompositeBegin_h();
+}
+$this->protocol->writePairBegin_s($key);
+$this->writeArg($val);
+$this->protocol->writePairEnd();
+} else {
+if(!$wrote_begin) {
+$wrote_begin=1;
+$this->protocol->writeCompositeBegin_h();
+}
+$this->protocol->writePairBegin_n($key);
+$this->writeArg($val);
+$this->protocol->writePairEnd();
+}
+}
+if(!$wrote_begin) {
+$this->protocol->writeCompositeBegin_a();
+}
+$this->protocol->writeCompositeEnd();
+}
+}
+function writeArgs($args) {
+$this->inArgs=true;
+$n=count($args);
+for($i=0; $i<$n; $i++) {
+$this->writeArg($args[$i]);
+}
+$this->inArgs=false;
+}
+function createObject($name,$args) {
+$this->protocol->createObjectBegin($name);
+$this->writeArgs($args);
+$this->protocol->createObjectEnd();
+$val=$this->getInternalResult();
+return $val;
+}
+function referenceObject($name,$args) {
+$this->protocol->referenceBegin($name);
+$this->writeArgs($args);
+$this->protocol->referenceEnd();
+$val=$this->getInternalResult();
+return $val;
+}
+function getProperty($object,$property) {
+$this->protocol->propertyAccessBegin($object,$property);
+$this->protocol->propertyAccessEnd();
+return $this->getResult();
+}
+function setProperty($object,$property,$arg) {
+$this->protocol->propertyAccessBegin($object,$property);
+$this->writeArg($arg);
+$this->protocol->propertyAccessEnd();
+$this->getResult();
+}
+function invokeMethod($object,$method,$args) {
+$this->protocol->invokeBegin($object,$method);
+$this->writeArgs($args);
+$this->protocol->invokeEnd();
+$val=$this->getResult();
+return $val;
+}
+function unref($object) {
+if (isset($this->protocol)) $this->protocol->writeUnref($object);
+}
+function apply($arg) {
+$name=$arg->p;
+$object=$arg->v;
+$ob=($object==null) ? $name : array(&$object,$name);
+$isAsync=$this->isAsync;
+$methodCache=$this->methodCache;
+$currentArgumentsFormat=$this->currentArgumentsFormat;
+try {
+$res=$arg->getResult(true);
+if((($object==null) && !function_exists($name)) || (!($object==null) && !method_exists($object,$name))) throw new JavaException("java.lang.NoSuchMethodError","$name");
+$res=call_user_func_array($ob,$res);
+if (is_object($res) && (!($res instanceof java_JavaType))) {
+trigger_error("object returned from $name() is not a Java object",E_USER_WARNING);
+$this->protocol->invokeBegin(0,"makeClosure");
+$this->protocol->writeULong($this->globalRef->add($res));
+$this->protocol->invokeEnd();
+$res=$this->getResult();
+}
+$this->protocol->resultBegin();
+$this->writeArg($res);
+$this->protocol->resultEnd();
+} catch (JavaException $e) {
+$trace=$e->getTraceAsString();
+$this->protocol->resultBegin();
+$this->protocol->writeException($e->__java,$trace);
+$this->protocol->resultEnd();
+} catch(Exception $ex) {
+error_log($ex->__toString());
+trigger_error("Unchecked exception detected in callback",E_USER_ERROR);
+die (1);
+}
+$this->isAsync=$isAsync;
+$this->methodCache=$methodCache;
+$this->currentArgumentsFormat=$currentArgumentsFormat;
+}
+function cast($object,$type) {
+switch($type[0]) {
+case 'S': case 's':
+return $this->invokeMethod(0,"castToString",array($object));
+case 'B': case 'b':
+return $this->invokeMethod(0,"castToBoolean",array($object));
+case 'L': case 'I': case 'l': case 'i':
+return $this->invokeMethod(0,"castToExact",array($object));
+case 'D': case 'd': case 'F': case 'f':
+return $this->invokeMethod(0,"castToInExact",array($object));
+case 'N': case 'n':
+return null;
+case 'A': case 'a':
+return $this->invokeMethod(0,"castToArray",array($object));
+case 'O': case 'o':
+return $object;
+default:
+throw new java_RuntimeException("$type illegal");
+}
+}
+function getContext() {
+static $cache=null;
+if (!is_null($cache)) return $cache;
+return $cache=$this->invokeMethod(0,"getContext",array());
+}
+function getSession($args) {
+return $this->invokeMethod(0,"getSession",$args);
+}
+function getServerName() {
+static $cache=null;
+if (!is_null($cache)) return $cache;
+return $cache=$this->protocol->getServerName();
+}
+}
+function java_shutdown() {
+global $java_initialized;
+if (!$java_initialized) return;
+if (session_id()) session_write_close();
+$client=__javaproxy_Client_getClient();
+if (!isset($client->protocol) || $client->inArgs) return;
+if ($client->preparedToSendBuffer)
+$client->sendBuffer.=$client->preparedToSendBuffer;
+$client->sendBuffer.=$client->protocol->getKeepAlive();
+$client->protocol->flush();
+$client->protocol->keepAlive();
+}
+register_shutdown_function("java_shutdown");
+class java_GlobalRef {
+public $map;
+function java_GlobalRef() {
+$this->map=array();
+}
+function add($object) {
+if(is_null($object)) return 0;
+return array_push($this->map,$object);
+}
+function get($id) {
+if(!$id) return 0;
+return $this->map[--$id];
+}
+}
+class java_NativeParser {
+public $parser,$handler;
+public $level,$event;
+public $buf;
+function java_NativeParser($handler) {
+$this->handler=$handler;
+$this->parser=xml_parser_create();
+xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0);
+xml_set_object($this->parser,$this);
+xml_set_element_handler($this->parser,"begin","end");
+xml_parse($this->parser,"";
+$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT)));
+}
+function writeBoolean($boolean) {
+$this->client->currentArgumentsFormat.=$format="
\n";
- }
- echo "
\n";
-
- /* create a PHP class which implements the Java toString() method */
- class MyClass {
- function toString() { return "hello PHP from Java!"; }
- }
-
- /* create a Java object from the PHP object */
- $javaObject = java_closure(new MyClass());
- echo "PHP says that Java says: "; echo $javaObject; echo "
\n";
- echo "
\n";
-
-
- echo java("php.java.bridge.Util")->VERSION; echo "
\n";
-
-} catch (JavaException $ex) {
- echo "An exception occured: "; echo $ex; echo "
\n";
-}
-
-?>
diff --git a/tests.jsr223/test/Utf8.java b/tests.jsr223/test/Utf8.java
deleted file mode 100644
index 70cda09..0000000
--- a/tests.jsr223/test/Utf8.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-*- mode: Java; tab-width:8 -*-*/
-
-package test;
-
-import java.io.StringReader;
-
-import javax.script.Invocable;
-import javax.script.ScriptException;
-
-import php.java.script.InvocablePhpScriptEngine;
-import php.java.script.PhpScriptEngine;
-
-/**
- * @author jostb
- *
- * Call this example with -Dfile.encoding=UTF-8
- */
-public class Utf8 {
-
- public static void main(String[] args) throws ScriptException, NoSuchMethodException {
- int result = 0;
-
- System.setProperty("php.java.bridge.default_log_level", "4");
- System.setProperty("php.java.bridge.default_log_file", "");
- System.setProperty("php.java.bridge.php_exec", "php-cgi");
-
- String utf8 =
- "Cześć! -- שלום -- Grüß Gott -- Dobrý deň -- Dobrý den -- こんにちは, コンニチハ";
-
- String phpCode =
- "call(java_closure()); \n"+
- "?>";
-
- InvocablePhpScriptEngine engine = new InvocablePhpScriptEngine();
- StringReader reader = new StringReader(phpCode);
- engine.eval(reader);
-
- Invocable i = (Invocable)engine;
- String utf82 = i.getInterface(null).toString();
-
- if(!utf82.equals(utf8)) {
- System.out.println("ERROR");
- System.out.println(utf82);
- System.out.println(utf8);
- result = 1;
- } else {
- System.out.println("test okay");
- }
-
- engine.release();
- System.exit(result);
- }
-}