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 class
TellerHandlerServlet.CloseAccount
private class
TellerHandlerServlet.CreateAccount
private class
TellerHandlerServlet.CreateAccounts
private class
TellerHandlerServlet.DepositAccount
private class
TellerHandlerServlet.GetAccount
private class
TellerHandlerServlet.GetAccounts
private class
TellerHandlerServlet.GetLedger
private class
TellerHandlerServlet.Handler
private class
TellerHandlerServlet.StealAccounts
private class
TellerHandlerServlet.WithdrawAccount
-
Field Summary
Fields Modifier and Type Field Description static String
ADMIN_TYPE
static String
CLOSE_ACCOUNT_COMMAND
static String
COMMAND_PARAM
static String
CREATE_ACCOUNT_COMMAND
static String
CREATE_ACCOUNTS_COMMAND
static String
DEPOSIT_COMMAND
private static String
ERROR_URL
static String
EXCEPTION_PARAM
static String
GET_ACCOUNT_COMMAND
static String
GET_ACCOUNTS_COMMAND
static String
GET_LEDGER_COMMAND
static String
HANDLER_TYPE_KEY
private Map<String,TellerHandlerServlet.Handler>
handlers
private Teller
injectedTeller
This will get automatically injected when running within the application server with the TellerEJB.static String
jndiName
private static org.slf4j.Logger
logger
static String
STEAL_ALL_ACCOUNTS_COMMAND
private Teller
teller
private static String
UNKNOWN_COMMAND_URL
static String
WITHDRAW_COMMAND
-
Constructor Summary
Constructors Constructor Description TellerHandlerServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
protected void
doGet(HttpServletRequest request, HttpServletResponse response)
This is the main dispatch method for the servlet.protected void
doPost(HttpServletRequest request, HttpServletResponse response)
Since this is a toy, we don't really care whether they call get or post.protected Teller
getTeller()
This helper method will return a Teller in development based on a JNDI lookup.void
init()
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 ServletException
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.- Overrides:
init
in 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:
NamingException
IOException
-
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:
doGet
in classHttpServlet
- Throws:
ServletException
IOException
-
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:
doPost
in classHttpServlet
- Throws:
ServletException
IOException
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceServlet
- Overrides:
destroy
in classGenericServlet
-
-