Beispiel #1
0
def handler(req):

    inputQuery = None
    if req.method == "GET":
        inputQuery = req.args
    else:
        inputQuery = req

    if not inputQuery:
        err = NoApplicableCode("No query string found.")
        pywps.response.response(err, req)
        return apache.OK

    # set PYWPS_CFG and PYWPS_PROCESSES environment variable, which can not
    # bee seen from mod_python
    env_vars = req.subprocess_env.copy()
    if env_vars.has_key("PYWPS_CFG"):
        os.environ["PYWPS_CFG"] = env_vars["PYWPS_CFG"]
    if env_vars.has_key("PYWPS_PROCESSES"):
        os.environ["PYWPS_PROCESSES"] = env_vars["PYWPS_PROCESSES"]

    # create the WPS object
    try:
        wps = pywps.Pywps(req.method)
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest()
            pywps.response.response(wps.response, req, wps.parser.isSoap, contentType=wps.request.contentType)
            return apache.OK
    except WPSException, e:
        pywps.response.response(e, req)
        return apache.OK
Beispiel #2
0
def application(environ, start_response):

    status = '200 OK'
    response_headers = [('Content-type', 'text/xml')]
    start_response(status, response_headers)

    inputQuery = None
    if "REQUEST_METHOD" in environ and environ["REQUEST_METHOD"] == "GET":
        inputQuery = environ["QUERY_STRING"]
    elif "wsgi.input" in environ:
        inputQuery = environ['wsgi.input']

    if not inputQuery:
        err = NoApplicableCode("No query string found.")
        return [err.getResponse()]

    # create the WPS object
    try:
        wps = pywps.Pywps(environ)
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest()
            return wps.response
    except WPSException, e:
        return [e]
Beispiel #3
0
def dispatchWps(environ, start_response):

    status = '200 OK'
    response_headers = [('Content-type','text/xml')]
    start_response(status, response_headers)

    inputQuery = None
    if "REQUEST_METHOD" in environ and environ["REQUEST_METHOD"] == "GET":
        inputQuery = environ["QUERY_STRING"]
    elif "wsgi.input" in environ:
        inputQuery = environ['wsgi.input']

    if not inputQuery:
        err =  NoApplicableCode("No query string found.")
        return [err.getResponse()]


    # create the WPS object
    try:
        wps = pywps.Pywps(environ["REQUEST_METHOD"])
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest()
            return wps.response
    except WPSException,e:
        return [e]
Beispiel #4
0
def application(environ, start_response):

    status = '200 OK'
    response_headers = [('Content-type', 'text/xml')]

    inputQuery = None
    if environ.get("REQUEST_METHOD", '') == "GET":
        inputQuery = environ.get("QUERY_STRING")
    elif "wsgi.input" in environ:
        inputQuery = environ.get('wsgi.input')

    response = ''
    try:
        if not inputQuery:
            raise NoApplicableCode("No query string found.")

        # create the WPS object
        wps = pywps.Pywps(environ["REQUEST_METHOD"], environ.get("PYWPS_CFG"))
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest(processes=environ.get("PYWPS_PROCESSES"))
            response_headers = [('Content-type', wps.request.contentType)]
            response = wps.response

    except WPSException, e:
        response = str(e)
Beispiel #5
0
def index():
    #start_response(status, response_headers)


    response_headers = [('Content-type','text/xml')]
    inputQuery = None
    if request.method == 'GET':
        inputQuery = str(request.args)
        print inputQuery
    elif request.method == 'POST':
        #inputQuery = environ['wsgi.input']
        inputQuery = request.args
    

    if not request.args:
        print pywps.Exceptions
        err =  pywps.Exceptions.NoApplicableCode("No query string found.")
        resp = make_response(err, 200)
        resp.headers['mime-type'] = 'text/xml'
        resp.headers['content-type'] = 'text/xml'
        return [err.getResponse()]

    # create the WPS object
    try:
        #resp = make_response(err, 200)
        #resp.headers['mime-type'] = 'text/xml'
        #resp.headers['content-type'] = 'text/xml'
        wps = pywps.Pywps(request.method)
        #if wps.parseRequest(inputQuery):
        pywps.debug(inputQuery)
        wps.performRequest()
        return wps.response
    except WPSException,e:
        return [e]
