01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.search.rdmserver;
07:
08: import com.sun.portal.search.soif.*;
09: import com.sun.portal.search.rdm.*;
10: import com.sun.portal.search.db.*;
11: import com.sun.portal.search.util.*;
12: import com.sun.portal.log.common.PortalLogger;
13:
14: import java.util.*;
15: import java.util.logging.Logger;
16: import java.util.logging.Level;
17: import java.io.*;
18:
19: /**
20: * RDMServerDescriptionService - RDM Message processing facilities: service routing, etc.
21: */
22: public class ServerDescriptionService extends RDMService {
23:
24: RDMServerDescription sd;
25:
26: public ServerDescriptionService() {
27: supportedServices.add(new RDMServiceDescriptor(RDM.RDM_SD_REQ,
28: null));
29: }
30:
31: public void service(RDMRequest req, RDMResponse res)
32: throws Exception {
33:
34: SearchLogger.getLogger().log(Level.FINE, "PSSH_CSPSRDMS0085");
35: boolean dblist_request = false;
36: try {
37: dblist_request = req.getHeader().getSOIF().getValue(
38: "dblist-request").equals("true");
39: } catch (Exception e) {
40: // exception is expected if the attribute was not set.
41: }
42:
43: res.getHeader().setType(RDM.RDM_SD_RES);
44:
45: if (sd == null)
46: loadServerDescription(req, res);
47:
48: // Transmit the RDM Response Header
49: res.sendHeader();
50:
51: if (!dblist_request) {
52: // Send the Server Description
53: res.getOutputStream().write(sd.getSOIF());
54: } else {
55: DbManager.getRootDbEntries(null, res.getOutputStream());
56: }
57: req.logRDM("xfer=1");
58: }
59:
60: synchronized void loadServerDescription(RDMRequest req,
61: RDMResponse res) throws Exception {
62:
63: if (sd != null)
64: return;
65:
66: String csid = req.getHeader().getCSID();
67: String sdfn = null;
68:
69: if ((sdfn = SearchConfig.getValue(SearchConfig.SERVER)) == null) {
70: SearchLogger.getLogger().log(Level.WARNING,
71: "PSSH_CSPSRDMS0086", SearchConfig.SERVER);
72: throw new Exception("Missing server description");
73: }
74:
75: // XXX For plug and play, we need to compare the current service set
76: // to the config set and write out changes with a new time stamp
77: // - why is this even in a file? - should generate dynamically...
78:
79: // Load the RDMServer description XXX not cached?
80: SOIFInputStream ss = null;
81: try {
82: ss = new SOIFInputStream(sdfn);
83: } catch (Exception e) {
84: SearchLogger.getLogger().log(Level.WARNING,
85: "PSSH_CSPSRDMS0087", sdfn);
86: throw e;
87: }
88:
89: try {
90: sd = new RDMServerDescription(ss, null); // XXX use real url
91: } catch (Exception e) {
92: SearchLogger.getLogger().log(Level.WARNING,
93: "PSSH_CSPSRDMS0088", sdfn);
94: throw e;
95: }
96:
97: }
98:
99: }
|