Friday, August 10, 2012

Monitoring the JCA Adapter’s through WLST script – Oracle SOA 11g


Sometimes we may need to monitor the runtime performance of the JCA adapters, the monitoring is possible through EM console for limited details, the below WLST script will help us to monitor the required details of the JCA adapter (the scrip should be extended to monitor more details).

The below script can be used for monitoring only the DBAdapter’s and MQAdapter’s; the same can be extended to monitor other JCA Adapters (like FileAdapter) .

Before executing the script change the below condition according to your server name.

if server.getName().strip().startswith('S') | server.getName().strip().startswith('O')

The Adapters are only available in SOA and OSB servers so that I am filtering the other servers  based on the name(AdminServer or MS servers) .The exception will be thrown if we are trying to cd the MBean related to Adapters in others servers.

ResourceAdapterMonitor.py

def monitorDBAdapter(serverName):
    cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools")
    connectionPools = ls(returnMap='true')
    print '--------------------------------------------------------------------------------------'
    print 'DBAdapter Runtime details for '+ serverName
    print '                                                                                      '
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

    print '%10s %13s %15s %18s' % ('Connection Pool', 'State', 'Current', 'Created')
    print '%10s %10s %24s %21s' % ('', '', 'Capacity', 'Connections')
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'
    for connectionPool in connectionPools:
       if connectionPool!='eis/DB/SOADemo':
          cd('/')
          cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools/"+str(connectionPool))
          print '%15s %15s %10s %20s' % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

def monitorMQAdapter(serverName):
    cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools")
    connectionPoolsMQ = ls(returnMap='true')
    print '--------------------------------------------------------------------------------------'
    print 'MQAdapter Runtime details for '+ serverName
    print '                                                                                      '
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

    print '%15s %17s %15s %18s' % ('Connection Pool', 'State', 'Current', 'Created')
    print '%15s %15s %24s %21s' % ('', '', 'Capacity', 'Connections')
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'
    for connectionPoolMQ in connectionPoolsMQ:
          cd('/')
          cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools/")
          cd(connectionPoolMQ)
          print '%15s %20s %10s %20s' % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'


