public void loadAdapter() throws IOException {
boolean httpAdapterLoaded = false;
boolean jrmpAdapterLoaded = false;
if ((httpport != -1) && classExists("mx4j.adaptor.http.HttpAdaptor")) {
try {
httpServerName = registerObject("mx4j.adaptor.http.HttpAdaptor",
"Http:name=HttpAdaptor");
if( httphost!=null )
mserver.setAttribute(httpServerName, new Attribute("Host", httphost));
mserver.setAttribute(httpServerName, new Attribute("Port", new Integer(httpport)));
if( "none".equals(authmode) || "basic".equals(authmode) || "digest".equals(authmode) )
mserver.setAttribute(httpServerName, new Attribute("AuthenticationMethod", authmode));
if( authuser!=null && authpassword!=null )
mserver.invoke(httpServerName, "addAuthorization",
new Object[] {
authuser,
authpassword},
new String[] { "java.lang.String", "java.lang.String" });
if(useXSLTProcessor) {
ObjectName processorName = registerObject("mx4j.adaptor.http.XSLTProcessor",
"Http:name=XSLTProcessor");
mserver.setAttribute(httpServerName, new Attribute("ProcessorName", processorName));
}
// starts the server
mserver.invoke(httpServerName, "start", null, null);
log.info( "Started MX4J console on host " + httphost + " at port " + httpport);
httpAdapterLoaded = true;
} catch( Throwable t ) {
httpServerName=null;
log.error( "Can't load the MX4J http adapter ", t );
}
}
if ((httpport != -1) && (!httpAdapterLoaded) && classExists("mx4j.tools.adaptor.http.HttpAdaptor")) {
try {
httpServerName = registerObject("mx4j.tools.adaptor.http.HttpAdaptor",
"Http:name=HttpAdaptor");
if( httphost!=null )
mserver.setAttribute(httpServerName, new Attribute("Host", httphost));
mserver.setAttribute(httpServerName, new Attribute("Port", new Integer(httpport)));
if( "none".equals(authmode) || "basic".equals(authmode) || "digest".equals(authmode) )
mserver.setAttribute(httpServerName, new Attribute("AuthenticationMethod", authmode));
if( authuser!=null && authpassword!=null )
mserver.invoke(httpServerName, "addAuthorization",
new Object[] {
authuser,
authpassword},
new String[] { "java.lang.String", "java.lang.String" });
if(useXSLTProcessor) {
ObjectName processorName = registerObject("mx4j.tools.adaptor.http.XSLTProcessor",
"Http:name=XSLTProcessor");
mserver.setAttribute(httpServerName, new Attribute("ProcessorName", processorName));
}
// starts the server
mserver.invoke(httpServerName, "start", null, null);
if(log.isInfoEnabled())
log.info( "Started MX4J console on host " + httphost + " at port " + httpport);
httpAdapterLoaded = true;
} catch( Throwable t ) {
httpServerName=null;
log.error( "Can't load the MX4J http adapter ", t );
}
}
if ((jrmpport != -1) && classExists("mx4j.tools.naming.NamingService")) {
try {
jrmpServerName = registerObject("mx4j.tools.naming.NamingService",
"Naming:name=rmiregistry");
mserver.setAttribute(jrmpServerName, new Attribute("Port",
new Integer(jrmpport)));
mserver.invoke(jrmpServerName, "start", null, null);
if(log.isInfoEnabled())
log.info( "Creating " + jrmpServerName );
// Create the JRMP adaptor
ObjectName adaptor = registerObject("mx4j.adaptor.rmi.jrmp.JRMPAdaptor",
"Adaptor:protocol=jrmp");
mserver.setAttribute(adaptor, new Attribute("JNDIName", "jrmp"));
mserver.invoke( adaptor, "putNamingProperty",
new Object[] {
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.rmi.registry.RegistryContextFactory"},
new String[] { "java.lang.Object", "java.lang.Object" });
String jrpmurl = "rmi://" + jrmphost + ":" + Integer.toString(jrmpport) ;
mserver.invoke( adaptor, "putNamingProperty",
new Object[] {
javax.naming.Context.PROVIDER_URL,
jrpmurl},
new String[] { "java.lang.Object", "java.lang.Object" });
// Registers the JRMP adaptor in JNDI and starts it
mserver.invoke(adaptor, "start", null, null);
if(log.isInfoEnabled())
log.info( "Creating " + adaptor + " on host " + jrmphost + " at port " + jrmpport);
jrmpAdapterLoaded = true;
} catch( Exception ex ) {
jrmpServerName = null;
log.error( "MX4j RMI adapter not loaded: " + ex.toString());
}
}
if ((httpport != -1) && (! httpAdapterLoaded) && classExists("com.sun.jdmk.comm.HtmlAdaptorServer")) {
try {
httpServerName=registerObject("com.sun.jdmk.comm.HtmlAdaptorServer",
"Adaptor:name=html,port=" + httpport);
if(log.isInfoEnabled())
log.info("Registering the JMX_RI html adapter " + httpServerName + " at port " + httpport);
mserver.setAttribute(httpServerName,
new Attribute("Port", new Integer(httpport)));
mserver.invoke(httpServerName, "start", null, null);
httpAdapterLoaded = true;
} catch( Throwable t ) {
httpServerName = null;
log.error( "Can't load the JMX_RI http adapter " + t.toString() );
}
}
if ((!httpAdapterLoaded) && (!jrmpAdapterLoaded))
log.warn( "No adaptors were loaded but mx.enabled was defined.");
}
Initialize the worker. After this call the worker will be
ready to accept new requests. |