Monthly Archive: November 2009

Steps to use userconfig file and userkey file

Steps to use userconfig file and userkey file

First create the user config file and the key file with the following method (Alternatively Weblogic Admin utility can be used to create the user config files).

storeUserConfig(‘C:/bea922/user_projects/domains/config-file’,’C:/bea922/user_projects/domains/keyfile’)

You can connect to the nodemanger using the userKeyFile and userConfigFile :
nmConnect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’, host=’10.10.71.79′, port=’5556′, domainName=’SAML_SOURCE’, domainDir=’C:/bea922/user_projects/domains/SAML_SOURCE’, nmType=’plain’)

Similarly you can connect to the server:
connect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’,url=’t3://10.10.71.79:7001′)
Note: I have tested in WLS 9.2.

The username and password stored in the config files can be read from the JAVA code in the following way.

import weblogic.security.UserConfigFileManager;
import weblogic.security.UsernameAndPassword;

UsernameAndPassword usernameAndPassword=UserConfigFileManager.getUsernameAndPassword(“C:/bea922/user_projects/domains/config-file”,”C:/bea922/user_projects/domains/keyfile”,”weblogic.management”);

String username=new String(usernameAndPassword.getUsername());
String password=new String(usernameAndPassword.getPassword());

Registering Custom MBeans with Weblogic Server

Registering Custom Mbeans with Weblogic Server.

Example.java

package jmxMbeans;

public class Example implements ExampleMBean {

public void sayHello(String str) {

System.out.println(“Hello ” + str + “‘!”);

}

}

ExampleMbean.java

package jmxMbeans;

public interface ExampleMBean {

void sayHello(String name);

}

Index.jsp

<%@ page import=”javax.management.MBeanServer”%>

<%@ page import=”javax.management.ObjectName”%>

<%@ page import=”javax.naming.Context”%>

<%@ page import=”javax.naming.InitialContext”%>

<%@ page import=”java.util.Hashtable”%>

<%@ page import=”jmxMbeans.ExampleMBean”%>

<%@ page import=”jmxMbeans.Example”%>

<html>

<body>

<p>Registering Mbeans.</p>

<%

Example ex = new Example();

MBeanServer mbeanServer = null;

Hashtable<String, String> env = new Hashtable<String, String>();

env.put(Context.SECURITY_PRINCIPAL, “weblogic”);

env.put(Context.SECURITY_CREDENTIALS, “weblogic”);

InitialContext ic = new InitialContext(env);

mbeanServer = (MBeanServer) ic.lookup(“java:comp/env/jmx/runtime”);

String MBEAN_OBJECT_NAME = “jmxMbeans:Name=Example,Type=ExampleMBean”;

registerMBean(mbeanServer,MBEAN_OBJECT_NAME,ex);

unregisterMBean(mbeanServer,MBEAN_OBJECT_NAME);

%>

<%!

void registerMBean(MBeanServer server,String mbeanObjectName,Object obj) {

ObjectName objectName = null;

try {

objectName = new ObjectName(mbeanObjectName);

server.registerMBean(obj, objectName);

System.out.println(“MBean registered:” + objectName);

} catch (Exception e) {

//log.log(Level.SEVERE, “Error registering MBean ” + objectName, e);

}

}

%>

<%!

void unregisterMBean(MBeanServer server,String mbeanObjectName) {

ObjectName objectName = null;

try {

objectName = new ObjectName(mbeanObjectName);

server.unregisterMBean(objectName);

System.out.println(“MBean unregistered: ” + objectName);

} catch (Exception e) {

System.out.println(“Error unregistering MBean ” + objectName);

e.printStackTrace();

}

}

%>

</body>

</html>


Invoking the Custom MBean

test.jsp

Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,”weblogic.jndi.WLInitialContextFactory”);
env.put(Context.SECURITY_PRINCIPAL, “weblogic”);
env.put(Context.SECURITY_CREDENTIALS, “weblogic”);
InitialContext ctx = new InitialContext(env);

try{

String MBEAN_OBJECT_NAME = “jmxMbeans:Name=Example,Type=ExampleMBean”;
MBeanServer server = (MBeanServer) ctx.lookup(“java:comp/env/jmx/runtime”);
ObjectName objName = new ObjectName(MBEAN_OBJECT_NAME);
Object[] params = new Object[] {“Faisal”};
String[] sigs = new String[] {“java.lang.String”};
server.invoke(objName, “sayHello”, (Object[])params, sigs);
}
catch(Exception e){
e.printStackTrace();
}
ctx.close();

Plan.xml usage for Message Driven Bean

This post is an illustration of usage of plan.xml for overriding features of Message Driven Bean application dynamically.

Administrators use deployment plans to easily change an application’s WebLogic Server configuration for a specific environment without modifying existing Java EE or WebLogic-specific deployment descriptors. Multiple deployment plans can be used to reconfigure a single application for deployment to multiple, differing WebLogic Server environments.

In the plan.xml we will override the specified in the element tag of the weblogic-ejb-jar.xml file.

Steps to be followed:-

1:- Create a MDB listening to the Queue with the specified in the weblogic-ejb-jar.xml file.

2:- Generate the plan.xml file using the weblogic.PlanGenerator.

Ex:- java weblogic.PlanGenerator D:\ TestApp\TestMDB.jar –configurables

Once the plan.xml file is generated we can override the value for the provider-url as below.

<variable>

<name>MessageDrivenDescriptor_ProviderUrl_125717420773411</name>

<value>t3://localhost:7001</value>

</variable>

After overriding the value from the plan.xml, run the weblogic.Deployer command to deploy the application specifying the deployment plan as below.

 

java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy -name TestAPP -source D:\TestAPP.ear -targets AdminServer -stage -plan D:\plan.xml

 

This would override the dynamically, not requiring to manually edit the weblogic-ejb-jar.xml.

Hope the post is helpful for those who would like to use the same archive files for different environments overcoming the tedious job of manually editing the deployment descriptors.

I have uploaded the sample application as well for further references.

http://www.4shared.com/file/161924469/59a49461/Planxml-Usage.html

References:-

http://download.oracle.com/docs/cd/E13222_01/wls/docs90/deployment/wlplangenerator.html

Cheers,

Wonders Team. 🙂