| /* |
| * $Id$ |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you 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.apache.struts.dispatcher.servlet; |
| |
| import org.apache.struts.chain.contexts.ActionContext; |
| import org.apache.struts.chain.contexts.ServletActionContext; |
| import org.apache.struts.dispatcher.AbstractMappingDispatcher; |
| |
| import java.lang.reflect.Method; |
| |
| import javax.servlet.http.HttpServletResponse; |
| |
| /** |
| * This servlet-based dispatcher uses the configuration value of the |
| * <code>parameter</code> attribute from the corresponding |
| * {@link org.apache.struts.action.ActionMapping} to pick the appropriate method |
| * on the action. Because mapping characteristics may differ between the various |
| * handlers, actions can be combined in the same class that, differ in their use |
| * of method signatures, forms, and/or validation. |
| * <p> |
| * For example, a single action may manage a subscription process by defining |
| * the following methods: |
| * <ul> |
| * <li><code>public ActionForward create(ActionMapping mapping, ActionForm form, |
| * HttpServletRequest request, HttpServletResponse response) throws Exception</code></li> |
| * <li><code>public ActionForward delete(ActionMapping mapping, ActionForm form, |
| * HttpServletRequest request, HttpServletResponse response) throws Exception</code></li> |
| * <li><code>public ActionForward edit(ActionMapping mapping, ActionForm form, |
| * HttpServletRequest request, HttpServletResponse response) throws Exception</code></li> |
| * <li><code>public ActionForward list(ActionMapping mapping, ActionForm form, |
| * HttpServletRequest request, HttpServletResponse response) throws Exception</code></li> |
| * <li><code>public ActionForward save(ActionMapping mapping, ActionForm form, |
| * HttpServletRequest request, HttpServletResponse response) throws Exception</code></li> |
| * </ul> |
| * for which a corresponding configuration would exist: |
| * |
| * <pre><code> |
| * <action path="/createSubscription" |
| * type="org.example.SubscriptionAction" |
| * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" |
| * parameter="create"> |
| * <forward path="/editSubscription.jsp"/> |
| * </action> |
| * |
| * <action path="/deleteSubscription" |
| * type="org.example.SubscriptionAction" |
| * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" |
| * parameter="delete" |
| * name="subscriptionForm" |
| * scope="request" |
| * input="/subscription.jsp"> |
| * <forward path="/deletedSubscription.jsp"/> |
| * </action> |
| * |
| * <action path="/editSubscription" |
| * type="org.example.SubscriptionAction" |
| * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" |
| * parameter="edit"> |
| * <forward path="/editSubscription.jsp"/> |
| * </action> |
| * |
| * <action path="/listSubscriptions" |
| * type="org.example.SubscriptionAction" |
| * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" |
| * parameter="list"> |
| * <forward path="/subscriptionList.jsp"/> |
| * </action> |
| * |
| * <action path="/saveSubscription" |
| * type="org.example.SubscriptionAction" |
| * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" |
| * parameter="save" |
| * name="subscriptionForm" |
| * scope="request" |
| * validate="true" |
| * input="/editSubscription.jsp"> |
| * <forward path="/savedSubscription.jsp"/> |
| * </action> |
| * </code></pre> |
| * |
| * @version $Rev$ |
| * @since Struts 1.4 |
| */ |
| public class ServletMappingDispatcher extends AbstractMappingDispatcher { |
| |
| protected Object[] buildMethodArguments(ActionContext context, Method method) { |
| return ServletDispatchUtils.buildClassicExecuteArguments((ServletActionContext) context); |
| } |
| |
| protected Method resolveMethod(ActionContext context, String methodName) throws NoSuchMethodException { |
| return ServletDispatchUtils.resolveClassicExecuteMethod(context, methodName); |
| } |
| |
| /** |
| * Sends the 404 HTTP error response. |
| * |
| * @return always <code>null</code> since the response is handled directly |
| */ |
| protected Object unspecified(ActionContext context) throws Exception { |
| HttpServletResponse response = ((ServletActionContext) context).getResponse(); |
| response.sendError(HttpServletResponse.SC_NOT_FOUND); |
| return null; |
| } |
| |
| } |