001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     * 
009     *       http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.samples.bank.web;
019    
020    import java.io.IOException;
021    import java.util.List;
022    
023    import javax.ejb.EJB;
024    import javax.naming.Context;
025    import javax.naming.InitialContext;
026    import javax.naming.NamingException;
027    import javax.servlet.ServletException;
028    import javax.servlet.http.HttpServlet;
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal;
033    import org.apache.geronimo.samples.bank.ejb.Customer;
034    import org.apache.geronimo.samples.bank.ejb.Account;
035    
036    
037    public class CustomerServiceServlet extends HttpServlet {
038            @EJB
039            private BankManagerFacadeLocal bm = null;
040    
041            protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
042                    viewCustomerInfo(req, res);
043            }
044    
045            protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
046                    doGet(req,res);
047            }
048            
049            private void viewCustomerInfo(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
050                    String path = "/error.jsp";;
051                    try {
052                            String customerCode = req.getParameter("customerCode");                 
053                            
054                            List<Account> accountList = (List<Account>)bm.getAccountInformation(customerCode);
055                            Customer customer = bm.getCustomer(customerCode);
056                            
057                            
058                            if(accountList != null && customer!= null){
059                                    
060                                    req.setAttribute("accountList",accountList);
061                                    req.setAttribute("customerCode",customerCode);
062                                    req.setAttribute("customerName",customer.getName());
063                                    path = "/customer_info.jsp";
064                                    
065                            }
066                            
067                    } catch (Exception e) {
068                            e.printStackTrace();
069                    }               
070                    getServletContext().getRequestDispatcher(path).forward(req,res);
071            }
072    
073    }