001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.bind;
018
019/**
020 * {@link ServletRequestBindingException} subclass that indicates a missing parameter.
021 *
022 * @author Juergen Hoeller
023 * @since 2.0.2
024 */
025@SuppressWarnings("serial")
026public class MissingServletRequestParameterException extends ServletRequestBindingException {
027
028        private final String parameterName;
029
030        private final String parameterType;
031
032
033        /**
034         * Constructor for MissingServletRequestParameterException.
035         * @param parameterName the name of the missing parameter
036         * @param parameterType the expected type of the missing parameter
037         */
038        public MissingServletRequestParameterException(String parameterName, String parameterType) {
039                super("");
040                this.parameterName = parameterName;
041                this.parameterType = parameterType;
042        }
043
044
045        @Override
046        public String getMessage() {
047                return "Required " + this.parameterType + " parameter '" + this.parameterName + "' is not present";
048        }
049
050        /**
051         * Return the name of the offending parameter.
052         */
053        public final String getParameterName() {
054                return this.parameterName;
055        }
056
057        /**
058         * Return the expected type of the offending parameter.
059         */
060        public final String getParameterType() {
061                return this.parameterType;
062        }
063
064}