/**
  * Create client by inspecting the URL
  * 
  * @param string url The API url
  * @return com.atlassian.jira.api.JiraClientProtocol
  */
 public static function forURL($url)
 {
     $u = new URL($url);
     if (strstr($u->getPath(), '/rest/api/2')) {
         return XPClass::forName('com.atlassian.jira.api.protocol.JiraClientRest2Protocol')->newInstance($u);
     } else {
         throw new IllegalArgumentException('No suitable client found for ' . $url);
     }
 }
Beispiel #2
0
 /**
  * Setup the class instance. A dsn string must be given with the relevant information
  * about the server and script:
  *
  * Eg: nagios://nagios.xp_framework.net:5667/service_to_monitor
  *
  * @param   string dsn
  */
 public function setup($dsn)
 {
     $url = new URL($dsn);
     $this->server = $url->getHost();
     $this->port = $url->getPort(5667);
     $this->version = $url->getParam('version', NscaProtocol::VERSION_2);
     $this->service = trim($url->getPath(), '/');
     $this->host = $url->getParam('hostname', System::getProperty('host.name'));
     if (false !== $url->getParam('domain', false)) {
         $this->host .= '.' . ltrim($url->getParam('domain'), '.');
     }
 }
 /**
  * Creates a new request object. Uses the system environment and global
  * variables to put necessary parameters into place.
  *
  * @param   string method
  * @param   peer.URL url
  */
 protected function newRequest($method, \peer\URL $url)
 {
     $q = $url->getQuery();
     $_SERVER['REQUEST_METHOD'] = $method;
     $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
     $_SERVER['HTTP_HOST'] = $url->getHost();
     $_SERVER['REQUEST_URI'] = $url->getPath('/') . ($q ? '?' . $q : '');
     $_SERVER['QUERY_STRING'] = $q;
     if ('https' === $url->getScheme()) {
         $_SERVER['HTTPS'] = 'on';
     }
     $_REQUEST = $url->getParams();
 }
 /**
  * Creates a new request object
  *
  * @param   string method
  * @param   peer.URL url
  * @return  scriptlet.HttpScriptletRequest
  */
 protected function newRequest($method, URL $url)
 {
     $q = $url->getQuery('');
     $req = new \scriptlet\HttpScriptletRequest();
     $req->method = $method;
     $req->env['SERVER_PROTOCOL'] = 'HTTP/1.1';
     $req->env['REQUEST_URI'] = $url->getPath('/') . ($q ? '?' . $q : '');
     $req->env['QUERY_STRING'] = $q;
     $req->env['HTTP_HOST'] = $url->getHost();
     if ('https' === $url->getScheme()) {
         $req->env['HTTPS'] = 'on';
     }
     $req->setHeaders(array());
     $req->setParams($url->getParams());
     return $req;
 }
 public function atInUserAndPath()
 {
     $u = new URL('http://user@localhost/@');
     $this->assertEquals('user', $u->getUser());
     $this->assertEquals('/@', $u->getPath());
 }
 public function doCreate()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/'));
     $res = new \scriptlet\HttpScriptletResponse();
     $s = newinstance('scriptlet.xml.XMLScriptlet', [], '{
   public function needsSession($request) { return true; }
 }');
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new 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([], $redirect->getParams(), $redirect->getURL());
 }
 public function handleSessionInitializationError()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/?psessionid=MALFORMED'));
     $res = new HttpScriptletResponse();
     $s = newinstance('scriptlet.HttpScriptlet', [], ['needsSession' => function ($request) {
         return true;
     }, 'handleSessionInitialization' => function ($request) {
         if (!preg_match('/^a-f0-9$/', $request->getSessionId())) {
             throw new IllegalArgumentException('Invalid characters in session id');
         }
         parent::handleSessionInitialization($request);
     }, 'handleSessionInitializationError' => function ($request, $response) {
         $request->getURL()->addParam('relogin', 1);
         return $request->session->initialize(null);
     }]);
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->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'));
     $this->assertEquals('1', $redirect->getParam('relogin'));
 }
 /**
  * Send proxy request
  *
  * @param  peer.Socket $s Connection to proxy
  * @param  peer.http.HttpRequest $request
  * @param  peer.URL $url
  */
 protected function proxy($s, $request, $url)
 {
     $request->setTarget(sprintf('%s://%s%s%s', $url->getScheme(), $url->getHost(), $url->getPort() ? ':' . $url->getPort() : '', $url->getPath('/')));
 }