Friday, May 25, 2012

Updating the BPEL Component preference value from JAVA – Oracle SOA Suite

Updating the BPEL Component preference value from JAVA – Oracle SOA Suite:

Sometimes we may need to update the preference value for the BPEL component in Oracle SOA Suite 11g or Oracle SOA Suite 12c, the below java code will help us to update the preference value.

This update is not a cluster-aware,remember that you must repeat the same process for each managed server of your environment.
Before executing the code change the mbeanName accordingly.

   String mBeanName ="*:*,j2eeType=SCAComposite.SCAComponent,revision=*,SCAComposite=\"Preference\",name=Preference";

import java.util.*;
import javax.naming.Context;

public class UpdatePreferenceValue {  

    public static MBeanServerConnection getMbeanServerConnection(String host,
                                                                 int port,
                                                                 String userName,
                                                                 String password) throws Exception {
        String jndiroot = "/jndi/";
        MBeanServerConnection m_connection = null;
        try {
            Hashtable jndiProps = new Hashtable();
            jndiProps.put(Context.SECURITY_PRINCIPAL, userName);
            jndiProps.put(Context.SECURITY_CREDENTIALS, password);

            JMXServiceURL serviceURL =new JMXServiceURL("t3", host, port, jndiroot +"");
            JMXConnector m_connector =JMXConnectorFactory.newJMXConnector(serviceURL, jndiProps);
            m_connection = m_connector.getMBeanServerConnection();

        } catch (Exception e) {

        return m_connection;

    private static CompositeDataSupport UpdatePreferenceData(CompositeDataSupport cds,String[] keys,String[] newValues) throws Exception {
        Map<String, Object> items =new HashMap<String, Object>(cds.getCompositeType().keySet().size());

        for (String key : cds.getCompositeType().keySet()) {
            boolean matched = false;
            int i = 0;

            for (; i < keys.length; i++) {
                String searchKey = keys[i];

                if (searchKey.equalsIgnoreCase(key)) {
                    items.put(key, newValues[i]);
                    matched = true;

            if (!matched) {             
                    items.put(key, cds.get(key));

        return new CompositeDataSupport(cds.getCompositeType(), items);

    public static void updatePreference(String host,String port,String userName,String password, String  preferenceName,String value) {
        String mBeanName ="*:*,j2eeType=SCAComposite.SCAComponent,revision=*,SCAComposite=\"Preference\",name=Preference";

        MBeanServerConnection mbsc;
        try {
            mbsc =getMbeanServerConnection(host, Integer.parseInt(port),userName,password);
            Set<ObjectName> mbeans=mbsc.queryNames(new ObjectName(mBeanName), null);
            ObjectName mbean=(ObjectName)mbeans.iterator().next();
 [] properties =
            for (int i = 0; i < properties.length; i++) {
                CompositeDataSupport cds = (CompositeDataSupport)properties[i];

                if (preferenceName.equalsIgnoreCase((String)cds.get("name"))) {

                    properties[i] =UpdatePreferenceData((CompositeDataSupport)properties[i],new String[] { "value" },new String[] { value });
                    mbsc.setAttribute(mbean,new Attribute("Properties", properties));

        } catch (Exception e) {
    public static void main(String[] args) {
        updatePreference("localhost", "8000","weblogic", "password","preference.password","password");

Jar files required in class path-


No comments:

Post a Comment