Apache Financial ServicesSimple Bank ServletThe Simple Servlet example demonstrates the embedding of a Merlin Kernel within a Servlet and the mechanisms used to get the initial reference to the Apache Financial Service Bank.
Servlet ImplementationThe Servlet implementation extends the Merlin Servlet extension. The Servlet extension establishes the Merlin Kernel and the Servlet implementation includes the logic for extracting the Bank service from the kernel. SimpleServlet.java (init method) /** * Servlet example containing an embedded Merlin Kernel. * * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a> */ public class SimpleServlet extends MerlinServlet { private Bank m_bank; public void init() throws ServletException { super.init(); URL root = (URL) getServletContext().getAttribute( Kernel.BASE_URL_KEY ); if( root == null ) { final String error = "Unable to locate the Merlin Kernel base URL for the supplied context."; throw new ServletException( error ); } try { // // get the bank // URL url = new URL( root, "/banking/bank#org.apache.bank.Bank" ); m_bank = (Bank) url.getContent(); log( "Bank established: " + m_bank ); // // ok - we have bank so we can now create and destroy // accounts - need to think about the best way to move on // from here // } catch( Exception e ) { throw new ServletException( "Bank initialization error.", e ); } } // etc. } |