Example #1
0
 def get_requests_and_response(self):
     out = StringIO.StringIO()
     s_req = "%s %s HTTP/%s" % ("GET", self.method, "1.0")
     req = http_request(DummyChannel(self), s_req, "GET", self.method, "1.0", self.headers)
     env = self.get_env(req)
     resp = make_response(req, env)
     zreq = HTTPRequest(out, env, resp)
     return req, zreq, resp
Example #2
0
    def get_requests_and_response(self, message):
        # All ZAMQP-requests are send to the same 'zamqp-consumer'-view. To
        # enhance the resulting transaction undo log, we append the view path
        # with message related details so that the full undo log path will be
        # @@zamqp-consumer/connection_id/exchange/routing_key[/correlation_id]
        exchange = getattr(message.method_frame, 'exchange', '') or '(default)'
        routing_key = getattr(message.method_frame, 'routing_key', '')
        correlation_id = getattr(message.header_frame, 'correlation_id', '')

        _params = (exchange, routing_key)
        if self._USE_VHM and self.vhm_method_prefix:
            _method = \
                self.vhm_method_prefix + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"
        elif self._USE_VHM:
            _method = \
                "/VirtualHostBase" + \
                "/{self.scheme}/{self.hostname}:{self.port}/{self.site_id}" + \
                "/VirtualHostRoot" + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"
        else:
            _method = \
                "/{self.site_id}" + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"

        if correlation_id:
            _method += "/{2}"
            _params += (correlation_id, )

        method = _method.format(self=self, *_params)

        out = StringIO.StringIO()
        s_req = '%s %s HTTP/%s' % ('GET', method, '1.0')
        req = http_request(AMQPMedusaChannel(self), s_req, 'GET', method,
                           '1.0', self.headers)
        env = self.get_env(req)
        resp = make_response(req, env)

        env['AMQP_MESSAGE'] = message
        env['AMQP_USER_ID'] = self.user_id
        zreq = AMQPRequest(out, env, resp)

        # TODO: We may need some abstraction here to support custom PAS-plugins
        # for authentication of AMQP-requests.
        #
        # The following default __ac-cookie support works only for the default
        # Plone 4.x-setup, for authenticating messages between Plone-sites with
        # the same plone.session shared secret. It could also be used for
        # authenticating web-stomp-origin requests, but in reality, there is no
        # safe way to give the web-stomp-javascript access the value of the
        # current __ac-cookie value.
        headers = getattr(message.header_frame, 'headers', {}) or {}
        x_cookie_auth = headers.get('x-cookie-auth', None)
        if x_cookie_auth:
            zreq.cookies['__ac'] = x_cookie_auth

        return req, zreq, resp
Example #3
0
    def get_requests_and_response(self, message):
        # All ZAMQP-requests are send to the same 'zamqp-consumer'-view. To
        # enhance the resulting transaction undo log, we append the view path
        # with message related details so that the full undo log path will be
        # @@zamqp-consumer/connection_id/exchange/routing_key[/correlation_id]
        exchange = getattr(message.method_frame, 'exchange', '') or '(default)'
        routing_key = getattr(message.method_frame, 'routing_key', '')
        correlation_id = getattr(message.header_frame, 'correlation_id', '')

        _params = (exchange, routing_key)
        if self._USE_VHM and self.vhm_method_prefix:
            _method = \
                self.vhm_method_prefix + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"
        elif self._USE_VHM:
            _method = \
                "/VirtualHostBase" + \
                "/{self.scheme}/{self.hostname}:{self.port}/{self.site_id}" + \
                "/VirtualHostRoot" + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"
        else:
            _method = \
                "/{self.site_id}" + \
                "/@@zamqp-consumer/{self.connection_id}/{0}/{1}"

        if correlation_id:
            _method += "/{2}"
            _params += (correlation_id, )

        method = _method.format(self=self, *_params)

        out = StringIO.StringIO()
        s_req = '%s %s HTTP/%s' % ('GET', method, '1.0')
        req = http_request(AMQPMedusaChannel(self), s_req, 'GET', method,
                           '1.0', self.headers)
        env = self.get_env(req)
        resp = make_response(req, env)

        env['AMQP_MESSAGE'] = message
        env['AMQP_USER_ID'] = self.user_id
        zreq = AMQPRequest(out, env, resp)

        # TODO: We may need some abstraction here to support custom PAS-plugins
        # for authentication of AMQP-requests.
        #
        # The following default __ac-cookie support works only for the default
        # Plone 4.x-setup, for authenticating messages between Plone-sites with
        # the same plone.session shared secret. It could also be used for
        # authenticating web-stomp-origin requests, but in reality, there is no
        # safe way to give the web-stomp-javascript access the value of the
        # current __ac-cookie value.
        headers = getattr(message.header_frame, 'headers', {}) or {}
        x_cookie_auth = headers.get('x-cookie-auth', None)
        if x_cookie_auth:
            zreq.cookies['__ac'] = x_cookie_auth

        return req, zreq, resp