Beispiel #6
0
def handler(req):

    inputQuery = None
    if req.method == "GET":
        inputQuery = req.args
    else:
        inputQuery = req

    if not inputQuery:
        err =  NoApplicableCode("No query string found.")
        pywps.response.response(err,req)
        return apache.OK

    # set PYWPS_CFG and PYWPS_PROCESSES environment variable, which can not
    # bee seen from mod_python
    env_vars = req.subprocess_env.copy()
    if env_vars.has_key("PYWPS_CFG"):
        os.environ["PYWPS_CFG"] = env_vars["PYWPS_CFG"]
    if env_vars.has_key("PYWPS_PROCESSES"):
        os.environ["PYWPS_PROCESSES"] = env_vars["PYWPS_PROCESSES"]

    # create the WPS object
    try:
        wps = pywps.Pywps(req.method)
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest()
            pywps.response.response(wps.response, req,
                    wps.parser.isSoap, self.wps.parser.isSoapExecute,contentType = wps.request.contentType)
            return apache.OK
    except WPSException,e:
        pywps.response.response(e, req) 
        return apache.OK
Beispiel #7
0
def index():
    #start_response(status, response_headers)

    response_headers = [('Content-type', 'text/xml')]
    inputQuery = None
    if request.method == 'GET':
        inputQuery = str(request.args)
        print inputQuery
    elif request.method == 'POST':
        #inputQuery = environ['wsgi.input']
        inputQuery = request.args

    if not request.args:
        print pywps.Exceptions
        err = pywps.Exceptions.NoApplicableCode("No query string found.")
        resp = make_response(err, 200)
        resp.headers['mime-type'] = 'text/xml'
        resp.headers['content-type'] = 'text/xml'
        return [err.getResponse()]

    # create the WPS object
    try:
        #resp = make_response(err, 200)
        #resp.headers['mime-type'] = 'text/xml'
        #resp.headers['content-type'] = 'text/xml'
        wps = pywps.Pywps(request.method)
        #if wps.parseRequest(inputQuery):
        pywps.debug(inputQuery)
        wps.performRequest()
        return wps.response
    except WPSException, e:
        return [e]
Beispiel #8
0
def application(environ, start_response):

    status = '200 OK'
    response_headers = [('Content-type', 'text/xml')]

    inputQuery = None
    if environ.get("REQUEST_METHOD", '') == "GET":
        inputQuery = environ.get("QUERY_STRING")
    elif "wsgi.input" in environ:
        inputQuery = environ.get('wsgi.input')

    response = ''
    try:
        if not inputQuery:
            raise NoApplicableCode("No query string found.")

        # create the WPS object
        wps = pywps.Pywps(environ["REQUEST_METHOD"], environ.get("PYWPS_CFG"))
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest(processes=environ.get("PYWPS_PROCESSES"))
            response_headers = [('Content-type', wps.request.contentType)]
            response = wps.response

    except WPSException, e:
        response = str(e)
Beispiel #9
0
def index(request):
    """
    WPS endpoint.

    This view relays the HTTP request to PyWPS, captures its response and then
    sends it back to the web server. It is inspired by the wps.py file which is
    present in PyWPS source code repository.
    """

    to_return = None
    input_query = request.META["QUERY_STRING"]
    default_content_type = "application/xml"
    content_type = default_content_type
    if request.method == pywps.METHOD_GET and input_query == "":
        error = NoApplicableCode("No query string found")
        to_return = _write_response(str(error))
    elif request.method == pywps.METHOD_GET:
        input_query = request.META["QUERY_STRING"]
    else:
        input_query = request.body
    if to_return is None:
        wps_server = pywps.Pywps(
            method=request.method,
            configFiles=(settings.PYWPS_SETTINGS_FILE,)
        )
        try:
            if wps_server.parseRequest(input_query):
                pywps.debug(wps_server.inputs)
                wps_response = wps_server.performRequest()
                if wps_response:
                    to_return = _write_response(
                        wps_server.response,
                        soap_version=wps_server.parser.soapVersion,
                        is_soap=wps_server.parser.isSoap,
                        is_soap_execute=wps_server.parser.isSoapExecute
                    )
                    content_type = wps_server.request.contentType
        except WPSException as err:
            traceback.print_exc(file=pywps.logFile)
            to_return = _write_response(
                str(err),
                soap_version=wps_server.parser.soapVersion,
                is_soap=wps_server.parser.isSoap,
                is_soap_execute=wps_server.parser.isSoapExecute
            )
            content_type = default_content_type
        finally:
            if hasattr(wps_server.request, "umn"):
                print("Deleting the mapobj attribute of request.umn in "
                      "order to prevent memory leaks...")
                del wps_server.request.umn
    # release mapserver memory in order to avoid leaks when
    # running under wsgi
    mapscript.msCleanup(1)
    return HttpResponse(to_return, content_type=content_type)
