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.Collection;
22  import java.util.List;
23  import java.util.ArrayList;
24  
25  import javax.ejb.EJB;
26  import javax.persistence.EntityManagerFactory;
27  import javax.persistence.EntityManager;
28  import javax.persistence.PersistenceUnit;
29  import javax.naming.Context;
30  import javax.naming.InitialContext;
31  import javax.naming.NamingException;
32  import javax.servlet.ServletException;
33  import javax.servlet.http.HttpServlet;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  
37  import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal;
38  import org.apache.geronimo.samples.bank.ejb.ExchangeRate;
39  import org.apache.geronimo.samples.bank.ejb.Customer;
40  
41  public class CommonServiceServlet extends HttpServlet {
42  	@EJB
43  	private BankManagerFacadeLocal bm = null;
44  	
45  	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
46  		viewRates(req, res);
47  	}
48  
49  	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
50  		doGet(req,res);
51  	}
52  	
53  	private void viewRates(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
54  		String path = "/error.jsp";;
55  		
56  		try {
57  			List<ExchangeRate> rates = (List<ExchangeRate>)bm.getExchangeRates();
58  			req.setAttribute("ratesList", rates);
59  
60  			path = "/exchange_rates.jsp";
61  			
62  		} catch (Exception e) {
63  			e.printStackTrace();
64  		}
65  		getServletContext().getRequestDispatcher(path).forward(req,res);
66  	}
67  }