Source Code Cross Referenced for WsClientServlet.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » wssample » servlets » wsclient » 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 » JOnAS 4.8.6 » org.objectweb.wssample.servlets.wsclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.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: WsClientServlet.java 6004 2004-12-20 11:07:52Z sauthieg $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.wssample.servlets.wsclient;
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.naming.NamingException;
032:        import javax.servlet.ServletConfig;
033:        import javax.servlet.ServletException;
034:        import javax.servlet.http.HttpServlet;
035:        import javax.servlet.http.HttpServletRequest;
036:        import javax.servlet.http.HttpServletResponse;
037:        import javax.xml.rpc.ServiceException;
038:
039:        import org.objectweb.jonas.common.Log;
040:
041:        import org.objectweb.util.monolog.api.Logger;
042:
043:        import org.objectweb.wssample.gen.google.GoogleSearchService;
044:        import org.objectweb.wssample.gen.google.GoogleSearchPort;
045:        import org.objectweb.wssample.gen.google.GoogleSearchResult;
046:        import org.objectweb.wssample.gen.google.ResultElement;
047:
048:        /**
049:         * WebServices Client Servlet
050:         *
051:         * @author Guillaume Sauthier
052:         */
053:        public class WsClientServlet extends HttpServlet {
054:
055:            /**
056:             * logger
057:             */
058:            private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX);
059:
060:            /**
061:             * Initializes the servlet.
062:             * @param config ServletConfig
063:             * @throws ServletException if super.init(config); fails
064:             */
065:            public void init(ServletConfig config) throws ServletException {
066:                super .init(config);
067:            }
068:
069:            /**
070:             * Destroys the servlet.
071:             */
072:            public void destroy() {
073:
074:            }
075:
076:            /**
077:             * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
078:             * methods.
079:             *
080:             * @param request servlet request
081:             * @param response servlet response
082:             *
083:             * @throws ServletException default servlet exception thrown
084:             * @throws IOException default servlet exception thrown
085:             */
086:            protected void processRequest(HttpServletRequest request,
087:                    HttpServletResponse response) throws ServletException,
088:                    IOException {
089:
090:                response.setContentType("text/html");
091:                PrintWriter out = response.getWriter();
092:                // output your page here
093:                out.println("<html>");
094:                out.println("<head>");
095:                out.println("<title>Google WebService Response</title>");
096:                out
097:                        .println("<style type=\"text/css\"> @import \"style/ow_jonas.css\"; </style>");
098:                out.println("</head>");
099:                out.println("<body class=\"bodywelcome\">");
100:
101:                out.println("<div class=\"logos\">");
102:                out
103:                        .println("<a href=\"http://jakarta.apache.org\"><img title=\"Jakarta Tomcat\" alt=\"Jakarta Tomcat\" src=\"images/tomcat.gif\" /></a>");
104:                out
105:                        .println("<a href=\"http://jetty.mortbay.org/jetty/\"><img title=\"Mortbay Jetty\" alt=\"Mortbay Jetty\" src=\"images/jetty.gif\" /></a>");
106:                out
107:                        .println("<a href=\"http://jonas.objectweb.org\"><img title=\"JOnAS WebSite\" alt=\"JOnAS WebSite\" src=\"images/ow_jonas_logo.gif\" /></a>");
108:                out.println("</div>");
109:
110:                // Get and Display results
111:                try {
112:                    // Get the Context
113:                    Context ctx = new InitialContext();
114:
115:                    String key = (String) ctx.lookup("java:comp/env/key");
116:
117:                    // Lookup the binded service
118:                    Object s = ctx.lookup("java:comp/env/service/google");
119:                    GoogleSearchService google = (GoogleSearchService) s;
120:
121:                    // get the Port object
122:                    GoogleSearchPort search = google.getGoogleSearchPort();
123:
124:                    // execute the query
125:                    GoogleSearchResult result = search.doGoogleSearch(key,
126:                            request.getParameter("search"), 0, // first
127:                            // index
128:                            10, // maxresult
129:                            false, //filter
130:                            null, //restrict
131:                            false, // safesearch
132:                            null, //lr
133:                            null, //ie
134:                            null //oe
135:                            );
136:
137:                    out.println("<div class=\"titlepage\">Results</div>");
138:                    out.println("<div class=\"links\">");
139:
140:                    // Display the results
141:                    ResultElement[] elements = result.getResultElements();
142:                    for (int i = 0; i < elements.length; i++) {
143:                        out.println("<i><a href=\"" + elements[i].getURL()
144:                                + "\">" + elements[i].getTitle()
145:                                + "</a></i><br/>");
146:                        out.println(elements[i].getSummary() + "<br/><br/>");
147:                    }
148:                    out.println("</div>");
149:
150:                } catch (NamingException ne) {
151:                    out
152:                            .println("<div class=\"titlepage\">Error when looking for service-ref</div>");
153:                    ne.printStackTrace(out);
154:                } catch (ServiceException se) {
155:                    out
156:                            .println("<div class=\"titlepage\">Error when performign service-ref</div>");
157:                    se.printStackTrace(out);
158:                }
159:
160:                out.println("</body>");
161:                out.println("</html>");
162:                out.close();
163:            }
164:
165:            /**
166:             * Handles the HTTP <code>GET</code> method.
167:             *
168:             * @param request servlet request
169:             * @param response servlet response
170:             *
171:             * @throws ServletException default servlet exception thrown
172:             * @throws IOException default servlet exception thrown
173:             */
174:            protected void doGet(HttpServletRequest request,
175:                    HttpServletResponse response) throws ServletException,
176:                    IOException {
177:                processRequest(request, response);
178:            }
179:
180:            /**
181:             * Handles the HTTP <code>POST</code> method.
182:             *
183:             * @param request servlet request
184:             * @param response servlet response
185:             *
186:             * @throws ServletException default servlet exception thrown
187:             * @throws IOException default servlet exception thrown
188:             */
189:            protected void doPost(HttpServletRequest request,
190:                    HttpServletResponse response) throws ServletException,
191:                    IOException {
192:                processRequest(request, response);
193:            }
194:
195:            /**
196:             * @return Returns a short description of the servlet.
197:             */
198:            public String getServletInfo() {
199:                return "Servlet which is client of the WebServices API of Google";
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.