1 /* 2 * $Id$ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 package org.apache.struts.webapp.validator; 23 24 import jakarta.servlet.http.HttpServletRequest; 25 import jakarta.servlet.http.HttpServletResponse; 26 import jakarta.servlet.http.HttpSession; 27 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 35 /** 36 * Implementation of <strong>Action</strong> that validates a registration form. 37 * 38 */ 39 public final class RegistrationAction extends Action { 40 private static final long serialVersionUID = -4885363822107512126L; 41 42 /** 43 * The {@code Log} instance for this class. 44 */ 45 private final static Logger LOG = 46 LoggerFactory.getLogger(RegistrationAction.class); 47 48 /** 49 * Process the specified HTTP request, and create the corresponding HTTP 50 * response (or forward to another web component that will create it). 51 * Return an <code>ActionForward</code> instance describing where and how 52 * control should be forwarded, or <code>null</code> if the response has 53 * already been completed. 54 * 55 * @param mapping The ActionMapping used to select this instance 56 * @param form The optional ActionForm bean for this request (if any) 57 * @param request The HTTP request we are processing 58 * @param response The HTTP response we are creating 59 * 60 * @return Action to forward to 61 * @exception Exception if an input/output error or servlet exception occurs 62 */ 63 public ActionForward execute( 64 ActionMapping mapping, 65 ActionForm form, 66 HttpServletRequest request, 67 HttpServletResponse response) 68 throws Exception { 69 70 // Was this transaction cancelled? 71 if (isCancelled(request)) { 72 LOG.info(" {} - Registration transaction was cancelled", 73 mapping.getAttribute()); 74 75 removeFormBean(mapping, request); 76 77 return (mapping.findForward("success")); 78 } 79 80 return mapping.findForward("success"); 81 } 82 83 /** 84 * Convenience method for removing the obsolete form bean. 85 * 86 * @param mapping The ActionMapping used to select this instance 87 * @param request The HTTP request we are processing 88 */ 89 protected void removeFormBean( 90 ActionMapping mapping, 91 HttpServletRequest request) { 92 93 // Remove the obsolete form bean 94 if (mapping.getAttribute() != null) { 95 if ("request".equals(mapping.getScope())) { 96 request.removeAttribute(mapping.getAttribute()); 97 } else { 98 HttpSession session = request.getSession(); 99 session.removeAttribute(mapping.getAttribute()); 100 } 101 } 102 } 103 }