Beispiel #10
0
    def doPywps(self,request, response, inputQuery,method):

        # create the WPS object
        try:
            wps = pywps.Pywps(method)
            if wps.parseRequest(inputQuery):
                pywps.debug(wps.inputs)
                wpsresponse = wps.performRequest(processes=[self.getProcesses()])
                if wpsresponse:
                    pywps.response.response(wps.response, response, wps.parser.isSoap,self.wps.parser.isSoapExecute)
        except WPSException,e:
            pywps.response.response(e, response)
Beispiel #11
0
def pywps_view(request):
    """
    * TODO: add xml response renderer
    * TODO: fix exceptions ... use OWSException (raise ...)
    """
    response = request.response
    response.status = "200 OK"
    response.content_type = "text/xml"

    inputQuery = None
    os.environ["REQUEST_METHOD"] = request.method
    if request.method == "GET":
        inputQuery = request.query_string
    elif request.method == "POST":
        inputQuery = request.body_file_raw
    else:
        return HTTPBadRequest()

    if not inputQuery:
        return OWSNoApplicableCode("No query string found.")

    if request.wps_cfg:
        os.environ['PYWPS_CFG'] = request.wps_cfg

    # set the environ for wps from request environ
    for key in request.wps_environ_keys:
        if key in request.environ:
            os.environ[key] = request.environ[key]

    # create the WPS object
    try:
        wps = pywps.Pywps(os.environ["REQUEST_METHOD"], os.environ.get("PYWPS_CFG"))
        if wps.parseRequest(inputQuery):
            pywps.debug(wps.inputs)
            wps.performRequest(processes=os.environ.get("PYWPS_PROCESSES"))
            response_headers = [('Content-type', wps.request.contentType)]
            return wps.response
    except WPSException,e:
        return str(e)
Beispiel #12
0
        # if QUERY_STRING isn't found in env-dictionary, try to read
        # query from command line:
        if len(sys.argv)>1:  # any arguments available?
            inputQuery = sys.argv[1]
    if not inputQuery:
        err =  NoApplicableCode("No query string found.")
        pywps.response.response(err,sys.stdout)
        sys.exit(1)
else:
    inputQuery = sys.stdin

# create the WPS object
wps = None
try:
    wps = pywps.Pywps(method)
    if wps.parseRequest(inputQuery):
        pywps.debug(wps.inputs)
        response = wps.performRequest()
        # request performed, write the response back
        if response:
            # print only to standard out
                pywps.response.response(wps.response,
                    sys.stdout,wps.parser.soapVersion,wps.parser.isSoap,wps.parser.isSoapExecute, wps.request.contentType)
                
except WPSException,e:
    traceback.print_exc(file=pywps.logFile)
    pywps.response.response(e, sys.stdout, wps.parser.soapVersion,
                            wps.parser.isSoap,
                            wps.parser.isSoapExecute)

Beispiel #13
0
    if config.config.has_option('qgis', 'user_folder'):
        user_folder = config.getConfigValue('qgis', 'user_folder')

    # init QgsApplication
    QgsApplication(sys.argv, False, user_folder)
    # supply path to where is your qgis installed
    QgsApplication.setPrefixPath(config.getConfigValue("qgis", "prefix"), True)

    # load providers
    QgsApplication.initQgis()

    # initialize application
    qa = QApplication(sys.argv)
    wps = pywps.Pywps(method)
    if wps.parseRequest(inputQuery):
        pywps.debug(wps.inputs)
        response = wps.performRequest()
        # request performed, write the response back
        if response:
            # print only to standard out
            pywps.response.response(wps.response,
                                    sys.stdout, wps.parser.soapVersion, wps.parser.isSoap, wps.parser.isSoapExecute, wps.request.contentType)
    QgsApplication.exitQgis()
    qa.exit()

except WPSException, e:
    traceback.print_exc(file=pywps.logFile)
    pywps.response.response(e, sys.stdout, wps.parser.soapVersion,
                            wps.parser.isSoap,
                            wps.parser.isSoapExecute)