Example #4
0
 def get_requests_and_response(self):
     out = StringIO()
     s_req = '%s %s HTTP/%s' % ('GET', self.method, '1.0')
     req = http_request(DummyChannel(self), s_req, 'GET', self.method,
                        '1.0', self.headers)
     env = self.get_env(req)
     resp = make_response(req, env)
     zreq = HTTPRequest(out, env, resp)
     return req, zreq, resp
Example #5
0
 def get_requests_and_response(self):
     out = StringIO.StringIO()
     s_req = '%s %s HTTP/%s' % ('GET', self.method, '1.0')
     req = http_request(DummyChannel(self), s_req, 'GET', self.method,
                        '1.0', self.headers)
     env = self.get_env(req)
     resp = make_response(req, env)
     zreq = HTTPRequest(out, env, resp)
     return req, zreq, resp
Example #6
0
    def clean_shutdown_control(self, _shutdown_phase, time_in_this_phase):
        """
      Inform invoked method that a shutdown is in progress.

      Here we:
       - Prevent regular tics from being sent. This does not prevent
         already-issued tics from running.
       - Issue a special tic, ran asynchronously from regular tics and
         asynchronously from this thread.
       - Wait for that special tic to return, so that we know all clean
         shutdown handlers have completely run.
       - Return control to caller.

      To wait for shutdown handler to return, it has been chosen to use a
      semaphore scheme. It has the following drawbacks:
       - It is intrusive: we need to hook foreign classes, since it's not
         the way things happen with regular zope data exchange.
       - We can't get what the shutdown handler returned (http return code,
         page content, ...) so we will never take Lifetime's veto. So shutdown
         handler must block until shutdown is complete, which is not how
         clean_shutdown_control is supposed to work. Note though that it is a
         design weakness in clean_shutdown_control, since some shutdown
         handlers might not have finshed their job at the time process gets
         closed.
    """
        self.running = False
        if self.shutdown_method is not None:
            # XXX: should use a float for time representation
            method = '%s?phase:int=%i&time_in_phase:float=%f' % \
              (self.shutdown_method, _shutdown_phase, time_in_this_phase)

            stdin = StringIO.StringIO()
            request_string = 'GET %s HTTP/1.0' % (method, )
            request = http_request(
                DummyChannel(self), request_string, 'GET', method, '1.0',
                self.headers)
            environment = self.get_env(request)
            response = make_response(request, environment)

            # Hook response._finish to get a notification when request is over.
            def _finish():
                response.__class__._finish(response)
                wait_for_close_lock.release()

            response._finish = _finish
            # (end of hook)
            zope_request = HTTPRequest(stdin, environment, response)
            wait_for_close_lock.acquire()
            self.zhandler('Zope2', zope_request, response)
            self.log_info('ClockServer: Waiting for shutdown handler.')
            wait_for_close_lock.acquire()
            self.log_info('ClockServer: Going on.')
            wait_for_close_lock.release()
        return 0  # TODO: detect an error to allow taking the veto.
Example #7
0
 def get_requests_and_response(self, conn, data):
     out = StringIO.StringIO()
     s_req = '%s %s HTTP/%s' % ('GET', self.method, '1.0')
     req = http_request(WebSocketChannel(self, conn), s_req,
                        'GET', self.method,
                        '1.0', self.server.headers)
     env = self.get_env(req)
     resp = make_response(req, env)
     env['HTTP_COOKIE'] = conn.cookie
     env['WEBSOCKET_DATA'] = data
     return req, WebSocketRequest(out, env, resp), resp
