Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(\util\cmd\ParamString $args)
 {
     $url = new \peer\URL($args->value(0));
     // If protocol string does not contain port number, set default.
     if (self::ESDL_PORT === $url->getPort(self::ESDL_PORT)) {
         $url->setPort(self::ESDL_PORT);
     }
     // Check given URL to inform user if invalid port used.
     if (self::ESDL_PORT !== $url->getPort()) {
         \util\cmd\Console::$err->writeLine('Notice: using non-standard port ' . $url->getPort() . ', ESDL services are usually available at port 6449.');
     }
     $this->remote = Remote::forName($url->getURL());
     $this->jndi = $args->value(1);
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5') . '.xsl'));
 }
 /**
  * Extract a ".ar" file into a given target directory
  *
  * @param   string base
  * @param   string ar
  * @param   io.Folder target
  * @throws  lang.IllegalStateException in case the target is not found
  * @throws  lang.FormatException in case the .ar-file is not parseable
  */
 protected function extract($base, $ar, Folder $target)
 {
     // Open a HTTP connection
     $url = new \peer\URL($base . $ar . '.ar');
     $r = create(new HttpConnection($url))->get();
     if (\peer\http\HttpConstants::STATUS_OK != $r->getStatusCode()) {
         throw new \lang\IllegalStateException(sprintf('Unexpected response %d:%s for %s', $r->getStatusCode(), $r->getMessage(), $url->getURL()));
     }
     $in = new BufferedInputStream($r->getInputStream());
     do {
         // Seach for first section header, --[LENGTH]:[FILENAME]-- and parse it
         do {
             $line = $this->readLine($in);
             if (!$in->available()) {
                 throw new \lang\FormatException('Cannot locate section header');
             }
         } while (2 !== sscanf($line, '--%d:%[^:]--', $length, $filename));
         // Calculate target file
         $file = new File($target, $filename);
         $folder = new Folder($file->getPath());
         $folder->exists() || $folder->create();
         \util\cmd\Console::writef('     >> [%-10s] %s (%.2f kB) [%s]%s', $ar, $filename, $length / 1024, str_repeat('.', self::PROGRESS_INDICATOR_WIDTH), str_repeat("", self::PROGRESS_INDICATOR_WIDTH + 1));
         // Transfer length bytes into file
         $c = 0;
         $out = $file->getOutputStream();
         $size = 0;
         while ($size < $length) {
             $chunk = $in->read(min(0x1000, $length - $size));
             $size += strlen($chunk);
             $out->write($chunk);
             // Update progress
             $d = ceil($size / $length * self::PROGRESS_INDICATOR_WIDTH);
             if ($d == $c) {
                 continue;
             }
             \util\cmd\Console::write(str_repeat('#', $d - $c));
             $c = $d;
         }
         $out->close();
         \util\cmd\Console::writeLine();
     } while ($in->available() > 0);
     $in->close();
 }
 public function doCreate()
 {
     $req = $this->newRequest('GET', new \peer\URL('http://localhost/'));
     $res = new \scriptlet\HttpScriptletResponse();
     $s = newinstance('scriptlet.xml.XMLScriptlet', array(), '{
   public function needsSession($request) { return TRUE; }
 }');
     $s->service($req, $res);
     $this->assertEquals(\peer\http\HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new \peer\URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals(sprintf('/xml/psessionid=%s/static', session_id()), $redirect->getPath());
     $this->assertEquals(array(), $redirect->getParams(), $redirect->getURL());
 }
 public function createSession()
 {
     $this->newRequest('GET', new \peer\URL('http://localhost/'));
     $s = newinstance('scriptlet.HttpScriptlet', array(), '{
   public function needsSession($request) { return TRUE; }
 }');
     $response = $s->process();
     $this->assertEquals(\peer\http\HttpConstants::STATUS_FOUND, $response->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new \peer\URL(substr($response->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals('/', $redirect->getPath());
     $this->assertEquals(session_id(), $redirect->getParam('psessionid', ''), $redirect->getURL());
 }