require 'rubygems' require 'rack' module Jangle class App # The router should respond to route(service_request) attr_accessor :router # Splits the request path into a format (the suffix, e.g. .xml) # and the remaining path (which becomes part of the connector request); # the format specifies the content type for the response; # the connector request fetches JSON from the connector. def call(env) start_time = Time.now http_request = Rack::Request.new(env) LOGGER.debug "Request to be served by Jangle: " + http_request.inspect # Find the endpoint via the router; # NB this resets the http request's path, as some may have been # gobbled during routing http_request.path_info, endpoint = self.router.route(http_request) # LOGGER.debug "Using this endpoint to serve request: " + endpoint.inspect # Get a response from the endpoint rack_response = endpoint.serve(http_request) LOGGER.debug "Response returned by Jangle: " + rack_response.inspect end_time = Time.now time_taken = end_time - start_time LOGGER.info "Request took #{time_taken} seconds to serve" # Return as standard HTTP response rack_response.finish end end end