Class TellerHandlerServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- ejava.examples.ejbsessionbank.web.TellerHandlerServlet
-
- All Implemented Interfaces:
Serializable,Servlet,ServletConfig
public class TellerHandlerServlet extends HttpServlet
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classTellerHandlerServlet.CloseAccountprivate classTellerHandlerServlet.CreateAccountprivate classTellerHandlerServlet.CreateAccountsprivate classTellerHandlerServlet.DepositAccountprivate classTellerHandlerServlet.GetAccountprivate classTellerHandlerServlet.GetAccountsprivate classTellerHandlerServlet.GetLedgerprivate classTellerHandlerServlet.Handlerprivate classTellerHandlerServlet.StealAccountsprivate classTellerHandlerServlet.WithdrawAccount
-
Field Summary
Fields Modifier and Type Field Description static StringADMIN_TYPEstatic StringCLOSE_ACCOUNT_COMMANDstatic StringCOMMAND_PARAMstatic StringCREATE_ACCOUNT_COMMANDstatic StringCREATE_ACCOUNTS_COMMANDstatic StringDEPOSIT_COMMANDprivate static StringERROR_URLstatic StringEXCEPTION_PARAMstatic StringGET_ACCOUNT_COMMANDstatic StringGET_ACCOUNTS_COMMANDstatic StringGET_LEDGER_COMMANDstatic StringHANDLER_TYPE_KEYprivate Map<String,TellerHandlerServlet.Handler>handlersprivate TellerinjectedTellerThis will get automatically injected when running within the application server with the TellerEJB.static StringjndiNameprivate static org.slf4j.Loggerloggerstatic StringSTEAL_ALL_ACCOUNTS_COMMANDprivate Tellertellerprivate static StringUNKNOWN_COMMAND_URLstatic StringWITHDRAW_COMMAND
-
Constructor Summary
Constructors Constructor Description TellerHandlerServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()protected voiddoGet(HttpServletRequest request, HttpServletResponse response)This is the main dispatch method for the servlet.protected voiddoPost(HttpServletRequest request, HttpServletResponse response)Since this is a toy, we don't really care whether they call get or post.protected TellergetTeller()This helper method will return a Teller in development based on a JNDI lookup.voidinit()Init verify the teller reference to the EJB logic is in place and initializes the proper handler for the assigned role supplied in the servlet init parameters.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
COMMAND_PARAM
public static final String COMMAND_PARAM
- See Also:
- Constant Field Values
-
EXCEPTION_PARAM
public static final String EXCEPTION_PARAM
- See Also:
- Constant Field Values
-
HANDLER_TYPE_KEY
public static final String HANDLER_TYPE_KEY
- See Also:
- Constant Field Values
-
ADMIN_TYPE
public static final String ADMIN_TYPE
- See Also:
- Constant Field Values
-
CREATE_ACCOUNT_COMMAND
public static final String CREATE_ACCOUNT_COMMAND
- See Also:
- Constant Field Values
-
DEPOSIT_COMMAND
public static final String DEPOSIT_COMMAND
- See Also:
- Constant Field Values
-
WITHDRAW_COMMAND
public static final String WITHDRAW_COMMAND
- See Also:
- Constant Field Values
-
GET_ACCOUNT_COMMAND
public static final String GET_ACCOUNT_COMMAND
- See Also:
- Constant Field Values
-
CLOSE_ACCOUNT_COMMAND
public static final String CLOSE_ACCOUNT_COMMAND
- See Also:
- Constant Field Values
-
GET_ACCOUNTS_COMMAND
public static final String GET_ACCOUNTS_COMMAND
- See Also:
- Constant Field Values
-
CREATE_ACCOUNTS_COMMAND
public static final String CREATE_ACCOUNTS_COMMAND
- See Also:
- Constant Field Values
-
GET_LEDGER_COMMAND
public static final String GET_LEDGER_COMMAND
- See Also:
- Constant Field Values
-
STEAL_ALL_ACCOUNTS_COMMAND
public static final String STEAL_ALL_ACCOUNTS_COMMAND
- See Also:
- Constant Field Values
-
jndiName
public static final String jndiName
-
UNKNOWN_COMMAND_URL
private static final String UNKNOWN_COMMAND_URL
- See Also:
- Constant Field Values
-
ERROR_URL
private static final String ERROR_URL
- See Also:
- Constant Field Values
-
handlers
private Map<String,TellerHandlerServlet.Handler> handlers
-
injectedTeller
private Teller injectedTeller
This will get automatically injected when running within the application server with the TellerEJB. beanInterface is only needed to resolve the derived type ambiguity for Local and Remote caused by the design of our example.
-
teller
private Teller teller
-
-
Method Detail
-
init
public void init() throws ServletExceptionInit verify the teller reference to the EJB logic is in place and initializes the proper handler for the assigned role supplied in the servlet init parameters.- Overrides:
initin classGenericServlet- Throws:
ServletException
-
getTeller
protected Teller getTeller() throws NamingException, IOException
This helper method will return a Teller in development based on a JNDI lookup.- Returns:
- teller if found
- Throws:
NamingExceptionIOException
-
doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
This is the main dispatch method for the servlet. It expects to find a command keyed by an argument in the request parameters.- Overrides:
doGetin classHttpServlet- Throws:
ServletExceptionIOException
-
doPost
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Since this is a toy, we don't really care whether they call get or post.- Overrides:
doPostin classHttpServlet- Throws:
ServletExceptionIOException
-
destroy
public void destroy()
- Specified by:
destroyin interfaceServlet- Overrides:
destroyin classGenericServlet
-
-