continue;
if ( managers[i].sameProperties(p) )
return managers[i].getManager();
}
// Get the props we will initialize from:
ObservableProperties props = null;
if ( p instanceof ObservableProperties )
props = (ObservableProperties) p;
else
props = new ObservableProperties(p);
// Create a new manager for this set of properties:
HttpManager manager = null;;
try {
Object o = managerclass.newInstance();
if (o instanceof HttpManager) {
manager = (HttpManager) o;
} else { // default value
manager = new HttpManager();
}
} catch (Exception ex) {
ex.printStackTrace();
manager = new HttpManager();
}
manager.props = props;
// Initialize this new manager filters:
String filters[] = props.getStringArray(FILTERS_PROP_P, null);
if ( filters != null ) {
for (int i = 0 ; i < filters.length ; i++) {
try {
Class c = Class.forName(filters[i]);
PropRequestFilter f = null;
f = (PropRequestFilter) c.newInstance();
f.initialize(manager);
} catch (PropRequestFilterException ex) {
System.out.println("Couldn't initialize filter \""
+ filters[i]
+ "\" init failed: "
+ ex.getMessage());
} catch (Exception ex) {
System.err.println("Error initializing prop filters:");
System.err.println("Coulnd't initialize ["
+ filters[i]
+ "]: " + ex.getMessage());
ex.printStackTrace();
System.exit(1);
}
}
}
// The factory to create MIME reply holders:
manager.factory = manager.getReplyFactory();
// The class to create HttpServer instances from
String c = props.getString(SERVER_CLASS_P, DEFAULT_SERVER_CLASS);
try {
manager.serverclass = Class.forName(c);
} catch (Exception ex) {
System.err.println("Unable to initialize HttpManager: ");
System.err.println("Class \""+c+"\" not found, from property "
+ SERVER_CLASS_P);
ex.printStackTrace();
System.exit(1);
}
// Setup the template request:
Request tpl = manager.template;
// Set some default headers value (from props)
// Check for a proxy ?
manager.updateProxy();
// CacheControl, only-if-cached
tpl.setOnlyIfCached(props.getBoolean(ONLY_IF_CACHED_P, false));
// CacheControl, maxstale
int ival = props.getInteger(MAX_STALE_P, -1);
if ( ival >= 0 )
tpl.setMaxStale(ival);
// CacheControl, minfresh:
ival = props.getInteger(MIN_FRESH_P, -1);
if ( ival >= 0 )
tpl.setMinFresh(ival);
// general, lenient
manager.lenient = props.getBoolean(LENIENT_P, true);
manager.keepbody = props.getBoolean(KEEPBODY_P, false);
// General, User agent
String sval;
tpl.setValue("user-agent"
, props.getString(USER_AGENT_P
, DEFAULT_USER_AGENT));
// General, Accept
tpl.setValue("accept"
, props.getString(ACCEPT_P, DEFAULT_ACCEPT));
// General, Accept-Language
sval = props.getString(ACCEPT_LANGUAGE_P, null);
if ( sval != null ) {
if (sval.trim().length() > 0) {
tpl.setValue("accept-language", sval);
}
}
// General, Accept-Encoding
sval = props.getString(ACCEPT_ENCODING_P, null);
if ( sval != null ) {
if (sval.trim().length() > 0) {
tpl.setValue("accept-encoding", sval);
}
}
// Maximum number of allowed connections:
manager.conn_max = props.getInteger(CONN_MAX_P, 5);
// timeout value
manager.timeout = props.getInteger(TIMEOUT_P, manager.timeout);
// connection timeout
manager.conn_timeout = props.getInteger(CONN_TIMEOUT_P,
manager.conn_timeout);
// Register ourself as a property observer:
props.registerObserver(manager);
// Register that manager in our knwon managers:
for (int i = 0 ; i < managers.length ; i++) {
if ( managers[i] == null ) {
managers[i] = new ManagerDescription(manager, p);
return manager;