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.servlet.mvc.multiaction; 018 019import java.util.Map; 020import javax.servlet.ServletException; 021import javax.servlet.http.HttpServletRequest; 022 023import org.springframework.core.style.StylerUtils; 024import org.springframework.web.util.UrlPathHelper; 025 026/** 027 * Exception thrown when there is no handler method ("action" method) 028 * for a specific HTTP request. 029 * 030 * @author Rod Johnson 031 * @author Juergen Hoeller 032 * @see MethodNameResolver#getHandlerMethodName(javax.servlet.http.HttpServletRequest) 033 * @deprecated as of 4.3, in favor of annotation-driven handler methods 034 */ 035@Deprecated 036@SuppressWarnings("serial") 037public class NoSuchRequestHandlingMethodException extends ServletException { 038 039 private String methodName; 040 041 042 /** 043 * Create a new NoSuchRequestHandlingMethodException for the given request. 044 * @param request the offending HTTP request 045 */ 046 public NoSuchRequestHandlingMethodException(HttpServletRequest request) { 047 this(new UrlPathHelper().getRequestUri(request), request.getMethod(), request.getParameterMap()); 048 } 049 050 /** 051 * Create a new NoSuchRequestHandlingMethodException. 052 * @param urlPath the request URI that has been used for handler lookup 053 * @param method the HTTP request method of the request 054 * @param parameterMap the request's parameters as map 055 */ 056 public NoSuchRequestHandlingMethodException(String urlPath, String method, Map<String, String[]> parameterMap) { 057 super("No matching handler method found for servlet request: path '" + urlPath + 058 "', method '" + method + "', parameters " + StylerUtils.style(parameterMap)); 059 } 060 061 /** 062 * Create a new NoSuchRequestHandlingMethodException for the given request. 063 * @param methodName the name of the handler method that wasn't found 064 * @param controllerClass the class the handler method was expected to be in 065 */ 066 public NoSuchRequestHandlingMethodException(String methodName, Class<?> controllerClass) { 067 super("No request handling method with name '" + methodName + 068 "' in class [" + controllerClass.getName() + "]"); 069 this.methodName = methodName; 070 } 071 072 073 /** 074 * Return the name of the offending method, if known. 075 */ 076 public String getMethodName() { 077 return this.methodName; 078 } 079 080}