Example #8
0
  def clean_shutdown_control(self, _shutdown_phase, time_in_this_phase):
    """
      Inform invoked method that a shutdown is in progress.

      Here we:
       - Prevent regular tics from being sent. This does not prevent
         already-issued tics from running.
       - Issue a special tic, ran asynchronously from regular tics and
         asynchronously from this thread.
       - Wait for that special tic to return, so that we know all clean
         shutdown handlers have completely run.
       - Return control to caller.

      To wait for shutdown handler to return, it has been chosen to use a
      semaphore scheme. It has the following drawbacks:
       - It is intrusive: we need to hook foreign classes, since it's not
         the way things happen with regular zope data exchange.
       - We can't get what the shutdown handler returned (http return code,
         page content, ...) so we will never take Lifetime's veto. So shutdown
         handler must block until shutdown is complete, which is not how
         clean_shutdown_control is supposed to work. Note though that it is a
         design weakness in clean_shutdown_control, since some shutdown
         handlers might not have finshed their job at the time process gets
         closed.
    """
    self.running = False
    if self.shutdown_method is not None:
      # XXX: should use a float for time representation
      method = '%s?phase:int=%i&time_in_phase:float=%f' % \
        (self.shutdown_method, _shutdown_phase, time_in_this_phase)

      stdin = StringIO.StringIO()
      request_string = 'GET %s HTTP/1.0' % (method, )
      request = http_request(DummyChannel(self), request_string, 'GET', method,
                             '1.0', self.headers)
      environment = self.get_env(request)
      response = make_response(request, environment)
      # Hook response._finish to get a notification when request is over.
      def _finish():
        response.__class__._finish(response)
        wait_for_close_lock.release()
      response._finish = _finish
      # (end of hook)
      zope_request = HTTPRequest(stdin, environment, response)
      wait_for_close_lock.acquire()
      self.zhandler('Zope2', zope_request, response)
      self.log_info('ClockServer: Waiting for shutdown handler.')
      wait_for_close_lock.acquire()
      self.log_info('ClockServer: Going on.')
      wait_for_close_lock.release()
    return 0 # TODO: detect an error to allow taking the veto.
Example #9
0
def make_request_and_response(server, task):
    payload = StringIO.StringIO()
    if task['payload'] is not None:
        payload.write(task['payload'])
        payload.seek(0)
    additional_headers = ['User-Agent: {0:s}'.format(TASK_QUEUE_SERVER_IDENT)]
    req = '{0:s} {1:s} HTTP/{2:s}'.format(task['method'], task['url'], '1.1')
    req = http_request(TaskChannel(server, task), req,
                       task['method'], task['url'], '1.1',
                       task['headers'] + additional_headers)
    env = make_env(req, task['method'])
    resp = make_response(req, env)
    task_request = TaskRequest(payload, env, resp)
    task_request.retry_max_count = server.retry_max_count
    return req, task_request, resp
Example #10
0
def make_request_and_response(server, task):
    payload = StringIO.StringIO()
    if task['payload'] is not None:
        payload.write(task['payload'])
        payload.seek(0)
    additional_headers = ['User-Agent: {0:s}'.format(TASK_QUEUE_SERVER_IDENT)]
    req = '{0:s} {1:s} HTTP/{2:s}'.format(task['method'], task['url'], '1.1')
    req = http_request(TaskChannel(server,
                                   task), req, task['method'], task['url'],
                       '1.1', task['headers'] + additional_headers)
    env = make_env(req, task['method'])
    resp = make_response(req, env)
    task_request = TaskRequest(payload, env, resp)
    task_request.retry_max_count = server.retry_max_count
    return req, task_request, resp
Example #11
0
    def get_requests_and_response(self, message):
        method = '%s/@@zamqp-consumer' % self.site_id

        out = StringIO.StringIO()
        s_req = '%s %s HTTP/%s' % ('GET', method, '1.0')
        req = http_request(DummyChannel(self), s_req, 'GET', method,
                           '1.0', self.headers)
        env = self.get_env(req)
        resp = make_response(req, env)

        env["AMQP_MESSAGE"] = message
        env["AMQP_USER_ID"] = self.user_id
        zreq = AMQPRequest(out, env, resp)

        return req, zreq, resp
Example #12
0
    def continue_request(self, sin, request):
        "continue handling request now that we have the stdin"

        s = get_header(CONTENT_LENGTH, request.header)
        if s:
            s = int(s)
        else:
            s = 0
        DebugLogger.log('I', id(request), s)

        env = self.get_environment(request)
        zresponse = make_response(request, env)
        if self._force_connection_close:
            zresponse._http_connection = 'close'
        zrequest = HTTPRequest(sin, env, zresponse)
        request.channel.current_request = None
        request.channel.queue.append((self.module_name, zrequest, zresponse))
        request.channel.work()
Example #13
0
    def continue_request(self, sin, request):
        "continue handling request now that we have the stdin"

        s = get_header(CONTENT_LENGTH, request.header)
        if s:
            s = int(s)
        else:
            s = 0
        DebugLogger.log('I', id(request), s)

        env = self.get_environment(request)
        zresponse = make_response(request, env)
        if self._force_connection_close:
            zresponse._http_connection = 'close'
        zrequest = HTTPRequest(sin, env, zresponse)
        request.channel.current_request = None
        request.channel.queue.append((self.module_name, zrequest, zresponse))
        request.channel.work()