From de7cc67cf3159976649b12edbc59a113e1185d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Gschwind?= Date: Wed, 7 Feb 2024 14:48:13 +0100 Subject: [PATCH] Implement sub-path for status request --- pywps/app/Process.py | 2 +- pywps/app/Service.py | 73 ++++++++++++++++++++++------------------ tests/test_assync.py | 2 +- tests/test_wps_status.py | 2 +- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/pywps/app/Process.py b/pywps/app/Process.py index a1051133f..e226d6838 100644 --- a/pywps/app/Process.py +++ b/pywps/app/Process.py @@ -184,7 +184,7 @@ def status_filename(self): @property def status_url(self): base_url = config.get_config_value('server', 'url') - return f"{base_url}?service=WPS&request=status&uuid={self.uuid}" + return f"{base_url}/status?uuid={self.uuid}" def _execute_process(self, async_, wps_request, wps_response): """ diff --git a/pywps/app/Service.py b/pywps/app/Service.py index cdd440155..a92273b86 100755 --- a/pywps/app/Service.py +++ b/pywps/app/Service.py @@ -62,13 +62,15 @@ def __init__(self, processes: Sequence = [], cfgfiles=None, preprocessors: Optio if not LOGGER.handlers: LOGGER.addHandler(logging.NullHandler()) - def get_status(self, wps_request, uuid): + def get_status(self, http_request): try: - _, mimetype = get_response_type(wps_request.http_request.accept_mimetypes, - wps_request.default_mimetype) + _, mimetype = get_response_type(http_request.accept_mimetypes, + "text/xml") except Exception: mimetype = get_default_response_mimetype() - return StatusResponse(wps_request.version, wps_request.requested_status_uuid, mimetype) + from urllib.parse import parse_qs + request = parse_qs(http_request.environ["QUERY_STRING"]) + return StatusResponse(request.get("version", ["1.0.0"])[0], request["uuid"][0], mimetype) def get_capabilities(self, wps_request, uuid): return CapabilitiesResponse(wps_request, uuid, version=wps_request.version, processes=self.processes) @@ -168,39 +170,44 @@ def call(self, http_request): LOGGER.debug('Setting PYWPS_CFG to {}'.format(environ_cfg)) os.environ['PYWPS_CFG'] = environ_cfg - wps_request = WPSRequest(http_request, self.preprocessors) - LOGGER.info('Request: {}'.format(wps_request.operation)) - if wps_request.operation in ['getcapabilities', - 'describeprocess', - 'execute', - 'status']: - log_request(request_uuid, wps_request) + if http_request.environ["PATH_INFO"] == "/status": try: - response = None - if wps_request.operation == 'getcapabilities': - response = self.get_capabilities(wps_request, request_uuid) - response._update_status(WPS_STATUS.SUCCEEDED, '', 100) - - elif wps_request.operation == 'describeprocess': - response = self.describe(wps_request, request_uuid, wps_request.identifiers) - response._update_status(WPS_STATUS.SUCCEEDED, '', 100) - - elif wps_request.operation == 'execute': - response = self.execute( - wps_request.identifier, - wps_request, - request_uuid - ) - elif wps_request.operation == 'status': - response = self.get_status(wps_request, request_uuid) - return response + return self.get_status(http_request) except Exception as e: - # This ensure that logged request get terminated in case of exception while the request is not - # accepted - store_status(request_uuid, WPS_STATUS.FAILED, 'Request rejected due to exception', 100) + store_status(request_uuid, WPS_STATUS.FAILED, + 'Request rejected due to exception', 100) raise e else: - raise RuntimeError("Unknown operation {}".format(wps_request.operation)) + wps_request = WPSRequest(http_request, self.preprocessors) + LOGGER.info('Request: {}'.format(wps_request.operation)) + if wps_request.operation in ['getcapabilities', + 'describeprocess', + 'execute']: + log_request(request_uuid, wps_request) + try: + response = None + if wps_request.operation == 'getcapabilities': + response = self.get_capabilities(wps_request, request_uuid) + response._update_status(WPS_STATUS.SUCCEEDED, '', 100) + + elif wps_request.operation == 'describeprocess': + response = self.describe(wps_request, request_uuid, wps_request.identifiers) + response._update_status(WPS_STATUS.SUCCEEDED, '', 100) + + elif wps_request.operation == 'execute': + response = self.execute( + wps_request.identifier, + wps_request, + request_uuid + ) + return response + except Exception as e: + # This ensure that logged request get terminated in case of exception while the request is not + # accepted + store_status(request_uuid, WPS_STATUS.FAILED, 'Request rejected due to exception', 100) + raise e + else: + raise RuntimeError("Unknown operation {}".format(wps_request.operation)) except NoApplicableCode as e: return e diff --git a/tests/test_assync.py b/tests/test_assync.py index 6d23a9d7e..81b817460 100644 --- a/tests/test_assync.py +++ b/tests/test_assync.py @@ -54,7 +54,7 @@ def test_async(self): total_time = 0 sleep_time = .01 while wps.status not in ["ProcessSucceeded", "ProcessFailed"]: - resp = client.get(f'{url.path}?{url.query}').data + resp = client.open(base_url='/wps', path='/status', method='GET', query_string=url.query).data if resp: wps.checkStatus(response=resp, sleepSecs=0.01) else: diff --git a/tests/test_wps_status.py b/tests/test_wps_status.py index 1ed358efd..6bf724e4d 100644 --- a/tests/test_wps_status.py +++ b/tests/test_wps_status.py @@ -52,6 +52,6 @@ def test_wps_status(self): # Parse url because we do not have real server url = urlparse(url) - resp = client.get(f'{url.path}?{url.query}') + resp = client.open(base_url='/wps', path='/status', method='GET', query_string=url.query) assert_response_success(resp)