예제 #1
0
 def do_POST(self, *args, **kwargs):
     create_context(self.server, self.client_address, self.headers)
     try:
         ServiceContainer.SOAPRequestHandler.do_POST(
             self, *args, **kwargs)
     finally:
         delete_context()
예제 #2
0
 def do_POST(self, *args, **kwargs):
     create_context(self.server, self.client_address, self.headers)
     try:
         SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.do_POST(
             self, *args, **kwargs)
     finally:
         delete_context()
예제 #3
0
    def do_GET(self):
        create_context(self.server, self.client_address, self.headers)
        try:
            first_question_mark = self.path.find("?")
            if first_question_mark >= 0:
                path = self.path[0:first_question_mark]
                options = urllib.unquote(self.path[first_question_mark + 1:])
            else:
                path = self.path
                options = ""

            parameters = [
                field for field in options.split("&") if field.find("=") >= 0
            ]

            session_id_param = [
                field[field.find("=") + 1:] for field in parameters
                if field.startswith("sessionid")
            ]
            if len(session_id_param) == 0:
                self._write(400, "sessionid not provided")
                return

            session_id = session_id_param[0]

            last_slash = path.rfind("/")
            if last_slash >= 0:
                method_name = path[last_slash + 1:]
            else:
                method_name = path

            if 'get_%s' % method_name in dir(Methods):
                method = getattr(Methods, 'get_%s' % method_name)
                try:
                    response = method(self, session_id, parameters)
                except MethodError as me:
                    #                    import traceback
                    #                    traceback.print_exc()
                    log.log(self, log.level.Error, str(me))
                    log.log_exc(self, log.level.Warning)
                    self._write(400, "Error: %s" % me)
                    return
                json_response = json.dumps(response)
            else:
                self._write(
                    400,
                    "method %s not implemented" % urllib2.quote(method_name))
                return

            self._write(200, json_response)
        except Exception as e:
            import traceback
            traceback.print_exc()

            log.log(self, log.level.Error, str(e))
            log.log_exc(self, log.level.Warning)
            self._write(500, 'Error in server. Contact administrator')
        finally:
            delete_context()
예제 #4
0
    def do_GET(self):
        create_context(self.server, self.client_address, self.headers)
        try:
            first_question_mark = self.path.find("?")
            if first_question_mark >= 0:
                path = self.path[0:first_question_mark]
                options = urllib.unquote(self.path[first_question_mark + 1:])
            else:
                path = self.path
                options = ""

            parameters = [ field for field in options.split("&") if field.find("=") >= 0 ]

            session_id_param = [ field[field.find("=") + 1:] for field in parameters if field.startswith("sessionid") ]
            if len(session_id_param) == 0:
                self._write(400, "sessionid not provided")
                return

            session_id = session_id_param[0]

            last_slash = path.rfind("/")
            if last_slash >= 0:
                method_name = path[last_slash + 1:]
            else:
                method_name = path

            if 'get_%s' % method_name in dir(Methods):
                method = getattr(Methods, 'get_%s' % method_name)
                try:
                    response = method(self, session_id, parameters)
                except MethodError as me:
#                    import traceback
#                    traceback.print_exc()
                    log.log( self, log.level.Error, str(me))
                    log.log_exc( self, log.level.Warning)
                    self._write(400, "Error: %s" % me)
                    return
                json_response = json.dumps(response)
            else:
                self._write(400, "method %s not implemented" % urllib2.quote(method_name))
                return

            self._write(200, json_response)
        except Exception as e:
            import traceback
            traceback.print_exc()

            log.log( self, log.level.Error, str(e))
            log.log_exc( self, log.level.Warning)
            self._write(500, 'Error in server. Contact administrator')
        finally:
            delete_context()
