Source Code Cross Referenced for ClientServletStateless.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » examples » statelessbean » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » ow2 easybeans » org.ow2.easybeans.examples.statelessbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: ClientServletStateless.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.examples.statelessbean;
025:
026:        import java.io.IOException;
027:        import java.io.PrintWriter;
028:
029:        import javax.naming.Context;
030:        import javax.naming.InitialContext;
031:        import javax.servlet.ServletException;
032:        import javax.servlet.http.HttpServlet;
033:        import javax.servlet.http.HttpServletRequest;
034:        import javax.servlet.http.HttpServletResponse;
035:
036:        /**
037:         * Servlet's client for the stateless session bean.
038:         * @author Florent Benoit
039:         */
040:        public class ClientServletStateless extends HttpServlet {
041:
042:            /**
043:             * Serializable class uid.
044:             */
045:            private static final long serialVersionUID = 6893863749912962928L;
046:
047:            /**
048:             * Called by the server (via the service method) to allow a servlet to
049:             * handle a GET request.
050:             * @param request an HttpServletRequest object that contains the request the
051:             *        client has made of the servlet
052:             * @param response an HttpServletResponse object that contains the response
053:             *        the servlet sends to the client
054:             * @throws IOException if an input or output error is detected when the
055:             *         servlet handles the GET request
056:             * @throws ServletException if the request for the GET could not be handled
057:             */
058:            @Override
059:            public void doGet(final HttpServletRequest request,
060:                    final HttpServletResponse response) throws IOException,
061:                    ServletException {
062:
063:                response.setContentType("text/html");
064:                PrintWriter out = response.getWriter();
065:                out.println("<html>");
066:                out.println("<head>");
067:                out.println("<title>");
068:                out.println("Client of stateless session bean</title>");
069:                out.println("</head>");
070:                out.println("<body>");
071:
072:                // no operation ? displays button for hello world and calculator
073:                String operation = request.getParameter("operation");
074:                if (operation != null) {
075:                    if (operation.equals("helloWorld")) {
076:                        displayHelloWorld(out);
077:                    } else if (operation.equals("add")) {
078:                        // get two parameters
079:                        String param1 = request.getParameter("p1");
080:                        String param2 = request.getParameter("p2");
081:                        if (param1 != null && param2 != null) {
082:                            int v1 = Integer.parseInt(param1);
083:                            int v2 = Integer.parseInt(param2);
084:                            displayResult(out, v1, v2);
085:                        } else {
086:                            out.println("Missing values for operation add");
087:                        }
088:                    }
089:                }
090:                out.println("<hr width=\"80%\"/>");
091:                displayDefault(out);
092:
093:                out.println("</body>");
094:                out.println("</html>");
095:                out.close();
096:            }
097:
098:            /**
099:             * Call HelloWorld method.
100:             * @param out the given writer
101:             */
102:            private void displayHelloWorld(final PrintWriter out) {
103:                out.println("Calling helloWorld() method");
104:                out.println("<br>");
105:                try {
106:                    getBean().helloWorld();
107:                    out.println("helloWorld() method called OK.");
108:                } catch (Exception e) {
109:                    displayException(out, "Cannot call helloworld on the bean",
110:                            e);
111:                }
112:            }
113:
114:            /**
115:             * By default, call helloWorld method.
116:             * @param out the given writer
117:             */
118:            private void displayDefault(final PrintWriter out) {
119:                out
120:                        .println("<form method=get action=\"\" enctype=\"multipart/form-data\">");
121:                out.println("sum of a + b :");
122:                out
123:                        .println("<p><input type=hidden name=\"operation\" value=\"add\"></p>");
124:                out.println("<p><input type=text name=p1 value=\"1\"></p>");
125:                out.println("<p><input type=text name=p2 value=\"2\"></p>");
126:                out.println("<p><input type=submit value=\"add !\"></p>");
127:                out.println("</form>");
128:                out
129:                        .println("<form method=get action=\"\" enctype=\"multipart/form-data\">");
130:                out
131:                        .println("<p><input type=hidden name=\"operation\" value=\"helloWorld\"></p>");
132:                out
133:                        .println("<p><input type=submit value=\"hello world !\"></p>");
134:                out.println("</form>");
135:            }
136:
137:            /**
138:             * Prints he result of the sum of val1 and val2.
139:             * @param out the given writer
140:             * @param val1 first arg for add method
141:             * @param val2 second arg for add method
142:             */
143:            private void displayResult(final PrintWriter out, final int val1,
144:                    final int val2) {
145:                out.println("<br> Sum of '" + val1 + "' and '" + val2 + "' = ");
146:                try {
147:                    int sum = getBean().add(val1, val2);
148:                    out.println(sum);
149:                } catch (Exception e) {
150:                    displayException(out,
151:                            "<br>Cannot call add() method on the bean", e);
152:                }
153:            }
154:
155:            /**
156:             * If there is an exception, print the exception.
157:             * @param out the given writer
158:             * @param errMsg the error message
159:             * @param e the content of the exception
160:             */
161:            private void displayException(final PrintWriter out,
162:                    final String errMsg, final Exception e) {
163:                out.println("<p>Exception : " + errMsg);
164:                out.println("<pre>");
165:                e.printStackTrace(out);
166:                out.println("</pre></p>");
167:            }
168:
169:            /**
170:             * Lookup the stateless bean and gets a reference on it.
171:             * @return the stateless bean business interface.
172:             * @throws Exception if the bean cannot be retrieved.
173:             */
174:            private StatelessRemote getBean() throws Exception {
175:                Context initialContext = new InitialContext();
176:                Object o = initialContext
177:                        .lookup("org.ow2.easybeans.examples.statelessbean.StatelessBean"
178:                                + "_"
179:                                + StatelessRemote.class.getName()
180:                                + "@Remote");
181:
182:                if (o instanceof  StatelessRemote) {
183:                    StatelessRemote statelessBean = (StatelessRemote) o;
184:                    return statelessBean;
185:                }
186:                throw new Exception("Cannot cast object into StatelessRemote");
187:
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.