Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Handle Accept header for JSON/XML response in WPS 2.0 #125

Closed
4 tasks done
fmigneault opened this issue May 7, 2020 · 0 comments · Fixed by #455
Closed
4 tasks done

[Feature] Handle Accept header for JSON/XML response in WPS 2.0 #125

fmigneault opened this issue May 7, 2020 · 0 comments · Fixed by #455
Assignees
Labels
process/wps1 Issue related to WPS 1.x processes support process/wps2 Issue related to WPS 2.x processes support process/wps3 Issue related to WPS 3.x (REST-JSON) processes support

Comments

@fmigneault
Copy link
Collaborator

fmigneault commented May 7, 2020

Context

Given that WPS 2.0 supports JSON response, we should handle a provided Accept=application/json header on the WPS route (eg: /ows/wps by default). By default this route returns XML.
Some code to do the detection of WPS version/format was introduced in f0cd31e but is still unused.
This is now functional

GET /ows/wps?service=wps&request=describeprocess&identifier=jsonarray2netcdf
Accept: application/json
See returned response (proper OGCAPI - Processes content)
{
    "id": "jsonarray2netcdf",
    "title": "JSON array to NetCDF",
    "version": "1.1",
    "description": "Extracts and fetches NetCDF files from a JSON file containing an URL string array, and provides them on the output directory.",
    "keywords": [
        "builtin"
    ],
    "metadata": [],
    "inputs": {
        "input": {
            "title": "input",
            "minOccurs": 1,
            "maxOccurs": 1,
            "formats": [
                {
                    "default": true,
                    "mediaType": "application/json"
                }
            ]
        }
    },
    "outputs": {
        "output": {
            "title": "output",
            "formats": [
                {
                    "default": true,
                    "mediaType": "application/x-netcdf"
                }
            ]
        }
    },
    "visibility": "public",
    "jobControlOptions": [
        "async-execute"
    ],
    "outputTransmission": [
        "reference"
    ],
    "processDescriptionURL": "http://localhost:4002/processes/jsonarray2netcdf",
    "processEndpointWPS1": "http://localhost:4002/ows/wps",
    "executeEndpoint": "http://localhost:4002/processes/jsonarray2netcdf/jobs",
    "links": [
        {
            "type": "application/json",
            "title": "Current process description.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes/jsonarray2netcdf",
            "rel": "self"
        },
        {
            "type": "application/json",
            "title": "Process definition.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes/jsonarray2netcdf",
            "rel": "process-meta"
        },
        {
            "type": "application/json",
            "title": "Process execution endpoint for job submission.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes/jsonarray2netcdf/execution",
            "rel": "http://www.opengis.net/def/rel/ogc/1.0/execute"
        },
        {
            "type": "application/json",
            "title": "List of registered processes.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes",
            "rel": "http://www.opengis.net/def/rel/ogc/1.0/processes"
        },
        {
            "type": "application/json",
            "title": "List of job executions corresponding to this process.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes/jsonarray2netcdf/jobs",
            "rel": "http://www.opengis.net/def/rel/ogc/1.0/job-list"
        },
        {
            "type": "application/json",
            "title": "List of processes registered under the service.",
            "hreflang": "en-CA",
            "href": "http://localhost:4002/processes",
            "rel": "up"
        }
    ]
}

If version is WPS 1.x, the only supported format is XML. This should also be the default return on /ows/wps route if no version=... parameter was provided in the URL.
Default behaviour is to provide the corresponding XML into JSON format, regardless of version:

GET /ows/wps?service=wps&request=describeprocess&identifier=jsonarray2netcdf&f=json
See produced response (JSON PyWPS content)
{
  "pywps_version": "4.5.0",
  "processes": [
    {
      "class": "weaver.processes.wps_package:WpsPackage",
      "uuid": "None",
      "workdir": null,
      "version": "1.1",
      "identifier": "jsonarray2netcdf",
      "title": "JSON array to NetCDF",
      "abstract": "Extracts and fetches NetCDF files from a JSON file containing an URL string array, and provides them on the output directory.",
      "keywords": [
        "builtin"
      ],
      "metadata": [],
      "inputs": [
        {
          "identifier": "input",
          "title": "input",
          "abstract": "",
          "keywords": [],
          "metadata": [],
          "type": "complex",
          "data_format": {
            "mime_type": "application/json",
            "encoding": "",
            "schema": "",
            "extension": ".json"
          },
          "asreference": false,
          "supported_formats": [
            {
              "mime_type": "application/json",
              "encoding": "",
              "schema": "",
              "extension": ".json"
            }
          ],
          "workdir": null,
          "mode": 1,
          "min_occurs": 1,
          "max_occurs": 1,
          "translations": null,
          "mimetype": "application/json"
        }
      ],
      "outputs": [
        {
          "identifier": "output",
          "title": "output",
          "abstract": "",
          "keywords": [],
          "type": "complex",
          "supported_formats": [
            {
              "mime_type": "application/x-netcdf",
              "encoding": "",
              "schema": "",
              "extension": ".nc"
            }
          ],
          "asreference": false,
          "data_format": {
            "mime_type": "application/x-netcdf",
            "encoding": "",
            "schema": "",
            "extension": ".nc"
          },
          "file": null,
          "workdir": null,
          "mode": 1,
          "min_occurs": 1,
          "max_occurs": 1,
          "translations": null,
          "mimetype": "application/x-netcdf"
        }
      ],
      "store_supported": "true",
      "status_supported": "true",
      "profile": [],
      "translations": null
    }
  ],
  "language": "fr-CA"
}

TODO

  • redirect a WPS-REST (3.0) call (eg: /processes, /processes/{id}, etc.) to their corresponding WPS 2.0 /ows/wps request if any from (Accept: application/xml, Accept: text/xml, f=xml, format=xml) is provided (inverse of what is currently functional).
    Use dict2xml (or similar) to provide an XML body corresponding to the original JSON.
  • handle other variation format= as alias of f= on OWS endpoint.
  • convert the PyWPS JSON to an actual (valid) OGC API - Processes representation rather than plain XML->JSON conversion.
  • Employ this tween definition to detect Accept header / format query and raise HTTP 422 if not acceptable :
    https://github.com/Ouranosinc/Magpie/blob/f67a134d52ec8f3951cb1a08a07c1c5beb518882/magpie/api/generic.py#L106-L202
@fmigneault fmigneault added process/wps1 Issue related to WPS 1.x processes support process/wps2 Issue related to WPS 2.x processes support triage/feature New requested feature. process/wps3 Issue related to WPS 3.x (REST-JSON) processes support labels May 7, 2020
@fmigneault fmigneault self-assigned this May 7, 2020
@github-actions github-actions bot removed the triage/feature New requested feature. label May 18, 2020
This was referenced Feb 12, 2021
fmigneault added a commit that referenced this issue Aug 11, 2022
…oint with query format / accept header detection (resolves #125)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process/wps1 Issue related to WPS 1.x processes support process/wps2 Issue related to WPS 2.x processes support process/wps3 Issue related to WPS 3.x (REST-JSON) processes support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant