Author: prasad
Date: Fri Jan 19 19:15:10 2007
New Revision: 498055
URL: http://svn.apache.org/viewvc?view=rev&rev=498055
Log:
* Calculator Servlet to demonstrate dependency injection of an EJB
Added:
geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
(with props)
Added: geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java?view=auto&rev=498055
==============================================================================
--- geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
(added)
+++ geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
Fri Jan 19 19:15:10 2007
@@ -0,0 +1,65 @@
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.samples.calculator;
+
+import java.io.IOException;
+import javax.ejb.EJB;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.geronimo.samples.slsb.calculator.CalculatorLocal;
+
+// A stateful session bean must be declared at the type level
+// whereas a stateless session bean may be declared at any level.
+// @EJB(name="CalculatorLocal", beanInterface=CalculatorLocal.class)
+
+public class CalculatorServlet extends HttpServlet {
+
+ // the ejb container will route every request to different bean instances.
+ @EJB
+ private CalculatorLocal calc;
+
+ public void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ try {
+ String firstNumber = req.getParameter("firstNumber");
+ String secondNumber = req.getParameter("secondNumber");
+ String operation = req.getParameter("operation");
+
+ int firstInt = (firstNumber == null) ? 1 : Integer.valueOf(firstNumber).intValue();
+ int secondInt = (secondNumber == null) ? 1 : Integer.valueOf(secondNumber).intValue();
+
+ if ("multiply".equals(operation) ) {
+ req.setAttribute("result", calc.multiply(firstInt, secondInt));
+ }
+ else if ("add".equals(operation) ) {
+ req.setAttribute("result", calc.sum(firstInt, secondInt));
+ }
+
+ getServletContext().getRequestDispatcher("/").forward(req, resp);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
+ }
+
+}
Propchange: geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/samples/trunk/calculator-stateless-pojo/calculator-stateless-war/src/main/java/org/apache/geronimo/samples/calculator/CalculatorServlet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
|