001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.rdmserver;
007:
008: import com.sun.portal.search.rdm.*;
009: import com.sun.portal.search.soif.*;
010: import com.sun.portal.search.util.*;
011: import com.sun.portal.log.common.PortalLogger;
012:
013: import java.io.*;
014: import java.util.*;
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017: import java.text.*;
018: import java.net.*;
019:
020: /**
021: * TestRDMServer:
022: * Server-side glue for RDM written for command line invocation.
023: * Routes the unencapsulated RDM to the appropriate process,
024: * and returns RDM response.
025: *
026: * Usage:
027: * TestRDMServer [-h serverroot]
028: * (reads commands from stdin)
029: *
030: * Commands:
031: * blah
032: *
033: */
034: public class TestRDMServer {
035:
036: // RDM objects - one of each
037: RDMContext rdmcontext;
038: RDMServer rdmserver;
039: RDMConfig rdmconfig;
040:
041: public TestRDMServer(String serverroot) throws Exception {
042:
043: try {
044: rdmcontext = new TestRDMContext(serverroot);
045: rdmconfig = rdmcontext.getRDMConfig();
046: rdmserver = new RDMServer(rdmcontext);
047: rdmserver.init(rdmconfig);
048: } catch (Exception e) {
049: SearchLogger.getLogger().log(Level.WARNING,
050: "PSSH_CSPSRDMS0131", e);
051: if (rdmcontext != null)
052: rdmcontext.log("RDM Server failed to start", e);
053: throw e;
054: }
055: SearchLogger.getLogger().log(Level.SEVERE, "PSSH_CSPSRDMS0132",
056: rdmserver.getVersion());
057: //rdmcontext.log("RDM Server is on-line: " + rdmserver.getVersion());
058: }
059:
060: /** Destroys the servlet. */
061: public void destroy() {
062: // XXX close db, etc
063: }
064:
065: /** Handles the HTTP <code>GET</code> method.
066: * @param request servlet request
067: * @param response servlet response
068: */
069: protected void doGet(String queryString, SOIFOutputStream response)
070: throws Exception {
071: RDMRequest rdmrequest = null;
072: try {
073: rdmrequest = RDMServlet.buildRDMRequest(queryString);
074: } catch (Exception e) {
075: throw new Exception(
076: "Did not receive valid RDM Request - GET method\n"
077: + e);
078: }
079: processRDMRequest(rdmrequest, response);
080: }
081:
082: /** Handles the HTTP <code>POST</code> method.
083: * @param request servlet request
084: * @param response servlet response
085: */
086: protected void doPost(SOIFInputStream request,
087: SOIFOutputStream response) throws Exception {
088: RDMRequest rdmrequest = null;
089: try {
090: rdmrequest = new RDMRequest(request);
091: } catch (Exception e) {
092: throw new Exception(
093: "Did not receive valid RDM Request - POST method\n"
094: + e);
095: }
096: processRDMRequest(rdmrequest, response);
097: }
098:
099: /**
100: * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
101: * @param request servlet request
102: * @param response servlet response
103: */
104: protected void processRDMRequest(RDMRequest req,
105: SOIFOutputStream response) throws Exception,
106: java.io.IOException {
107: SearchLogger.getLogger().log(Level.INFO, "PSSH_CSPSRDMS0133");
108: try {
109: // Create the RDM Response
110: RDMResponse res = new RDMResponse(new SOIFOutputStream(
111: response));
112: res.getHeader().setCSID(req.getHeader().getCSID());
113:
114: // Service the request
115: rdmserver.service(req, res);
116: } catch (Exception e) {
117: // XXX CSLog ?
118: SearchLogger.getLogger().log(Level.WARNING,
119: "PSSH_CSPSRDMS0046", e);
120: //rdmcontext.log("Exception: rdm-service", e);
121: // XXX for debugging only...
122: //throw new Exception(""+e);
123: //System.exit(1); XXX ???
124: } finally {
125: SearchLogger.getLogger().log(Level.INFO,
126: "PSSH_CSPSRDMS0134");
127: }
128: }
129:
130: static final int SOIFRequestMode = 0;
131: static final int QueryRequestMode = 1;
132: static final int SOIFPostMode = 2;
133:
134: static public void main(String[] args) throws Exception {
135:
136: String serverroot = null;
137: int cmdmode = QueryRequestMode;
138:
139: for (int i = 0; i < args.length; ++i) {
140: if (args[i].equals("-h")) {
141: serverroot = args[++i];
142: continue;
143: }
144: if (args[i].equals("-c")) {
145: cmdmode = SOIFRequestMode;
146: continue;
147: }
148: if (args[i].equals("-p")) {
149: cmdmode = SOIFPostMode;
150: continue;
151: }
152: System.out
153: .println("Usage: TestRDMServer [-h serverroot] [-p]");
154: System.out
155: .println(" serverroot = server root directory (default: '.')");
156: System.out
157: .println(" -c = read commands from SOIF RDM requests (default query string lines)");
158: System.out.println(" -p = canned post (status request)");
159: System.exit(0);
160: }
161:
162: TestRDMServer rdmcli = new TestRDMServer(serverroot);
163: SOIFOutputStream response = new SOIFOutputStream(System.out);
164:
165: // XXX need a thread pool here
166:
167: BufferedReader cmdRdr = null;
168: SOIFInputStream cmdStream = null;
169:
170: if (cmdmode == QueryRequestMode) {
171: cmdRdr = new BufferedReader(
172: new InputStreamReader(System.in));
173: } else if (cmdmode == SOIFRequestMode) {
174: cmdStream = new SOIFInputStream(System.in);
175: }
176:
177: String[] get_queries = {
178: "type=status-request",
179: "type=server-request",
180: "type=schema-request",
181: "type=schema-request&va=In-Root-Table", // XXX case sensitivite - need to fix
182: "type=taxonomy-request",
183: "type=rd-request&ql=url&scope=http://w3.mcom.com:80/~mikeb/argon/catprox/proxy/current/unix/",
184: "type=rd-request&va=Title,url&ql=url&scope=http://w3.mcom.com:80/~mikeb/argon/catprox/proxy/current/unix/",
185: "type=rd-request&ql=url&scope=TEST_NON_EXISTENT",
186: "type=rd-request&ql=search&scope=java&view-hits=-1",
187: "type=rd-request&ql=search&scope=*&view-hits=-1",
188: "type=bogus",
189: "typo=bogus",
190: "type=rd-request&ql=XXXXX&scope=http://w3.mcom.com:80/~mikeb/argon/catprox/proxy/current/unix/",
191: "type=rd-request&ql=search&scope=java",
192: "type=rd-request&ql=search&scope=java&va=title,score",
193: "type=rd-request&ql=search&scope=java&va=title,score&vo=+title,-score",
194: "type=rd-request&ql=search&scope=java&va=title,score&vo=+title,-score&search-category=Internal:Engineering:Java",
195: "type=rd-request&ql=nsir&scope=java&va=title,score",
196: "type=rd-request&ql=verity&scope=java&va=title,score",
197: "type=rd-request&ql=verity-ql&scope=java&va=title,score",
198: "type=rd-request&ql=gatherer&scope=XXXXX&va=title,score",
199: "type=rd-request&ql=gatherer&scope=all&va=title,score",
200: "type=rd-request&ql=gatherer&scope=since 1/1/01 12:1:17&va=title,score",
201: "type=rd-request&ql=gatherer&scope=\"since BAD DATE XXX\"&va=title,score",
202: "type=rd-request&ql=gatherer&scope=\"since Sat, 12 Aug 1995 13:30:00 GMT\"&va=title,score",
203: "type=rd-request&ql=subtree&scope=descendant+Internal:Engineering:Java%0d%0ajava&va=title,score",
204: "type=rd-request&ql=subtree&scope=descendant+ROOT%0d%0ajava&va=title,score",
205: "type=rd-request&ql=subtree&scope=descendant+Internal:Engineering:Java%0d%0a&va=title,score",
206: "type=taxonomy-request&ql=search&scope=java&va=id,score",
207: "type=taxonomy-request&ql=search&scope=*&va=id,score",
208: "type=taxonomy-request&ql=taxonomy-basic&scope=advise-doc-count/4+Internal:Engineering:Java",
209: "type=taxonomy-request&ql=taxonomy-basic&scope=children+ROOT",
210: "type=taxonomy-request&ql=taxonomy-basic&scope=children+ROOT&vh=1..20&va=id,Parent-Id",
211: "type=taxonomy-request&ql=taxonomy-basic&scope=descendant/2+ROOT&vh=5",
212: "type=taxonomy-request&ql=taxonomy-basic&scope=children+Internal",
213: "type=taxonomy-request&ql=taxonomy-basic&scope=children+Internal&vh=3",
214: "type=taxonomy-request&ql=taxonomy-basic&scope=children+Internal&vh=1..3",
215: "type=taxonomy-request&ql=taxonomy-basic&scope=children+Internal&vh=3..4&va=id,Parent-Id",
216: "type=rd-request&ql=search&scope=java+toolxxxs&va=id,score",
217: "type=rd-request&ql=search&scope=worker&view-hits=11..20&va=id,score",
218: "type=rd-request&ql=search&scope=worker&view-hits=81..88&va=id,score",
219: "type=rd-request&ql=search&scope=worker&va=id,score",
220: "type=rd-request&ql=search&scope=java&va=title,gv-rating&vo=-gv-rating",
221: "type=rd-request&ql=search&scope=java&va=title&database=default",
222: "type=rd-request&ql=search&scope=java&va=title&database=db1",
223: "type=rd-request&ql=search&scope="
224: + Encoder.urlEncode(
225: "\u0430\u0431\u0432\u0433\u00c0",
226: "UTF-8") + "&va=title",
227: "type=rd-request&ql=search&scope=%D0%B4&va=title", // invalid utf-8
228: "type=rd-request&ql=search&scope=%26%2353428%3B&va=title",
229: "type=rd-request&ql=search&scope=%C3%B1&va=title", // utf-8 for ?
230: "type=rd-request&ql=search&scope=?&va=title", // iso8859-1 for ?
231: "type=rd-request&ql=search&scope=?&va=title&lang=en;iso8859-1", // iso8859-1 for ?
232: "type=rd-request&ql=search&scope=%26%23D0B4%3B&va=title",
233: "type=rd-request&ql=search&scope=%26%2326494%3B&va=title",
234: "type=rd-request&ql=search&scope="
235: + Encoder.urlEncode("\u7247\u8c9d", "UTF-8"),
236: "type=rd-request&ql=search&scope="
237: + Encoder.urlEncode("\u7247\u8c9d", "UTF-8")
238: + "&va=title,description,passage,hit-terms",
239: "type=rd-request&ql=search&scope=tuna&va=title,description,passage,hit-terms&hl=true",
240: "type=rd-request&ql=search&scope=*&va=hl-title,classification,hl-classification,hl-description",
241: "type=rd-request&ql=search&scope=<passage>java&va=hl-title,classification,hl-classification,hl-description",
242: "type=rd-request&ql=search&scope=<passage>yahoo+regional&va=hl-title,classification,hl-classification,hl-description",
243: "type=rd-request&ql=search&scope=java+internal+tools&va=title,hl-title,classification,hl-classification,description,hl-description",
244: "type=rd-request&ql=search&scope=<passage>java+internal+tools&va=title,hl-title,classification,hl-classification,hl-description",
245: "type=rd-request&ql=search&scope=java+arrays&va=title,classification,description,passage,hit-terms&hl=true",
246: "type=rd-request&ql=search&scope=*&va=title,description,passage,hit-terms&hl=true",
247: "type=rd-request&ql=search&scope=<passage>java&va=title,description,passage,hit-terms",
248: "type=rd-request&ql=search&scope=<passage>java+internal+tools+arrays&va=title,classification,hl-description,passage,passage-score,hit-terms,highlights&hl=true",
249: "type=rd-request&ql=search&scope=<passage>a*&va=title,classification,hl-description,passage,passage-score,hit-terms,highlights&hl=true",
250: "type=rd-request&ql=search&scope=<passage>java+arrays&va=title,description,passage,passage-score,hit-terms,highlights&hl=true&hlt=*,*,[,],(,)",
251: "type=rd-request&ql=search&scope=<passage>java&va=hl-description,passage,passage-score,hit-terms,highlights,&hl=true",
252: "type=rd-request&ql=search&scope=url<matches>*thompson*&va=title,hl-description,passage,passage-score,hit-terms,highlights,&hl=true",
253: "type=rd-request&ql=search&scope="
254: + Encoder
255: .urlEncode(
256: "http://hbombsgi.mcom.com:6666/annalee/build_mut/ns/netsite/config",
257: "UTF-8") + "&va=url",
258: "type=rd-request&ql=search&scope=http%3A%2F%2Fhbombsgi.mcom.com%3A6666%2Fannalee%2Fbuild_mut%2Fns%2Fnetsite%2Fconfig",
259: "type=rd-request&ql=search&scope=rd-last-changed > \"Tuesday, February 03, 2004 10:41:59 GMT\"",
260: "",
261: "fed search",
262: "type=rd-request&ql=search&scope=rawling&database=jndi-sun",
263: "type=rd-request&ql=search&scope=java&database=google",
264: "", null, };
265:
266: String[] post_queries = {
267: "type=status-request",
268: "type=server-request",
269: "type=schema-request",
270: "type=schema-request&va=In-Root-Table", // XXX case sensitivite - need to fix
271: "type=taxonomy-request",
272: "type=rd-request&ql=url&scope=http://w3.mcom.com:80/~mikeb/argon/catprox/proxy/current/unix/",
273: "type=rd-request&va=Title,url&ql=url&scope=http://w3.mcom.com:80/~mikeb/argon/catprox/proxy/current/unix/",
274: "", null, };
275:
276: for (int i = 0; i < get_queries.length; ++i) {
277: System.out.println("" + i + ": " + get_queries[i]);
278: }
279:
280: for (;;) {
281: try {
282: if (cmdmode == QueryRequestMode) {
283: String query = cmdRdr.readLine();
284: if (query.equals("x"))
285: break;
286: else if (query.equals("g")) {
287: cmdmode = QueryRequestMode;
288: continue;
289: } else if (query.equals("p")) {
290: cmdmode = SOIFPostMode;
291: continue;
292: } else if (query.equals("?")) {
293: if (cmdmode == QueryRequestMode) {
294: for (int i = 0; i < get_queries.length; ++i) {
295: System.out.println("" + i + ": "
296: + get_queries[i]);
297: }
298: } else if (cmdmode == SOIFPostMode) {
299: for (int i = 0; i < post_queries.length; ++i) {
300: System.out.println("" + i + ": "
301: + get_queries[i]);
302: }
303: }
304: continue;
305: }
306: if (query.length() <= 2)
307: query = get_queries[Integer.parseInt(query)];
308: rdmcli.doGet(query, response);
309: } else if (cmdmode == SOIFRequestMode)
310: rdmcli.doPost(cmdStream, response);
311: else if (cmdmode == SOIFPostMode) {
312: String query = cmdRdr.readLine();
313: if (query.equals("x"))
314: break;
315: else if (query.equals("g")) {
316: cmdmode = QueryRequestMode;
317: continue;
318: } else if (query.equals("p")) {
319: cmdmode = SOIFPostMode;
320: continue;
321: } else if (query.equals("?")) {
322: for (int i = 0; i < post_queries.length; ++i) {
323: System.out.println("" + i + ": "
324: + post_queries[i]);
325: }
326: continue;
327: }
328: //if (query.length() <= 2)
329: //query = post_queries[Integer.parseInt(query)];
330: String postdata = null;
331: switch (Integer.parseInt(query)) {
332: case 0:
333: postdata = "-------1234\r\n\r\n@RDMHEADER { -\r\nrdm-type{14}:\tstatus-request\r\n}\r\n\r\n----1234\r\n";
334: break;
335: case 1:
336: postdata = "-------1234\r\n\r\n"
337: + "@RDMHEADER { -\r\nrdm-type{17}:\trd-submit-request\r\n}\r\n"
338: // no request object
339: + "@DOCUMENT { car1\n"
340: + "title{4}:\tcar1\n"
341: + "partial-text{21}:\tthis is car1 car cars\n"
342: + "}\n" + "\r\n----1234\r\n";
343: break;
344: case 2:
345: postdata = "@RDMHEADER { -\r\nrdm-type{17}:\trd-submit-request\r\n}\r\n"
346: + "@REQUEST { -\n"
347: + "submit-type{13}:\tnonpersistent\n"
348: + "submit-operation{4}:\tblah\n" // invalid op
349: + "}\n"
350: + "@DOCUMENT { car1\n"
351: + "title{4}:\tcar1\n"
352: + "partial-text{21}:\tthis is car1 car cars\n"
353: + "}\n" + "\r\n----1234\r\n";
354: break;
355: case 3:
356: postdata = "@RDMHEADER { -\r\nrdm-type{17}:\trd-submit-request\r\n}\r\n"
357: + "@REQUEST { -\n"
358: + "submit-type{13}:\tnonpersistent\n"
359: + "submit-operation{8}:\tretrieve\n"
360: + "}\n"
361: + "@DOCUMENT { car1\n"
362: + "}\n"
363: + "\r\n----1234\r\n";
364: break;
365: }
366: SOIFInputStream postStream = new SOIFInputStream(
367: postdata.getBytes());
368: rdmcli.doPost(postStream, response);
369: }
370: } catch (Exception e) {
371: e.printStackTrace();
372: break;
373: }
374: }
375: rdmcli.destroy();
376: }
377:
378: }
|