예제 #5
0
    def do_GET(self):
        self.weblab_cookie = None
        self.login_weblab_cookie = None
        for current_cookie in (self.headers.getheader('cookie') or '').split('; '):
            if current_cookie.startswith('weblabsessionid'):
                self.weblab_cookie = current_cookie
            if current_cookie.startswith('loginweblabsessionid'):
                self.login_weblab_cookie = current_cookie

        if self.weblab_cookie is None:
            if self.server_route is not None:
                self.weblab_cookie = "weblabsessionid=sessidnotfound.%s" % self.server_route
            else:
                self.weblab_cookie = "weblabsessionid=sessidnotfound"

        if self.login_weblab_cookie is None:
            if self.server_route is not None:
                self.login_weblab_cookie = "loginweblabsessionid=loginsessid.not.found.%s" % self.server_route
            else:
                self.login_weblab_cookie = "loginweblabsessionid=sessidnotfound"

        create_context(self.server, self.client_address, self.headers)
        try:
            for method in self.methods:
                if method.matches(self.path):
                    m = method(self, self.cfg_manager, self.original_server)
                    message = m.run()
                    self._write(m.get_status(), m.get_content_type(), m.get_other_cookies(), message, m.get_other_headers(), m.avoid_weblab_cookies())
                    break
            else:
                NotFoundMethod(self, self.cfg_manager, self.original_server).run()
        except RequestManagedError as e:
            return
        except MethodError as e:
            log.log( self, log.level.Error, str(e))
            log.log_exc( self, log.level.Warning)
            self._write(e.status, 'text/html', [], e.msg)
        except Exception as e:
            import traceback
            traceback.print_exc()

            log.log( self, log.level.Error, str(e))
            log.log_exc( self, log.level.Warning)
            self._write(500, 'text/html', [], 'Error in server. Contact administrator')
        finally:
            delete_context()
예제 #6
0
 def do_POST(self, *args, **kwargs):
     create_context(self.server, self.client_address, self.headers)
     try:
         ServiceContainer.SOAPRequestHandler.do_POST(self, *args, **kwargs)
     finally:
         delete_context()
예제 #7
0
 def do_POST(self, *args, **kwargs):
     create_context(self.server, self.client_address, self.headers)
     try:
         SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.do_POST(self, *args, **kwargs)
     finally:
         delete_context()
예제 #8
0
    def do_POST(self):
        """
        This do_POST callback handles an HTTP request containing a JSON-encoded RPC request.
        """
        create_context(self.server, self.client_address, self.headers)

        try:
            length = int(self.headers['content-length'])
            post_content = self.rfile.read(length)

            # The contents of the POST contain a string with the JSON-encoded request. Decode that string.
            try:
                decoded = json.loads(post_content)
            except ValueError:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Couldn't deserialize message"}
                self.finish_error(response)
                return

            # Retrieve the name of the method being invoked.
            method_name = decoded.get('method')
            if method_name is None:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Missing 'method' attr"}
                self.finish_error(response)
                return

            # Retrieve the parameters of the method being invoked.
            params = decoded.get('params')
            if params is None:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Missing 'params' attr"}
                self.finish_error(response)
                return

            # Ensure that we actually have a facade manager, as we should.
            # (The method specified in the JSON request, which we are going to invoke,
            # is actually located in the facade manager).
            if self.facade_manager is None:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Facade manager not set"}
                self.finish_error(response)
                return

            # Ensure that the method that is remotely being called does exist.
            if not hasattr(self.facade_manager, method_name):
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Method not recognized"}
                self.finish_error(response)
                return

            # Retrieve a reference to the method.
            method = getattr(self.facade_manager,method_name)

            # Build a standard dictionary with the parameters to call the actual method.
            newparams = {}
            try:
                for param in params:
                    newparams[str(param)] = params[param]
            except Exception as e:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"unicode not accepted in param names"}
                self.finish_error(response)
                return

            # Call the method specified in the request,
            # with the parameters from the dictionary we just built.
            try:
                return_value = method(**newparams)
            except RemoteFacadeManager.JSONError as jsone:
                response = jsone.args[0]
                self.finish_error(response)
                return
            except Exception as e:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Unexpected exception: %s" % e}
                self.finish_error(response)
                return

            # No exception was raised so the request was successful. We will now return the response to
            # the remote caller.
            try:
                # Serialize the response to a JSON dictionary.
                parsed_return_value = simplify_response(return_value)
                response = json.dumps({"result":parsed_return_value, "is_exception" : False})
            except Exception as e:
                response = {"is_exception":True,"code":WEBLAB_GENERAL_EXCEPTION_CODE,"message":"Error encoding return value"}
                log.log( JsonHttpHandler, log.level.Error, "Request from %s: %s" % (get_context().get_ip_address(), "Error encoding return value: %s" % e))
                log.log( JsonHttpHandler, log.level.Error, "Message was: %s" % return_value)
                log.log_exc( JsonHttpHandler, log.level.Warning )
                self.finish_error(response)
                return

            self.finish_post(response)
        finally:
            delete_context()
