001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.wsif.util;
059:
060: import java.io.InputStream;
061: import java.security.AccessController;
062: import java.security.PrivilegedAction;
063: import java.util.Properties;
064:
065: import org.apache.wsif.WSIFConstants;
066: import org.apache.wsif.logging.Trc;
067:
068: /**
069: * The WSIFProperties class contains various static methods to read
070: * values from the wsif.properties file. Its main purpose is to prevent the
071: * properties file from being read in from disk each time a property is checked.
072: *
073: * @author Ant Elder <antelder@apache.org>
074: */
075: public class WSIFProperties {
076:
077: private static Properties properties;
078:
079: /**
080: * Reads a property from the wsif.properties file.
081: *
082: * @param property the property to read
083: * @return the value of ther property or null if the property is not defined
084: */
085: public static String getProperty(String property) {
086: Trc.entry(null, property);
087: if (properties == null) {
088: properties = (Properties) AccessController
089: .doPrivileged(new PrivilegedAction() {
090: public Object run() {
091: InputStream in = (Thread.currentThread()
092: .getContextClassLoader())
093: .getResourceAsStream(WSIFConstants.WSIF_PROPERTIES);
094:
095: Properties p2 = new Properties();
096: try {
097: p2.load(in);
098: } catch (Exception ignored) {
099: Trc.exception(ignored);
100: return null;
101: }
102: return p2;
103: }
104: });
105: }
106:
107: if (properties == null) {
108: Trc.exit(null);
109: return null;
110: }
111:
112: String s = properties.getProperty(property);
113: Trc.exit(s);
114: return s;
115: }
116:
117: /**
118: * Reads the async request timeout value from the wsif.properties file. This
119: * property defines how long WSIF will keep a WSIFOperation stored in the
120: * correlation service waiting for the reply to a WSIFOperation
121: * executeRequestResponseAsync method call.
122: *
123: * @return the async request timeout value in milliseconds. If the property
124: * is invalid or not defined in the properties file then a value of
125: * zero is returned.
126: */
127: public static long getAsyncTimeout() {
128: Trc.entry(null);
129: long t;
130: try {
131: t = Long
132: .parseLong(getProperty(WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT));
133: if (t < 0) {
134: t = 0;
135: } else {
136: t = t * 1000; // convert to milliseconds
137: }
138: } catch (NumberFormatException e) {
139: Trc.exception(e);
140: t = 0;
141: }
142: Trc.exit(new Long(t));
143: return t;
144: }
145:
146: /**
147: * Reads the synchronous request timeout from the wsif.properties file. This defines
148: * how long (in milliseconds) WSIF will wait for a synchronous response.
149: * Default of 0 means forever.
150: */
151: public static long getSyncTimeout() {
152: Trc.entry(null);
153: long t;
154: try {
155: t = Long
156: .parseLong(getProperty(WSIFConstants.WSIF_PROP_SYNC_TIMEOUT));
157: if (t < 0) {
158: t = 0;
159: }
160: } catch (NumberFormatException e) {
161: Trc.exception(e);
162: t = 0;
163: }
164: Trc.exit(new Long(t));
165: return t;
166: }
167: }
|