Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Jaspersoft/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class Client
{
private $restReq;
private $restUrl2;
protected $hostname;
protected $username;
protected $password;
protected $orgId;
private $serverUrl;
protected $hostname;
protected $username;
protected $password;
protected $orgId;
protected $repositoryService;
protected $userService;
protected $organizationService;
Expand All @@ -35,20 +36,23 @@ class Client
protected $thumbnailService;
protected $logCollectorService;
protected $serverService;
protected $options;

public function __construct($serverUrl, $username, $password, $orgId = null)
public function __construct($serverUrl, $username, $password, $orgId = null, $options = array())
{
$this->serverUrl = $serverUrl;
$this->username = $username;
$this->password = $password;
$this->orgId = $orgId;
$this->options = $options;

$this->restReq = new RESTRequest();
if (!empty($this->orgId)) {
$this->restReq->setUsername($this->username .'|'. $this->orgId);
} else {
$this->restReq->setUsername($this->username);
}
$this->restReq->setOptions($this->options);
$this->restReq->setPassword($this->password);
$this->restUrl2 = $this->serverUrl . BASE_REST2_URL;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Jaspersoft/Service/RepositoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public function updateFileResource(File $resource, $binaryData)
$url = self::makeUrl(null, $resource->uri);

$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'PUT');
$response = $this->service->sendBinary($url, $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'PUT', array(201, 200));

return File::createFromJSON(json_decode($response, true), get_class($resource));

}
Expand All @@ -198,7 +199,7 @@ public function createFileResource(File $resource, $binaryData, $parentFolder, $

$url .= '?' . Util::query_suffix(array("createFolders" => $createFolders));
$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'POST');
$response = $this->service->sendBinary($url, $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'POST', array(201, 200));
return File::createFromJSON(json_decode($response, true), get_class($resource));
}

Expand Down
54 changes: 41 additions & 13 deletions src/Jaspersoft/Tool/RESTRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
class RESTRequest
{

protected $url;
protected $verb;
protected $request_body;
protected $request_length;
protected $username;
protected $password;
protected $accept_type;
protected $content_type;
protected $response_body;
protected $response_info;
protected $file_to_upload = array();
protected $url;
protected $verb;
protected $request_body;
protected $request_length;
protected $username;
protected $password;
protected $accept_type;
protected $content_type;
protected $response_body;
protected $response_headers;
protected $response_info;
protected $file_to_upload = array();
protected $headers;
protected $curl_timeout;
protected $curl_handle;
protected $curl_cookiejar;
protected $options;

public function __construct ($url = null, $verb = 'GET', $request_body = null)
public function __construct ($url = null, $verb = 'GET', $request_body = null, $options = array())
{
$this->url = $url;
$this->verb = $verb;
Expand All @@ -37,6 +40,7 @@ public function __construct ($url = null, $verb = 'GET', $request_body = null)
$this->curl_timeout = 30;
$this->curl_handle = curl_init();
$this->curl_cookiejar = null;
$this->options = $options;

if ($this->request_body !== null)
{
Expand Down Expand Up @@ -276,6 +280,9 @@ protected function doExecute (&$curlHandle)

protected function setCurlOpts (&$curlHandle)
{
$ssl_verifypeer = $this->getOptionValue('ssl_verifypeer',true);
$ssl_cainfo = $this->getOptionValue('ssl_cainfo','');

curl_setopt($curlHandle, CURLOPT_URL, $this->url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_HEADER, true);
Expand All @@ -286,6 +293,10 @@ protected function setCurlOpts (&$curlHandle)
$this->headers[] = "Accept: " . $this->accept_type;
if (!empty($this->headers))
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->headers);
if (!empty($ssl_cainfo))
curl_setopt($curlHandle, CURLOPT_CAINFO, $ssl_cainfo);
if (!$ssl_verifypeer)
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
}

protected function setAuth (&$curlHandle)
Expand Down Expand Up @@ -336,6 +347,23 @@ public function setContentType ($content_type)
{
$this->content_type = $content_type;
}
public function getOptions ()
{
return $this->options;
}
public function setOptions ($options = array())
{
$this->options = $options;
}
protected function getOptionValue($option_name, $default_value = null)
{
$option_value = $default_value;
if (is_array($this->options) && array_key_exists($option_name, $this->options))
{
$option_value = $this->options[$option_name];
}
return $option_value;
}
public function getPassword ()
{
return $this->password;
Expand Down Expand Up @@ -519,7 +547,7 @@ public function multipartRequestSend($url, $expectedCode = 200, $verb = 'PUT_MP'
}


public function sendBinary($url, $expectedCodes = array(200), $body, $contentType, $contentDisposition, $contentDescription, $verb = "POST")
public function sendBinary($url, $body, $contentType, $contentDisposition, $contentDescription, $verb = "POST", $expectedCodes = array(200))
{
$this->flush();
$this->setUrl($url);
Expand Down
2 changes: 1 addition & 1 deletion src/Jaspersoft/Tool/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function query_suffix($params)
$params[$k] = ($v) ? 'true' : 'false';
}
}
$url = http_build_query($params, null, '&');
$url = http_build_query($params, '', '&');
return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $url);
}

Expand Down