예제 #9
0
    def do_POST(self):
        """
        This do_POST callback handles an HTTP request containing a JSON-encoded RPC request.
        """
        create_context(self.server, self.client_address, self.headers)

        try:
            length = int(self.headers['content-length'])
            post_content = self.rfile.read(length)

            # The contents of the POST contain a string with the JSON-encoded request. Decode that string.
            try:
                decoded = json.loads(post_content)
            except ValueError:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Couldn't deserialize message"
                }
                self.finish_error(response)
                return

            # Retrieve the name of the method being invoked.
            method_name = decoded.get('method')
            if method_name is None:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Missing 'method' attr"
                }
                self.finish_error(response)
                return

            # Retrieve the parameters of the method being invoked.
            params = decoded.get('params')
            if params is None:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Missing 'params' attr"
                }
                self.finish_error(response)
                return

            # Ensure that we actually have a facade manager, as we should.
            # (The method specified in the JSON request, which we are going to invoke,
            # is actually located in the facade manager).
            if self.facade_manager is None:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Facade manager not set"
                }
                self.finish_error(response)
                return

            # Ensure that the method that is remotely being called does exist.
            if not hasattr(self.facade_manager, method_name):
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Method not recognized"
                }
                self.finish_error(response)
                return

            # Retrieve a reference to the method.
            method = getattr(self.facade_manager, method_name)

            # Build a standard dictionary with the parameters to call the actual method.
            newparams = {}
            try:
                for param in params:
                    newparams[str(param)] = params[param]
            except Exception as e:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "unicode not accepted in param names"
                }
                self.finish_error(response)
                return

            # Call the method specified in the request,
            # with the parameters from the dictionary we just built.
            try:
                return_value = method(**newparams)
            except RemoteFacadeManager.JSONError as jsone:
                response = jsone.args[0]
                self.finish_error(response)
                return
            except Exception as e:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Unexpected exception: %s" % e
                }
                self.finish_error(response)
                return

            # No exception was raised so the request was successful. We will now return the response to
            # the remote caller.
            try:
                # Serialize the response to a JSON dictionary.
                parsed_return_value = simplify_response(return_value)
                response = json.dumps({
                    "result": parsed_return_value,
                    "is_exception": False
                })
            except Exception as e:
                response = {
                    "is_exception": True,
                    "code": WEBLAB_GENERAL_EXCEPTION_CODE,
                    "message": "Error encoding return value"
                }
                log.log(
                    JsonHttpHandler, log.level.Error, "Request from %s: %s" %
                    (get_context().get_ip_address(),
                     "Error encoding return value: %s" % e))
                log.log(JsonHttpHandler, log.level.Error,
                        "Message was: %s" % return_value)
                log.log_exc(JsonHttpHandler, log.level.Warning)
                self.finish_error(response)
                return

            self.finish_post(response)
        finally:
            delete_context()