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: * Initial developer(s): Guillaume Sauthier______________.
022: * Contributor(s): ______________________________________.
023: *
024: * --------------------------------------------------------------------------
025: * $Id: GoogleClientBeanSLR.java 6004 2004-12-20 11:07:52Z sauthieg $
026: * --------------------------------------------------------------------------
027: */package org.objectweb.wssample.beans.wsclient;
028:
029: import java.rmi.RemoteException;
030:
031: import javax.ejb.CreateException;
032: import javax.ejb.SessionBean;
033: import javax.ejb.SessionContext;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037:
038: import org.objectweb.jonas.common.Log;
039: import org.objectweb.util.monolog.api.Logger;
040: import org.objectweb.util.monolog.api.BasicLevel;
041:
042: import org.objectweb.wssample.genbean.google.GoogleSearchResult;
043: import org.objectweb.wssample.genbean.google.GoogleSearchService;
044: import org.objectweb.wssample.genbean.google.GoogleSearchPort;
045:
046: import javax.xml.rpc.ServiceException;
047:
048: /**
049: * GoogleClientBean implementation. This bean use Google WebServices API
050: * to execute a given Query.
051: *
052: * @author Guillaume Sauthier
053: */
054: public class GoogleClientBeanSLR implements SessionBean {
055:
056: /**
057: * logger
058: */
059: private static Logger logger = null;
060:
061: /**
062: * Session Context
063: */
064: private SessionContext ejbContext;
065:
066: // ------------------------------------------------------------------
067: // SessionBean implementation
068: // ------------------------------------------------------------------
069:
070: /**
071: * Set the SessionContext
072: * @param ctx the SessionContext
073: */
074: public void setSessionContext(SessionContext ctx) {
075: if (logger == null) {
076: logger = Log.getLogger("org.objectweb.jonas_tests");
077: }
078: logger.log(BasicLevel.DEBUG, "");
079: ejbContext = ctx;
080: }
081:
082: /**
083: * ejbRemove
084: */
085: public void ejbRemove() {
086: logger.log(BasicLevel.DEBUG, "");
087: }
088:
089: /**
090: * ejbCreate
091: * @throws CreateException CreateException
092: */
093: public void ejbCreate() throws CreateException {
094: logger.log(BasicLevel.DEBUG, "");
095: }
096:
097: /**
098: * ejbPassivate
099: */
100: public void ejbPassivate() {
101: logger.log(BasicLevel.DEBUG, "");
102: }
103:
104: /**
105: * ejbActivate
106: */
107: public void ejbActivate() {
108: logger.log(BasicLevel.DEBUG, "");
109: }
110:
111: // ------------------------------------------------------------------
112: // GoogleClientBean implementation
113: // ------------------------------------------------------------------
114:
115: /**
116: * Execute a Query via Google WS api.
117: *
118: * @param query Query String
119: * @return query results
120: */
121: public GoogleSearchResult executeQuery(java.lang.String query) {
122:
123: logger.log(BasicLevel.INFO, "Executing Google Query '" + query
124: + "'");
125:
126: try {
127:
128: // Get the InitialContext where retrieve Service
129: Context ctx = new InitialContext();
130:
131: // Lookup the service
132: GoogleSearchService google = (GoogleSearchService) ctx
133: .lookup("java:comp/env/service/google");
134:
135: // get Google Port
136: GoogleSearchPort search = google.getGoogleSearchPort();
137:
138: // get Google Key
139: String key = (String) ctx.lookup("java:comp/env/googleKey");
140:
141: // Execute the query
142: return search.doGoogleSearch(key, query, 0, // first index
143: 10, // maxresult
144: false, //filter
145: null, //restrict
146: false, // safesearch
147: null, //lr
148: null, //ie
149: null //oe
150: );
151: } catch (NamingException ne) {
152: return null;
153: } catch (RemoteException re) {
154: return null;
155: } catch (ServiceException se) {
156: return null;
157: }
158: }
159: }
|