public function createChannel() { $channelName = java_getHeader("X_JAVABRIDGE_REDIRECT", $_SERVER); $context = java_getHeader("X_JAVABRIDGE_CONTEXT", $_SERVER); $len = strlen($context); $len0 = java_getCompatibilityOption($this->protocol->client); $len1 = chr($len & 0xff); $len >>= 8; $len2 = chr($len & 0xff); $this->channel = new EmptyChannel($this); $this->channel = $this->getChannel($channelName); $this->protocol->setSocketHandler(new SocketHandler($this->protocol, $this->channel)); $this->protocol->write("{$len0}{$len1}{$len2}{$context}"); $this->context = sprintf("X_JAVABRIDGE_CONTEXT: %s\r\n", $context); $this->protocol->handler = $this->protocol->getSocketHandler(); $this->protocol->handler->write($this->protocol->client->sendBuffer) or $this->protocol->handler->shutdownBrokenConnection("Broken local connection handle"); $this->protocol->client->sendBuffer = null; $this->protocol->handler->read(1) or $this->protocol->handler->shutdownBrokenConnection("Broken local connection handle"); }
/** * * @param string $name * @param boolean $again * @return \Soluble\Japha\Bridge\Driver\Pjb621\SocketHandler * @throws Exception\ConnectException * @throws Exception\IOException */ public function createSimpleHandler($name, $again = true) { $channelName = $name; $errno = null; $errstr = null; if (is_numeric($channelName)) { $peer = @pfsockopen($host = "127.0.0.1", $channelName, $errno, $errstr, 5); } else { $type = $channelName[0]; list($host, $channelName) = explode(":", $channelName); $peer = pfsockopen($host, $channelName, $errno, $errstr, 20); if (!$peer) { throw new Exception\ConnectException("No Java server at {$host}:{$channelName}. Error message: {$errstr} ({$errno})"); } } if (!$peer) { $java = file_exists(ini_get("extension_dir") . "/JavaBridge.jar") ? ini_get("extension_dir") . "/JavaBridge.jar" : java_get_base() . "/JavaBridge.jar"; if (!file_exists($java)) { throw new Exception\IOException("Could not find {$java} in " . getcwd() . ". Download it from http://sf.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_" . JAVA_PEAR_VERSION . "/exploded/JavaBridge.jar/download and try again."); } $java_cmd = "java -Dphp.java.bridge.daemon=true -jar \"{$java}\" INET_LOCAL:{$channelName} 0"; if (!$again) { throw new Exception\ConnectException("No Java back end! Please run it with: {$java_cmd}. Error message: {$errstr} ({$errno})"); } if (!java_checkCliSapi()) { trigger_error("This PHP SAPI requires a JEE or SERVLET back end. Start it,define ('JAVA_SERVLET',true); define('JAVA_HOSTS',...); and try again.", E_USER_ERROR); } system($java_cmd); return $this->createSimpleHandler($name, false); } stream_set_timeout($peer, -1); $handler = new SocketHandler($this, new SocketChannelP($peer, $host)); $compatibility = java_getCompatibilityOption($this->client); $this->write("{$compatibility}"); $this->serverName = "127.0.0.1:{$channelName}"; return $handler; }
public function write($data) { $compat = java_getCompatibilityOption($this->protocol->client); $this->headers = null; $socket = $this->socket; $webapp = $this->getWebApp(); $cookies = $this->getCookies(); $context = $this->getContext(); $res = "PUT "; $res .= $webapp; $res .= " HTTP/1.1\r\n"; $res .= "Host: {$this->host}:{$this->port}\r\n"; $res .= $context; $res .= $cookies; $res .= $this->getBodyFor($compat, $data); $count = fwrite($socket, $res) or $this->shutdownBrokenConnection("Broken connection handle"); fflush($socket) or $this->shutdownBrokenConnection("Broken connection handle"); return $count; }