All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.web.bind.UnsatisfiedServletRequestParameterException Maven / Gradle / Ivy

There is a newer version: 6.1.13
Show newest version
/*
 * Copyright 2002-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.bind;

import java.util.Iterator;
import java.util.Map;

import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * {@link ServletRequestBindingException} subclass that indicates an unsatisfied
 * parameter condition, as typically expressed using an @RequestMapping
 * annotation at the @Controller type level.
 *
 * @author Juergen Hoeller
 * @since 3.0
 * @see org.springframework.web.bind.annotation.RequestMapping#params()
 */
public class UnsatisfiedServletRequestParameterException extends ServletRequestBindingException {

	private final String[] paramConditions;

	private final Map actualParams;


	/**
	 * Create a new UnsatisfiedServletRequestParameterException.
	 * @param paramConditions the parameter conditions that have been violated
	 * @param actualParams the actual parameter Map associated with the ServletRequest
	 */
	@SuppressWarnings("unchecked")
	public UnsatisfiedServletRequestParameterException(String[] paramConditions, Map actualParams) {
		super("");
		this.paramConditions = paramConditions;
		this.actualParams = (Map) actualParams;
	}


	@Override
	public String getMessage() {
		return "Parameter conditions \"" + StringUtils.arrayToDelimitedString(this.paramConditions, ", ") +
				"\" not met for actual request parameters: " + requestParameterMapToString(this.actualParams);
	}

	private static String requestParameterMapToString(Map actualParams) {
		StringBuilder result = new StringBuilder();
		for (Iterator> it = actualParams.entrySet().iterator(); it.hasNext();) {
			Map.Entry entry = it.next();
			result.append(entry.getKey()).append('=').append(ObjectUtils.nullSafeToString(entry.getValue()));
			if (it.hasNext()) {
				result.append(", ");
			}
		}
		return result.toString();
	}

	/**
	 * Return the parameter conditions that have been violated.
	 * @see org.springframework.web.bind.annotation.RequestMapping#params()
	 */
	public final String[] getParamConditions() {
		return this.paramConditions;
	}

	/**
	 * Return the actual parameter Map associated with the ServletRequest.
	 * @see javax.servlet.ServletRequest#getParameterMap()
	 */
	public final Map getActualParams() {
		return this.actualParams;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy