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.Collection;
022    import java.util.List;
023    import java.util.ArrayList;
024    
025    import javax.ejb.EJB;
026    import javax.persistence.EntityManagerFactory;
027    import javax.persistence.EntityManager;
028    import javax.persistence.PersistenceUnit;
029    import javax.naming.Context;
030    import javax.naming.InitialContext;
031    import javax.naming.NamingException;
032    import javax.servlet.ServletException;
033    import javax.servlet.http.HttpServlet;
034    import javax.servlet.http.HttpServletRequest;
035    import javax.servlet.http.HttpServletResponse;
036    
037    import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal;
038    import org.apache.geronimo.samples.bank.ejb.ExchangeRate;
039    import org.apache.geronimo.samples.bank.ejb.Customer;
040    
041    public class CommonServiceServlet extends HttpServlet {
042            @EJB
043            private BankManagerFacadeLocal bm = null;
044            
045            protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
046                    viewRates(req, res);
047            }
048    
049            protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
050                    doGet(req,res);
051            }
052            
053            private void viewRates(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
054                    String path = "/error.jsp";;
055                    
056                    try {
057                            List<ExchangeRate> rates = (List<ExchangeRate>)bm.getExchangeRates();
058                            req.setAttribute("ratesList", rates);
059    
060                            path = "/exchange_rates.jsp";
061                            
062                    } catch (Exception e) {
063                            e.printStackTrace();
064                    }
065                    getServletContext().getRequestDispatcher(path).forward(req,res);
066            }
067    }