001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012package org.apache.tapestry5.http.internal.services; 013 014import java.util.List; 015 016import javax.servlet.http.HttpServletRequest; 017import javax.servlet.http.HttpServletResponse; 018 019import org.apache.tapestry5.http.AsyncRequestHandler; 020import org.apache.tapestry5.http.AsyncRequestHandlerResponse; 021import org.apache.tapestry5.http.internal.AsyncRequestService; 022 023/** 024 * Service that handles Tapestry's support for asynchronous Servlet API requests. 025 */ 026public class AsyncRequestServiceImpl implements AsyncRequestService 027{ 028 029 final private List<AsyncRequestHandler> handlers; 030 031 public AsyncRequestServiceImpl(List<AsyncRequestHandler> handlers) 032 { 033 super(); 034 this.handlers = handlers; 035 } 036 037 public AsyncRequestHandlerResponse handle(HttpServletRequest request, HttpServletResponse response) 038 { 039 040 AsyncRequestHandlerResponse handlerResponse = AsyncRequestHandlerResponse.notHandled(); 041 042 for (AsyncRequestHandler asyncRequestHandler : handlers) 043 { 044 handlerResponse = asyncRequestHandler.handle(request, response); 045 if (handlerResponse.isAsync()) 046 { 047 break; 048 } 049 } 050 051 return handlerResponse; 052 } 053 054}