01: package com.mockrunner.example.ejb;
02:
03: import javax.naming.InitialContext;
04: import javax.rmi.PortableRemoteObject;
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: import org.apache.struts.action.Action;
09: import org.apache.struts.action.ActionForm;
10: import org.apache.struts.action.ActionForward;
11: import org.apache.struts.action.ActionMapping;
12:
13: import com.mockrunner.example.ejb.interfaces.LogSession;
14: import com.mockrunner.example.ejb.interfaces.LogSessionHome;
15:
16: /**
17: * This example action takes a message parameter from the request
18: * and uses the {@link LogSessionBean} to log the message.
19: * See {@link LogActionTest} for an example test of this action.
20: */
21: public class LogAction extends Action {
22: public ActionForward execute(ActionMapping mapping,
23: ActionForm form, HttpServletRequest request,
24: HttpServletResponse response) throws Exception {
25: String message = request.getParameter("message");
26: try {
27: if (null != message) {
28: InitialContext initialContext = new InitialContext();
29: Object home = initialContext
30: .lookup("com/mockrunner/example/LogSession");
31: LogSessionHome logHome = (LogSessionHome) PortableRemoteObject
32: .narrow(home, LogSessionHome.class);
33: LogSession log = logHome.create();
34: log.logMessage(message);
35: log.remove();
36: }
37: } catch (Exception exc) {
38: exc.printStackTrace();
39: }
40: return mapping.findForward("success");
41: }
42: }
|