Accessing and Changing Configuration Information

Configuration MBeans on the Administration Server (Administration MBeans) configure the managed resources on all WebLogic Server instances in a domain. To enhance performance, each server instance creates and uses local replicas of the Administration MBeans. These local replicas are called Local Configuration MBeans.

Note: While you can view the values of Local Configuration MBeans, BEA recommends that you do not change attribute values in Local Configuration MBeans. Instead, change only the values of Administration MBean attributes. With some WebLogic Server facilities, such as clustering, a Managed Server replicates a subset of other Managed Server's configuration data. When the Managed Server replicates the data of other Managed Servers, it uses the values that are stored in Administration MBeans. Communication problems can occur if the values in Administration MBeans and Local Configuration MBeans differ.

The following sections provide examples for programmatically viewing and modifying the configuration of WebLogic Server resources using the weblogic.Admin utility, the JMX MBeanServer APIs, and the WebLogic Server type-safe interface:

 


Example: Using weblogic.Admin to View the Message Level for Standard Out

This example uses the weblogic.Admin utility to connect directly to a Managed Server and look up the value of its StdoutSeverityLevel attribute. This attribute, which belongs to the server's ServerMBean, specifies a threshold for determining which severity-level of messages a server prints to its standard out.

While BEA recommends that you use only Administration MBeans to change values, there might be situations in which it is preferable to look up the values that are in Local Configuration MBeans. For example, the Administration Server might be down, making it impossible for you to access Administration MBeans.

The example command:

  1. Uses the -url argument to connect to a Managed Server that runs on a host named myHost and that listens on port 8001.
  2. Uses the -username and -password arguments to specify the credentials of a user who has permission to view MBean attributes. For information about permissions to view and modify MBeans, refer to "Security Roles in the Securing WebLogic Resources guide.
  3. Uses the GET command to retrieve a Local Configuration MBean.

    To specify a Local Configuration MBean, it removes MBean and appends Config to the ServerMBean interface name. Note that the -type value for a Local Configuration instance of the ServerMBean is ServerConfig while the -type value for the corresponding Administration MBean instance is Server. For more information, refer to the description of Type in Table 3-1.

Listing 4-1 Configuring the Message Level

java weblogic.Admin -url myHost:8001 -username weblogic -password weblogic 



GET -pretty -type ServerConfig
---------------------------



MBeanName: "medrec:Location=MedRecServer,Name=MedRecServer,Type=ServerConfig" AcceptBacklog: 50 AdministrationPort: 0
...
        StdoutDebugEnabled: false


      StdoutEnabled: true


      StdoutFormat: standard


      StdoutLogStack: true


      StdoutSeverityLevel: 16

 


Example: Configuring the Message Level for Standard Out

The class in this example changes the value of the StdoutSeverityLevel attribute in the weblogic.management.configuration.ServerMBean to change the level of messages that a server instance named MedRecServer sends to standard out.

Because the example is changing configuration values, it changes the value in the Administration MBean and relies on the WebLogic management services to propagate the change to the Managed Server.

The example class:

  1. Uses JNDI to look up the Administration MBeanHome interface on the Administration Server.
  2. Uses the MBeanHome.getMBean(String name, String type) API to retrieve the type-safe interface of the ServerMBean Administration MBean for a server instance named Server1.
  3. Uses the type-safe interface to invoke the ServerMBean.setStdoutSeverityLevel method and set the severity level to 64.

In the example, weblogic is a user who has permission to view and modify MBean attributes. For information about permissions to view and modify MBeans, refer to "Security Roles in the Securing WebLogic Resources guide.

Listing 4-2 Configuring Standard Out Severity Level

import java.util.Set;



import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.management.MBeanServer;
import javax.management.Attribute;
import java.lang.Object;
import weblogic.jndi.Environment;



import weblogic.management.MBeanHome;
import weblogic.management.configuration.ServerMBean;
public class ChangeStandardOut1 {
    public static void main(String[] args) {



        MBeanHome home = null;
        ServerMBean server = null;
        //domain variables
        String url = "t3://localhost:7001";
        String username = "weblogic";
        String password = "weblogic";
        String serverName = "Server1";
        //setting the initial context



        try {
            Environment env = new Environment();
            env.setProviderUrl(url);
            env.setSecurityPrincipal(username);
            env.setSecurityCredentials(password);
            Context ctx = env.getInitialContext();
            //getting the Administration MBeanHome



            home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            // Using MBeanHome.getMBean(name, type) to retrieve a type-safe



            // interface for a ServerMBean
            server = (ServerMBean)home.getMBean(serverName,"Server");
            // Using ServerMBean.setStdoutSeverityLevel



            server.setStdoutSeverityLevel(64);
            //  Providing feedback that operation succeeded.



            System.out.println("Changed standard out severity level to: " +
                                 server.getStdoutSeverityLevel());
        } catch (Exception e) {
            System.out.println("Caught exception: " + e);
        }
    }
}

Skip navigation bar  Back to Top Previous Next