Skip to content

Commit

Permalink
Qgisproxy fix in reading XML and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
uprel committed Dec 4, 2018
1 parent 1964285 commit 20e68e2
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions admin/qgisproxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function doGetRequest($query_arr, $map, $client, $http_ver, $user)
break;
case "DescribeFeatureType":
$layer = $query_arr["TYPENAME"];
if (file_exists(PROJECT_PATH.'_data_definitions/'.$layer.'.xml')) {
if (is_readable(PROJECT_PATH.'_data_definitions/'.$layer.'.xml')) {
$content = file_get_contents(PROJECT_PATH.'_data_definitions/'.$layer.'.xml');
}
$contentType = "text/xml";
Expand Down Expand Up @@ -201,24 +201,27 @@ function doGetRequest($query_arr, $map, $client, $http_ver, $user)
}
}

}

if ($content == null) {
$response = $client->send($new_request, [
'query' => $query_arr,
'http_errors' => true,
//request without SSL verification, read this http://docs.guzzlephp.org/en/latest/request-options.html#verify-option
'verify' => false
]);
$contentType = $response->getHeaderLine('Content-Type');
$contentLength = $response->getHeaderLine('Content-Length');
$content = $response->getBody()->__toString();

//check GetProjectSettings XML
if ($query_arr["REQUEST"] == "GetProjectSettings") {
if ($content == null) {
$response = $client->send($new_request, [
'query' => $query_arr,
'http_errors' => true,
//request without SSL verification, read this http://docs.guzzlephp.org/en/latest/request-options.html#verify-option
'verify' => false
]);
$contentType = $response->getHeaderLine('Content-Type');
$contentLength = $response->getHeaderLine('Content-Length');
$content = $response->getBody()->__toString();
$code = $response->getStatusCode();

if($code == 200) {
//check GetProjectSettings XML
if ($query_arr["REQUEST"] == "GetProjectSettings") {
$contentXml = simplexml_load_string($content);
if ($contentXml !== false) {
if ($contentXml->getName() !== 'WMS_Capabilities') {
$m = "Unknown GetCapabilities error";
$m = "Unknown error";
if ($contentXml->ServiceException !== null) {
$m = (string)$contentXml->ServiceException;
}
Expand All @@ -228,26 +231,12 @@ function doGetRequest($query_arr, $map, $client, $http_ver, $user)
throw new Exception\ServerException($content, $new_request);
}
}
if ($response->getStatusCode() == 200) {
$cache->set($cacheKey, $content);
} else {
throw new Exception\ServerException($content, $new_request);
}
} else {
throw new Exception\ServerException($content, $new_request);
}
} else {

if ($content == null) {
//no caching request
$response = $client->send($new_request, [
'query' => $query_arr,
'http_errors' => true,
//request without SSL verification, read this http://docs.guzzlephp.org/en/latest/request-options.html#verify-option
'verify' => false
]);

$contentType = $response->getHeaderLine('Content-Type');
$contentLength = $response->getHeaderLine('Content-Length');
$content = $response->getBody();
if($useCache === TRUE) {
$cache->set($cacheKey, $content);
}
}

Expand Down

0 comments on commit 20e68e2

Please sign in to comment.