View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    * 
9    *       http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.geronimo.samples.bank.web;
19  
20  import java.io.IOException;
21  import java.util.List;
22  
23  import javax.ejb.EJB;
24  import javax.naming.Context;
25  import javax.naming.InitialContext;
26  import javax.naming.NamingException;
27  import javax.servlet.ServletException;
28  import javax.servlet.http.HttpServlet;
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal;
33  import org.apache.geronimo.samples.bank.ejb.Customer;
34  import org.apache.geronimo.samples.bank.ejb.Account;
35  
36  
37  public class CustomerServiceServlet extends HttpServlet {
38  	@EJB
39  	private BankManagerFacadeLocal bm = null;
40  
41  	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
42  		viewCustomerInfo(req, res);
43  	}
44  
45  	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
46  		doGet(req,res);
47  	}
48  	
49  	private void viewCustomerInfo(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
50  		String path = "/error.jsp";;
51  		try {
52  			String customerCode = req.getParameter("customerCode");			
53  			
54  			List<Account> accountList = (List<Account>)bm.getAccountInformation(customerCode);
55  			Customer customer = bm.getCustomer(customerCode);
56  			
57  			
58  			if(accountList != null && customer!= null){
59  				
60  				req.setAttribute("accountList",accountList);
61  				req.setAttribute("customerCode",customerCode);
62  				req.setAttribute("customerName",customer.getName());
63  				path = "/customer_info.jsp";
64  				
65  			}
66  			
67  		} catch (Exception e) {
68  			e.printStackTrace();
69  		}		
70  		getServletContext().getRequestDispatcher(path).forward(req,res);
71  	}
72  
73  }