![JAR search and dependency download from the Maven repository](/logo.png)
com.mockrunner.example.struts.StoreDataAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.6-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.6-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.struts;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* This example action demonstrates the access to a data repository
* stored in the ServletContext
. Since the repository
* is not thread safe we have to synchronize the access. Used to
* demonstrate how to do multithread testing. Check out
* {@link StoreDataActionTest}.
*/
public class StoreDataAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ServletContext context = request.getSession().getServletContext();
synchronized(context)
{
String id = request.getParameter("id");
String data = request.getParameter("data");
MemoryBasedRepository repository = MemoryBasedRepository.instance(context);
if(repository.get(id) != null) return mapping.findForward("failure");
System.out.println("Thread " + Thread.currentThread().getName() + " wins the race");
repository.set(id, data);
return mapping.findForward("success");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy