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.portlet.handler;
018
019import javax.portlet.PortletException;
020
021import org.springframework.util.StringUtils;
022
023/**
024 * Exception thrown when a request handler does not support a
025 * specific request method.
026 *
027 * @author Juergen Hoeller
028 * @since 3.0
029 */
030@SuppressWarnings("serial")
031public class PortletRequestMethodNotSupportedException extends PortletException {
032
033        private String method;
034
035        private String[] supportedMethods;
036
037
038        /**
039         * Create a new PortletRequestMethodNotSupportedException.
040         * @param method the unsupported HTTP request method
041         */
042        public PortletRequestMethodNotSupportedException(String method) {
043                this(method, null);
044        }
045
046        /**
047         * Create a new PortletRequestMethodNotSupportedException.
048         * @param method the unsupported HTTP request method
049         * @param supportedMethods the actually supported HTTP methods
050         */
051        public PortletRequestMethodNotSupportedException(String method, String[] supportedMethods) {
052                super("Request method '" + method + "' not supported by mapped handler");
053                this.method = method;
054                this.supportedMethods = supportedMethods;
055        }
056
057        /**
058         * Create a new PortletRequestMethodNotSupportedException.
059         * @param supportedMethods the actually supported HTTP methods
060         */
061        public PortletRequestMethodNotSupportedException(String[] supportedMethods) {
062                super("Mapped handler only supports client data requests with methods " +
063                                StringUtils.arrayToCommaDelimitedString(supportedMethods));
064                this.supportedMethods = supportedMethods;
065        }
066
067
068        /**
069         * Return the HTTP request method that caused the failure.
070         */
071        public String getMethod() {
072                return this.method;
073        }
074
075        /**
076         * Return the actually supported HTTP methods, if known.
077         */
078        public String[] getSupportedMethods() {
079                return this.supportedMethods;
080        }
081
082}