Http://blog.csdn.net/saidora/archive/2007/06/23/1663108.aspx
There are three mbeans in WebLogic, and their functions are as follows:
1. domainruntime mbean Server
Domainruntimeservermbean provides mbean access for domain-specific services (Application Deployment, JMS server, and JDBC data source.
Com. BEA: Name = domainruntimeservice, type = weblogic. Management. mbeanservers. domainruntime. domainruntimeservicembean
2. runtime mbean Server
Runtimeservermbean provides access to mbean activity configuration during running of the current server.
Com. BEA: Name = runtimeservice, type = weblogic. Management. mbeanservers. runtime. runtimeservicembean
3. Edit mbean Server
Editservicembean provides an entry point for managing the configuration of the current WebLogic Server domain.
Com. BEA: Name = editservice, type = weblogic. Management. mbeanservers. Edit. editservicembean
WebLogic 9.0 uses JMX or WLS to add users in different ways.
The example program is as follows:
Import java. Io. file;
Import java. Io. ioexception;
Import java.net. malformedurlexception;
Import java. util. hashtable;
Import javax. Management. mbeanserverconnection;
Import javax. Management. objectname;
Import javax. Management. Remote. jmxconnector;
Import javax. Management. Remote. jmxconnectorfactory;
Import javax. Management. Remote. jmxserviceurl;
Import javax. Naming. context;
Publicclass addtoweblogic {
Privatestatic string username = "WebLogic ";
Privatestatic string Password = "WebLogic ";
Privatestatic string protocol = "T3 ";
Privatestatic string hostname = "localhost ";
Privatestaticintport = 7001;
Privatestatic string JNDI = "/JNDI /";
// Domainruntime mbean server is used
Privatestatic string runtime_uri = "weblogic. Management. mbeanservers. domainruntime ";
Privatestatic string edit_service = "com. BEA: Name = domainruntimeservice, type = weblogic. Management. mbeanservers. domainruntime. domainruntimeservicembean ";
Private mbeanserverconnection domainmbeanserverconnection = NULL;
// In this domain, connect to the running server
Public mbeanserverconnection getconnection (string URI) throws ioexception, malformedurlexception {
// Describe the mbean server address
Jmxserviceurl serviceurl = new jmxserviceurl (protocol, hostname, port, JNDI + URI );
Hashtable H = new hashtable ();
// The username and password used to log on to WebLogic for this domain
H. Put (context. security_principal, username );
H. Put (context. security_credentials, password );
H. Put (jmxconnectorfactory. protocol_provider_packages, "weblogic. Management. Remote ");
// Construct the jmxconnector object.
Jmxconnector conne= jmxconnectorfactory. Connect (serviceurl, H );
// Connect to mbean
Mbeanserverconnection connection = connector. getmbeanserverconnection ();
Return connection;
}
Publicvoid addrun (string username, string password ){
Try {
Domainmbeanserverconnection = getconnection (runtime_uri );
Objectname service = new objectname (edit_service );
// Obtain the specific attributes of mbean and add the user to defaultauthenticator.
Objectname domainmbean = (objectname) domainmbeanserverconnection. getattribute (service, "domainconfiguration ");
Objectname securityconfiguration
= (Objectname) domainmbeanserverconnection. getattribute (domainmbean, "securityconfiguration ");
Objectname defaultrealm
= (Objectname) domainmbeanserverconnection. getattribute (securityconfiguration, "defaultrealm ");
Objectname [] atnproviders
= (Objectname []) domainmbeanserverconnection. getattribute (defaultrealm, "authenticationproviders ");
Objectname defaultatnprovider = NULL;
For (INT I = 0; I <atnproviders. length; I ++ ){
String name = (string) domainmbeanserverconnection. getattribute (atnproviders [I], "name ");
If (name. Equals ("defaultauthenticator ")){
Defaultatnprovider = atnproviders [I];
}
}
// Call the createuser function in WebLogic to add a user
Domainmbeanserverconnection. Invoke (defaultatnprovider, "createuser ",
New object [] {username, password, "generaluser "},
New String [] {"Java. Lang. String", "Java. Lang. String", "Java. Lang. String "});
// Call addmembertogroup in WebLogic to classify users into a group. domainmbeanserverconnection. Invoke (defaultatnprovider, "addmembertogroup ",
New object [] {"user", username },
New String [] {"Java. Lang. String", "Java. Lang. String "});
}
Catch (exception e ){
E. printstacktrace ();
}
}
Related functions:
Jmxconnectorfactory
The factory used to create the jmx api connector client. This class has no instances.
This method is usually used to establish a connection.
Public static jmxconnector connect (jmxserviceurl serviceurl, Map <string,?> Environment)
Throws ioexception
Create a connection to the connector server at the given address.
This method is equivalent:
Jmxconneconn = jmxconnectorfactory. newjmxconnector (serviceurl, environment );
Conn. Connect (Environment );
Parameters:
Serviceurl-the address of the connector server to connect.
Environment-a set of attributes used to determine how to establish a connection. This parameter can be null. The keyword in this ing must be a string. The appropriate type of each associated value depends on the attribute. This call does not change the content of environment.
Return Value:
Indicates the jmxconnector of the new connection. Each successful call to this method generates different objects.
Throw:
Nullpointerexception-If serviceurl is null.
Ioexception-unable to establish a connector client or connection due to communication problems.
Securityexception-connection cannot be established due to security reasons.
Getmbeanserverconnection
Mbeanserverconnection getmbeanserverconnection () throws ioexception
Returns an mbeanserverconnection object representing the remote mbean server. For a given jmxconnector, the same mbeanserverconnection object is usually returned for two successful calls to this method, although this is not required.
For each method in the returned mbeanserverconnection, calling this method will call the corresponding method in the remote mbean server. The value returned by the mbean server method is the value returned to the client. If the mbean server method generates an exception, the same exception occurs on the client. If an error is generated for the mbean server method (or an attempt to call it), the error is encapsulated in jmxservererrorexception, and the error is displayed on the client.
Calling this method is equivalent to calling getmbeanserverconnection (null). This means that no delegated topic is specified and all operations called on mbeanserverconnection must use a verified topic (if any ).
Return Value:
An object that implements the mbeanserverconnection interface by forwarding the method to the remote mbean server.
Throw:
Ioexception-if a valid mbeanserverconnection cannot be created, for example, the connection to the remote mbean server has not been established (using the connect method), the connection has been closed, or the connection has been disconnected.
Jmxserviceurl
Public jmxserviceurl (string protocol,
String host,
Int port)
Throws malformedurlexception
Construct a jmxserviceurl with the given protocol, host, and port. This constructor is equivalent to jmxserviceurl (protocol, host, port, null ).
Parameters:
Protocol-URL. If it is null, jmxmp is used by default.
Host-URL. If it is null, the local host name is used by default. It is determined by inetaddress. getlocalhost (). gethostname. If it is a numeric IPv6 address, you can enclose it in square brackets.
Port-URL port.
Throw:
Malformedurlexception-if a part is incorrectly syntactically incorrect, if the host is null and the local host name cannot be found, or if the port is negative.
Mbeanserverconnection
This interface indicates a way to communicate with the mbean server (whether local or remote. The mbeanserver interface of the local mbean Server extends this interface.
Getattribute
Object getattribute (objectname name,
String attribute)
Throws mbeanexception,
Attributenotfoundexception,
Instancenotfoundexception,
Reflectionexception,
Ioexception
Obtain the specific property value of the specified mbean. Mbean object name is used to identify mbean.
Parameters:
Name-mbean object name, which is used to retrieve mbean attributes.
Attribute-string of the attribute name to be retrieved.
Return Value:
The retrieved property value.
Throw:
Attributenotfoundexception-if the specified attribute is inaccessible in mbean.
Mbeanexception-exception thrown by the method for obtaining the encapsulated mbean.
Instancenotfoundexception-if the specified mbean is not registered in the mbean server.
Reflectionexception-wrap the java. Lang. Exception thrown when trying to call the setting method.
Runtimeoperationsexception-wrap java. Lang. illegalargumentexception: if the object name in the parameter is null or the attribute in the parameter is null.
Ioexception-communication problems occur when communicating with the mbean server.
Invoke
Object invoke (objectname name,
String operationname,
Object [] Params,
String [] signature)
Throws instancenotfoundexception,
Mbeanexception,
Reflectionexception,
Ioexception
Call an operation on mbean.
Parameters:
Name-mbean object name. You must call the method on this mbean.
Operationname-name of the operation to be called.
Params-an array containing the parameters to be set when an operation is called
Signature-an array containing the operation signature. The Class Loader used to load class objects is the same as the class loader used to load mbean (to call the operation on it.
Return Value:
The object returned by this operation, indicating the result of calling this operation on the specified mbean.
Throw:
Instancenotfoundexception-if the specified mbean is not registered in the mbean server.
Mbeanexception-the exception thrown by the method encapsulated on mbean.
Reflectionexception-wrap the java. Lang. Exception thrown when trying to call this method.
Ioexception-communication problems occur when communicating with the mbean server.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/saidora/archive/2007/06/23/1663108.aspx