001: /**
002: * $Id: WSRPConsumerConfig.java,v 1.13 2005/05/10 17:07:58 jtb Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wsrp.consumer.common;
014:
015: import java.util.Properties;
016: import java.util.Map;
017: import java.util.HashMap;
018: import java.util.Enumeration;
019:
020: import java.io.FileInputStream;
021: import java.io.IOException;
022: import java.io.FileNotFoundException;
023:
024: import javax.servlet.ServletContext;
025:
026: import com.sun.portal.util.ResourceLoader;
027:
028: public class WSRPConsumerConfig {
029:
030: public static final String WSRP_CONSUMER_CONFIG_FILE = "wsrpconsumerconfig.properties";
031:
032: public static final String PERF_LOGLEVEL_KEY = "perfLogLevel";
033:
034: public static final String SOAP_DEBUG_METHOD = "soapDebugMethod";
035:
036: public static final String MM_CLASSNAME = "mmClassname";
037:
038: public static final String PEM_CLASSNAME = "pemClassname";
039:
040: public static final String RSSM_CLASSNAME = "rssmClassname";
041:
042: public static final String ANON_SUPPORTS_INIT_COOKIE = "anonSupportsInitCookie";
043:
044: public static final String FILE_UPLOAD_MAX_SIZE = "fileUploadMaxSize";
045:
046: //
047: // default values (used when there is none defined in the config file
048: //
049: public static final String DEFAULT_MM_CLASSNAME = "com.sun.portal.wsrp.consumer.markup.impl.MarkupManagerImpl";
050:
051: public static final String DEFAULT_PEM_CLASSNAME = "com.sun.portal.wsrp.consumer.producermanager.impl.ProducerEntityManagerImpl";
052:
053: public static final String DEFAULT_RSSM_CLASSNAME = "com.sun.portal.wsrp.consumer.common.impl.StaticRemoteServiceStubManagerImpl";
054:
055: public static final String DEFAULT_SOAP_DUMP_FILENAME = "/tmp/psWSRPConsumerSOAPDump";
056:
057: //
058: // SOAP debugging
059: //
060: public static final int SOAP_DEBUG_NONE = 0;
061:
062: public static final int SOAP_DEBUG_TUNNEL = 1;
063:
064: public static final int SOAP_DEBUG_DUMP = 2;
065:
066: public static final String SOAP_DUMP_FILENAME = "soapDumpFile";
067:
068: public static final String TUNNEL_PREFIX = "tunnel_";
069:
070: public static final String TUNNEL_RSSM_CLASSNAME = "com.sun.portal.wsrp.consumer.common.impl.TunnelRemoteServiceStubManagerImpl";
071:
072: protected static Map tunnelMap = null;
073:
074: protected static int soapDebugMethod = SOAP_DEBUG_NONE;
075:
076: //
077: // static instance
078: //
079: protected static Properties properties = null;
080:
081: protected static WSRPConsumerConfig config = null;
082:
083: protected WSRPConsumerConfig() {
084: }
085:
086: public static void init(ServletContext sc)
087: throws WSRPConsumerException {
088:
089: init(WSRP_CONSUMER_CONFIG_FILE, null);
090: }
091:
092: public static void init(String filename, String portalId)
093: throws WSRPConsumerException {
094: config = new WSRPConsumerConfig();
095: if (filename != null && filename.length() > 0) {
096: config.doInit(filename, portalId);
097: } else {
098: throw new WSRPConsumerException(
099: "WSRPConsumerConfig.init(): properties file name not found.");
100: }
101: }
102:
103: public static WSRPConsumerConfig getInstance() {
104: //
105: // we assume that config has been initialized by the time
106: // this gets called
107: //
108: return config;
109: }
110:
111: protected void doInit(String filename, String portalId)
112: throws WSRPConsumerException {
113: ResourceLoader resourceLoader = null;
114: if (portalId == null) {
115: resourceLoader = ResourceLoader.getInstance(System
116: .getProperties());
117: } else {
118: resourceLoader = ResourceLoader.getInstance(portalId);
119: }
120:
121: try {
122: properties = resourceLoader.getProperties(filename);
123:
124: } catch (FileNotFoundException fnfe) {
125: throw new WSRPConsumerException(
126: "WSRPConsumerConfig.doInit(): ", fnfe);
127: } catch (IOException ioe) {
128: throw new WSRPConsumerException(
129: "WSRPConsumerConfig.doInit(): ", ioe);
130: }
131:
132: soapDebugMethod = initSOAPDebugMethod();
133: tunnelMap = initTunnelMap();
134: }
135:
136: protected int initSOAPDebugMethod() throws WSRPConsumerException {
137:
138: String soapDebugMethod = properties
139: .getProperty(SOAP_DEBUG_METHOD);
140:
141: int method = SOAP_DEBUG_NONE;
142:
143: if (soapDebugMethod.equals("tunnel")) {
144: method = SOAP_DEBUG_TUNNEL;
145: } else if (soapDebugMethod.equals("dump")) {
146: //
147: // not actiavated. (pending jaxrpc bug #5006641)
148: //
149: //method = SOAP_DEBUG_DUMP;
150: method = SOAP_DEBUG_NONE;
151: }
152:
153: return method;
154: }
155:
156: public int getSOAPDebugMethod() {
157:
158: return soapDebugMethod;
159: }
160:
161: protected Map initTunnelMap() throws WSRPConsumerException {
162:
163: Map tMap = new HashMap();
164: for (Enumeration i = properties.propertyNames(); i
165: .hasMoreElements();) {
166: String key = (String) i.nextElement();
167: if (key.startsWith(TUNNEL_PREFIX)
168: && key.length() > TUNNEL_PREFIX.length()) {
169: String tunnelKey = key
170: .substring(TUNNEL_PREFIX.length());
171: tMap.put(tunnelKey, properties.getProperty(key));
172: }
173: }
174:
175: return tMap;
176: }
177:
178: public Map getTunnelMap() {
179:
180: return tunnelMap;
181: }
182:
183: public String getSOAPDumpFilename() throws WSRPConsumerException {
184:
185: String filename = properties.getProperty(SOAP_DUMP_FILENAME);
186:
187: if (filename != null && filename.length() > 0) {
188: return filename;
189: } else {
190: return DEFAULT_SOAP_DUMP_FILENAME;
191: }
192: }
193:
194: public boolean doesAnonSupportInitCookie() {
195: String support = properties
196: .getProperty(ANON_SUPPORTS_INIT_COOKIE);
197: if (support != null && (support.equals("true"))) {
198: return true;
199: } else {
200: return false;
201: }
202: }
203:
204: public int getFileUploadMaxSize() {
205: String fileUploadSizeLimit = properties
206: .getProperty(FILE_UPLOAD_MAX_SIZE);
207:
208: if (fileUploadSizeLimit == null) {
209: return -1;
210: }
211:
212: try {
213: return Integer.parseInt(fileUploadSizeLimit);
214: } catch (NumberFormatException ex) {
215: return -1;
216: }
217: }
218:
219: public String getMarkupManagerClassname() {
220: String mmClassname = properties.getProperty(MM_CLASSNAME);
221: if (mmClassname == null) {
222: mmClassname = DEFAULT_MM_CLASSNAME;
223: }
224:
225: return mmClassname;
226: }
227:
228: public String getProducerEntityManagerClassname() {
229: String pemClassname = properties.getProperty(PEM_CLASSNAME);
230: if (pemClassname == null) {
231: pemClassname = DEFAULT_PEM_CLASSNAME;
232: }
233:
234: return pemClassname;
235: }
236:
237: public String getRemoteServiceStubManagerClassname()
238: throws WSRPConsumerException {
239: String rssmClassname = null;
240:
241: if (getSOAPDebugMethod() == SOAP_DEBUG_TUNNEL) {
242: rssmClassname = TUNNEL_RSSM_CLASSNAME;
243: } else {
244: rssmClassname = properties.getProperty(RSSM_CLASSNAME);
245: }
246:
247: if (rssmClassname == null) {
248: rssmClassname = DEFAULT_RSSM_CLASSNAME;
249: }
250:
251: return rssmClassname;
252: }
253:
254: }
|