def handle(target, base_request, request, response)
            handle_exceptions(response) do
                # Turn the ServletRequest into a Rack env hash
                env = servlet_to_rack(request)

                # Handle asynchronous responses via Servlet continuations.
                continuation = ContinuationSupport.getContinuation(request)

                # If this is an expired connection, do nothing.
                return if continuation.isExpired

                # We should never be re-dispatched.
                raise("Request re-dispatched.") unless continuation.isInitial

                # Add our own special bits to the rack environment so that 
                # Rack middleware can have access to the Java internals.
                env['rack.java.servlet'] = true
                env['rack.java.servlet.request'] = request
                env['rack.java.servlet.response'] = response
                env['rack.java.servlet.continuation'] = continuation

                # Add an callback that can be used to add results to the
                # response asynchronously.
                env['async.callback'] = Proc.new do |rack_response|
                    servlet_response = continuation.getServletResponse
                    rack_to_servlet(rack_response, servlet_response) \
                        and continuation.complete
                end

                # Execute the Rack request.
                catch(:async) do
                    rack_response = @app.call(env)
                   
                    # For apps that don't throw :async.
                    unless(rack_response[0] == -1)
                        # Nope, nothing asynchronous here.
                        rack_to_servlet(rack_response, response)
                        return
                    end
                end

                # If we got here, this is a continuation.
                continuation.suspend(response)
            end
        end
def handle(target, base_request, request, response)
            handle_exceptions(response) do
                # Turn the ServletRequest into a Rack env hash
                env = servlet_to_rack(request)

                # Handle asynchronous responses via Servlet continuations.
                continuation = ContinuationSupport.getContinuation(request)

                # If this is an expired connection, do nothing.
                return if continuation.isExpired

                # We should never be re-dispatched.
                raise("Request re-dispatched.") unless continuation.isInitial

                # Add our own special bits to the rack environment so that 
                # Rack middleware can have access to the Java internals.
                env['rack.java.servlet'] = true
                env['rack.java.servlet.request'] = request
                env['rack.java.servlet.response'] = response
                env['rack.java.servlet.continuation'] = continuation

                # Add an callback that can be used to add results to the
                # response asynchronously.
                env['async.callback'] = Proc.new do |rack_response|
                    servlet_response = continuation.getServletResponse
                    rack_to_servlet(rack_response, servlet_response) \
                        and continuation.complete
                end

                # Execute the Rack request.
                catch(:async) do
                    rack_response = @app.call(env)
                   
                    # For apps that don't throw :async.
                    unless(rack_response[0] == -1)
                        # Nope, nothing asynchronous here.
                        rack_to_servlet(rack_response, response)
                        return
                    end
                end

                # If we got here, this is a continuation.
                continuation.suspend(response)
            end
        end
Takes an incoming request (as a HttpServletRequest) and dispatches
 it to the rack application setup via [rackup]. All this really
 involves is translating the various bits of the Servlet API into
 the Rack API on the way in, and translating the response back on
 the way out.

 Also, we implement a common extension to the Rack api for
 asynchronous request processing.  We supply an 'async.callback'
 parameter in env to the Rack application.  If we catch an
 :async symbol thrown by the app, we initiate a Jetty continuation.

 When 'async.callback' gets a response with empty headers and an
 empty body, we declare the async response finished.