01: package com.sun.portal.search.rdmserver;
02:
03: import java.lang.reflect.*;
04: import java.io.*;
05:
06: /**
07: * Java side of rdmui nsapi - rdmserver bridge.
08: * This is indirectly connected to the RDM server
09: * to allow for connection debugging.
10: */
11: public class TestRDMUIBridge {
12:
13: static Method serviceMethod = null;
14:
15: public static byte[] rdmui_to_srv(byte[] request) {
16:
17: //if (true) return testResponse.getBytes();
18:
19: try {
20: if (serviceMethod == null) {
21: Class cls = Class
22: .forName("com.sun.portal.search.rdmserver.RDMUIBridge");
23: Method[] methods = cls.getMethods();
24: int i = 0;
25: String methodNames = "";
26: for (i = 0; i < methods.length; ++i) {
27: methodNames += methods[i].getName() + " ";
28: if (methods[i].getName().equalsIgnoreCase(
29: "rdmui_to_srv")) {
30: serviceMethod = methods[i];
31: break;
32: }
33: }
34: if (serviceMethod == null)
35: throw new Exception(
36: "RDMUIBridgeDebug failed to connect to RDMUIBridge");
37: }
38: Object[] args = new Object[1];
39: args[0] = request;
40: return (byte[]) serviceMethod.invoke(null, args);
41: }
42: //catch (InvocationTargetException ite) {
43: // throw ite.getTargetException(); // already logged
44: //}
45: catch (Exception e) {
46: // Encapsulate exception in rdm error message since nsapi
47: // can't interpret exception properly.
48: // XXX It doesn't interpret rdm error message either!
49: StringWriter sw = new StringWriter();
50: e.printStackTrace(new PrintWriter(sw));
51: byte[] b = sw.toString().getBytes();
52: String response = errorResponse + "{" + b.length + "}:\t"
53: + new String(b) + "\n}\n";
54: return response.getBytes();
55: }
56: }
57:
58: private final static String errorResponse = "@RDMHEADER { -\n"
59: + "rdm-version{3}: 1.0\n"
60: + "rdm-type{15}: status-response\n" + "rdm-error-message";
61:
62: private final static String testResponse = "@RDMHEADER { -\n"
63: + "catalog-service-id{52}: x-catalog://sunnyeuropa.red.iplanet.com:8890/compass\n"
64: + "rdm-version{3}: 1.0\n"
65: + "rdm-type{11}: rd-response\n"
66: + "rdm-response-interpret{44}: 1 results out of 83 hits across 83 documents"
67: + "}\n"
68: +
69:
70: "@DOCUMENT { http://sunnyeuropa.red.iplanet.com:8890/pdfs/world.123\n"
71: + "content-type{9}: text/html\n"
72: + "content-length{3}: 446\n"
73: + "description{4}: Some\n"
74: + "title{21}: 1 - dec 10 98 expires\n"
75: + "partial-text{18}: Some data here....\n"
76: + "rd-expires{29}: Thu, 10 Dec 1998 01:00:00 GMT\n"
77: + "last-modified{29}: Sat, 11 Dec 1999 03:28:16 GMT\n"
78: + "depth{1}: 1\n"
79: + "classification-1{48}: Robot Class Rules:A. Last Modified:02. by substr\n"
80: + "classification-2{47}: Robot Class Rules:A. Last Modified:05. by-regex\n"
81: + "md5{32}: b7c4db142fda0fb01a8822de88069db4\n"
82: + "rd-last-modified{29}: Sat, 01 Jan 2000 17:51:26 GMT\n"
83: + "}\n";
84:
85: }
|