001 // Copyright 2007, 2008 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry5.upload.internal.services; 016 017 import org.apache.commons.fileupload.servlet.ServletFileUpload; 018 import org.apache.tapestry5.services.HttpServletRequestFilter; 019 import org.apache.tapestry5.services.HttpServletRequestHandler; 020 import org.apache.tapestry5.upload.services.MultipartDecoder; 021 022 import javax.servlet.http.HttpServletRequest; 023 import javax.servlet.http.HttpServletResponse; 024 import java.io.IOException; 025 026 /** 027 * Filter that decodes an incoming multipart request. 028 */ 029 public class MultipartServletRequestFilter implements HttpServletRequestFilter 030 { 031 private final MultipartDecoder decoder; 032 033 public MultipartServletRequestFilter(MultipartDecoder multipartDecoder) 034 { 035 decoder = multipartDecoder; 036 } 037 038 public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler) 039 throws IOException 040 { 041 HttpServletRequest newRequest = ServletFileUpload.isMultipartContent(request) ? decoder.decode( 042 request) : request; 043 044 return handler.service(newRequest, response); 045 } 046 047 }