Example #1
0
    def process_request(self, request):
        content = None
        mode = request.x_mode
        if mode == MODE_VERSION:
            content = self.process_mode_version(request)
        elif mode == MODE_INFO:
            content = self.process_mode_info(request)
        elif mode == MODE_SCHEMA:
            content = self.process_mode_schema(request)
        else:
            raise error.ModeNotSupportedError()

        if not content:
            if not mode:
                message = u"Request has not X-Mode"
            else:
                message = u"Invalid X-Mode %s" % mode

            raise error.InternalExceptionError(message)

        body = simplejson.dumps(content, separators=(",", ":"))
        response = Response(body=body)
        response.content_type = "application/json; charset=utf-8"
        
        return response
Example #2
0
    def __call__(self, environ, start_response):
        response = Response()
        response.content_type  = "text/html"
        response.encoding = 'utf-8'
        response.body = "<h1>OK</h1>"

        #get the controller that handle current XHTTP request
        controller = environ['xhttp.controller']

        return response
Example #3
0
    def __call__(self, environ, start_response):
        request = Request(self.node, environ)
        #check that version is valid for current node
        try:
            x_version = float(request.x_version)
        except ValueError:
            x_version = None
        
        if x_version > self.node.server_version or not x_version:
            raise error.VersionNotSupportedError()

        try:
            if request.x_mode == MODE_PERFORM:
                #get controller in charge of performing request action
                controller = self.node.get_request_controller(request)
                if self.application:
                    environ['xhttp.controller'] = controller
                    environ['xhttp.request'] = request
                    environ['xhttp.node'] = controller
                    #call application to get the Response instance
                    response = self.application(environ, start_response)
                else:
                    #when no application is assigned to middleware
                    #call controller here to get Response
                    response = controller(request, self.node)
            else:
                #when X-Mode is not perform get contents from server node
                response = self.node.process_request(request)
        except error.XHTTPError, err:
            response = Response.create_from_error(err)