001// Copyright 2011 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. 014package org.apache.tapestry5.http.services; 015 016import javax.servlet.http.HttpServletRequest; 017 018import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration; 019 020/** 021 * Service that converts the body of an HTTP request to a given target class. 022 * Each implementation, which should be contributed to the {@link HttpRequestBodyConverter} service, 023 * should check whether it can actually handled that request. If not, it should return <code>null</code>, 024 * which means trying the next HttpRequestBodyConverter instance. 025 */ 026@UsesOrderedConfiguration(HttpRequestBodyConverter.class) 027public interface HttpRequestBodyConverter 028{ 029 030 /** 031 * Converts the body of this request. If this implementation cannot handle this request, 032 * probably by not handling its content type, it should return <code>null</code>. 033 * In addition, if the request body is empty, this method should also return 034 * <code>null</code>. 035 * @param request an {@linkplain HttpServletRequest}. 036 * @param type the target type. 037 * @return an object of the target type or <code>null</code>. 038 */ 039 <T> T convert(HttpServletRequest request, Class<T> type); 040 041}