def main():
      #connect(username, password, admurl)
      connect('weblogic','reuters123','t3://:)
      servers = cmo.getServers()
      domainRuntime()
      for server in servers:
         cd("/ServerLifeCycleRuntimes/" + server.getName())
         if cmo.getState() == 'RUNNING':  
            if server.getName().strip().startswith('S') | server.getName().strip().startswith('O') :
                 monitorDBAdapter(server.getName())
      for server in servers:
         cd('/')
         cd("/ServerLifeCycleRuntimes/" + server.getName())
         if cmo.getState() == 'RUNNING':  
            if server.getName().strip().startswith('S') | server.getName().strip().startswith('O') :
                 monitorMQAdapter(server.getName())   
      disconnect()
     
main()



Copy the script to the soa server and execute the below command

>   wlst.sh ResourceAdapterMonitor.py

O/P:
--------------------------------------------------------------------------------------
DBAdapter Runtime details for SOA1
--------------------------------------------------------------------------------------
Connection Pool         State         Current            Created
                                                    Capacity          Connections
--------------------------------------------------------------------------------------
  eis/DB/SOA             Running         22               1051
      eis/DB/Test           Running           2                  697
    eis/DB/Test1           Running           1                  130
--------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------
MQAdapter Runtime details for SOA1
------------------------------------------------------------------------------------------------------
Connection Pool                                       State          Current            Created
                                                                                  Capacity           Connections
------------------------------------------------------------------------------------------------------
eis/MQ/MQAdapter                                 Running          0                    0
eis/MQ/MQSeriesAdapterRemote            Running          2                   84
-------------------------------------------------------------------------------------------------------

Changing the reference endpoint of a Composite through JAVA – Oracle SOA 11g


The blog explain how to use the Java API to change the reference endpoint of a composite.

This update is not a cluster-aware; remember that you must repeat the same process for each managed server of your environment.

UpdateEndPoint .java

import java.util.*;
import javax.management.*;
import javax.management.openmbean.*;
import javax.management.remote.*;
import javax.naming.Context;

public class UpdateEndPoint {

    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);
            jndiProps.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");

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

        } catch (Exception e) {
            e.printStackTrace();
        }
        return m_connection;
    }

    private static CompositeDataSupport UpdateEndPointData(CompositeDataSupport cds,String[] keys,String[] newValues) throws Exception {
        Map items =new HashMap(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;
                    break;
                }
            }

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

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

    public static void updateEndPoint(String host, String port,String userName, String password,String compositeName,String revision, String referenceName, String endpoint) {

        String mBeanName =
            "oracle.soa.config:SCAComposite=\""+compositeName+"\""+",revision="+revision+",port=*,label=*,Application=*,name=WSBinding,SCAComposite.SCAReference="+referenceName+",j2eeType=SCAComposite.SCAReference.SCABinding,*";

        MBeanServerConnection mbsc;
        try {
            mbsc =getMbeanServerConnection(host, Integer.parseInt(port), userName, password);
            Set mbeans =mbsc.queryNames(new ObjectName(mBeanName), null);
            ObjectName mbean = (ObjectName)mbeans.iterator().next();
            javax.management.openmbean.CompositeData[] properties =(javax.management.openmbean.CompositeData[])mbsc.getAttribute(mbean, "Properties");
            boolean endpointFound = false;
            for (int i = 0; i < properties.length; i++) {
                CompositeDataSupport cds = (CompositeDataSupport)properties[i];        
 

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

                    properties[i] =UpdateEndPointData((CompositeDataSupport)properties[i],new String[] { "value" },new String[] { endpoint });
                    mbsc.setAttribute(mbean,new Attribute("Properties", properties));
                    endpointFound = true;
                    break;
                }
            }

            // Property not found, insert it
            if (!endpointFound) {
                CompositeDataSupport cds =UpdateEndPointData((CompositeDataSupport)properties[0],new String[] { "name", "value" },new String[] { "endpointURI",endpoint });
                CompositeData[] newPropertyArray =AppendEntry(properties, cds);
                mbsc.setAttribute(mbean,new Attribute("Properties", newPropertyArray));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static CompositeData[] AppendEntry(CompositeData[] properties,CompositeDataSupport endpointProperty) {
        CompositeData[] newArray =new CompositeData[properties.length + 1];
        for (int x = 0; x < properties.length; x++) {
            newArray[x] = properties[x];
        }
        newArray[properties.length] = endpointProperty;
        return newArray;
    }

    public static void main(String[] args) {        //updatePreference(host,post,username,password,compositeName,revision,,referenceParnerlink,enpoint);
  updateEndPoint("localhost", "8000", "weblogic", "password","InvokeServlet", "1.0","InvokeServletService","http://localhost:8080/EmployeeServlet/employeeservlet");
    }
}

Add the weblogic.jar file to the class.
Before executing the program, change the server details, Composite name, revision, reference name and the endpoint location accordingly.

Passing parameter to XSLT in SOA 11g


Not like SOA 10g, in SOA 11g the parameters can be directly added into the Transform activity from GUI.
The parameters can be of any schema element type; the XML Schema Simple types are not accepted.

Create a schema definition that will have the parameter definition e.g.
Here, I have defined the schema to pass the parameters startIndex and endIndex to the XSLT.





Create the variable (e.g. parameters) of required element type defined in the schema, in my case the element name is parameters.


Open the Transform activity and select the Input/output variables. Add the parameters variable in the source section, the first variable that is added becomes the source for the transformation activity. These additional variables become as parameters to the transform file.


The parameter can be accessed using the syntax: $parametername+ XPath expression for the node.





Correlating the request/response messages in MQ Series Adapter – Oracle SOA 11g


Mapping a response to a request in a request-reply interaction requires correlation.The MQ adapter provide the inbuilt options to correlate the request and response messages, there is no need of implementing the custom correlation to correlate the request and response messages.

Each MQSeries request message contains a message ID and a correlation ID. When an application receives a request message from Oracle BPEL PM, it checks for the correlation schema defined for the response message. Based on the correlation schema, the application generates the message ID and correlation ID of the response message. Based on the Message ID/Correlation ID the request/response messages will be correlated in the MQAdapter.

The below are the two patterns to correlate the request/response messages in MQ adapter.
·                     Get Message from MQ and Send Reply
·                     Send Message to MQ and Get Reply

Get Message from MQ and Send Reply:

MQ adapter gets a message from the inbound Queue and send a reply message to the outbound bound queue Synchronously/Asynchronously.
·                     Create a composite with synchronous/asynchronous BPEL process.
·                     Delete the default service created and add the MQ Adapter service



·                     Add the MQ JNDI name in the 3rd step of MQ adapter definition.

·                      Select the operation as Get message to MQ and Get Reply/Reports and the option name as Asynchronous/Synchronous in the 5th step.



·                      Select the Message Type as Normal and enter the request queue name as part 6th step.


·                     Enter the reply queue in the 7th step



·                     Configure the input/output schema s in 8th step


·                     Delete the default parnerlink in the BPEL and connect to the partner link created for the MQ.


·                     Delete and Recreate the input/output variables and complete the BPEL design as per the requirement.



·                     Double click on the receiveInput activity in the BPEL and select the properties tab.
·                     Select the messageid as the input for the property jca.mq.MQMD.MsgId – Create the messageid variable before as string type.


·                     Open the callbackclient activity and select the properties tab, add the messageid variable as the input to the property jca.mq.MQMD.MsgId


·                     Deploy the code and test.


 Send Message to MQ and Get Reply:
·                     Design the Composite and the BPEL process.









·                      Configure the MQ adapter as a reference by following the steps mentioned above.
·                     Make sure the Message Type selected as Normal in the 6th step




·                      Make sure the Message ID and the Correlation ID values selected as shown below in the 7th step.


·                     Deploy the composite and test.