Wednesday, April 23, 2014

Different approaches for connecting Weblogic Server to RAC database

Different approaches for connecting Weblogic Server to RAC database

Oracle Real Application Clusters (RAC) is a software component you can add to a high-availability solution that enables users on multiple machines to access a single database with increased performance. RAC comprises two or more Oracle database instances running on two or more clustered machines and accessing a shared storage device via cluster technology.


If your application requires load balancing across RAC nodes, WebLogic Server supports this capability through use of Using Connect-Time Load Balancing/Failover with Oracle RAC(JDBC URL based Load Balancing/Failover), JDBC Multi Data sources with Oracle RAC nodes and Gridlink Data Source.

Multi Data Source:

Refer the below URL's for details on Multi Data Source.

http://www.albinsblog.com/2012/02/jdbc-multi-data-sources-in-weblogic.html#.U1YNuvmukdQ
http://www.albinsblog.com/2012/02/creating-jdbc-multi-data-source-through.html

Connect-Time Load Balancing/Failover with Oracle RAC(JDBC URL based Load Balancing/Failover):

The JDBC connection string can be configure with single data source to support the load balancing and failover with RAC data source nodes.
Create a Generic Data source in weblogic server and provide the JDBC URL as below.Enable and disable the load balancing and failover accordingly.

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=on)(FAILOVER=on)(ADDRESS=(PROTOCOL=tcp)(HOST=RAC node1)(PORT=1521))(ADDRESS=(PROTOCOL=tcp)(HOST=RAC node2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=servicename)))

There are some limitation using this approach like the Global XA transactions are not supported.



WLST script to create Gridlink data source in weblogic

WLST script to create Gridlink data source in weblogic

This tutorial explains the approach to create Gridlink data source through WLST script in weblogic

Refer the below URL for details on Gridlink data source

https://www.albinsblog.com/2014/04/different-approaches-for-connecting.html


WLST Script


The below WLST script creates the Gridlink datasource with enabled configurations

GridLinkDataSource.properties

dbURL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=SERVICENAME)))
connectionpool.test.query=SQL SELECT * FROM DUAL
connectionpool.driver.class=oracle.jdbc.OracleDriver
connectionpool.username=SOA_EAIOWNER
connectionpool.password=orasoa11g
connectionpool.initCapacity=10
connectionpool.maxCapacity=60
datasource.name=EAISOAMetadataSource
datasource.jndi.name=eai/ds/EAISOAMetadataSource
datasource.target=Servers/AdminServer

domain.AdminIP=localhost
domain.AdminPort=7201

domain.AdminPasswd=Albin123!

GridLinkDatasourceCreation.py

from java.io import FileInputStreamdef createGridLinkJDBCResources(configProps):
   edit()
   startEdit()
        
   server='AdminServer'
   cd("Servers/"+server)
   target=cmo
   cd("../..")
   print '========================================='
   print 'Creating GridLink DataSource....'
   print '========================================='
   dsTestQuery=configProps.get("connectionpool.test.query")
   dsDriverName=configProps.get("connectionpool.driver.class")
  
            
   cd('/')
   dbURL= configProps.get("dbURL")           
   dsUserName = configProps.get("connectionpool.username")
   dsPassword = configProps.get("connectionpool.password")
   initCapacity = configProps.get("connectionpool.initCapacity")
   maxCapacity = configProps.get("connectionpool.maxCapacity")
   dsName = configProps.get("datasource.name")
   jndiname = configProps.get("datasource.jndi.name")
   datasourceTargets = configProps.get("datasource.target").split(",")print 'dsUserName',dsUserName
   print 'dsPassword',dsPassword
   print 'initCapacity',initCapacity
   print 'maxCapacity',maxCapacity
   print 'dsName',dsName
   print 'jndiname',jndiname
   print 'datasourceTargets',datasourceTargetsprint 'Creating DataSource: ',dsName,' ....'
  
   myResourceName = dsName   
   jdbcSystemResource = create(myResourceName,"JDBCSystemResource")     
   myFile = jdbcSystemResource.getDescriptorFileName()     
   jdbcResource = jdbcSystemResource.getJDBCResource()     
   jdbcResource.setName(myResourceName)# Create the DataSource Params     
   dpBean = jdbcResource.getJDBCDataSourceParams()     
   myName=jndiname 
   dpBean.setJNDINames([myName]) 
   dpBean.setGlobalTransactionsProtocol('TwoPhaseCommit')
    
   # Create the Driver Params     
   drBean = jdbcResource.getJDBCDriverParams()     
   drBean.setPassword(dsPassword)     
   drBean.setUrl(dbURL)     
   drBean.setDriverName(dsDriverName)#Create the Oracle params
   orapr=jdbcResource.getJDBCOracleParams()
   orapr.setFanEnabled(true)
   orapr.setOnsNodeList('node1:6200,node2:6200')
   propBean = drBean.getProperties()
   driverProps = Properties()     
   driverProps.setProperty("user",dsUserName)
   e = driverProps.propertyNames()
   while e.hasMoreElements() :             
  propName = e.nextElement()             
  myBean = propBean.createProperty(propName)           
  myBean.setValue(driverProps.getProperty(propName))   
  
  # Create the ConnectionPool Params     
  ppBean = jdbcResource.getJDBCConnectionPoolParams()     
  ppBean.setInitialCapacity(int(initCapacity))     
  ppBean.setMaxCapacity(int(maxCapacity))     
  ppBean.setTestConnectionsOnReserve(true)     
  ppBean.setTestTableName('SQL SELECT 1 FROM DUAL')xaParams = jdbcResource.getJDBCXAParams()     
  xaParams.setKeepXaConnTillTxComplete(1)# Add Target
   for datasourceTarget in datasourceTargets:
  print 'DataSourceTargets',datasourceTargets
  print 'DataSourceTarget',datasourceTarget
  if datasourceTarget=='':
   print ''
  else:
   jdbcSystemResource.addTarget(getMBean(datasourceTarget))     
  
 
   print 'DataSource: ',dsName,', has been created Successfully !!!'
   print '========================================='   
        
  
   save()
   activate()def main():
    propInputStream1 = FileInputStream("GridLinkDataSource.properties")
    configProps = util.Properties()
    configProps.load(propInputStream1)
  
    adminURL='t3://'+configProps.get('domain.AdminIP')+':'+configProps.get('domain.AdminPort')
    adminUserName='weblogic'
    adminPassword=configProps.get("domain.AdminPasswd")
    connect(adminUserName, adminPassword, adminURL)
  
    createGridLinkJDBCResources(configProps); 
  
    print 'Successfully created JDBC resources for SOACoreDomain'disconnect()main()

Script

https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/GridLinkDatasourceCreation

Before executing the script, change the configurations as required.Change the ONS node details in the script.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd GridLinkDatasourceCreation.py



After the successful execution of the script login to console and verify the Gridlink datasource created.




Monday, April 21, 2014

Oracle SOA Suite – Getting the payload from the Composite instance - Part2

Oracle SOA Suite  – Getting the payload from the Composite instance - Part2

n the previous post Oracle SOA Suite– Getting the payload from the Composite instance - Part1 - Through Java API i explained how to get the Oracle SOA Suite composite instance payload through JAVA API. In the previous approach we are getting the full audit trail of the instance and the required input payloads are retrieved using DOM parser and XPath expressions.For the larger payloads this approach fails to retrieve the payload.

In this post i am explaining the approach to get the Binary payload data from the database by executing the SQL statement and parsing the same to string message.

In Oracle SOA 11g the input payload related to the composite instances(input  to the composite and all the input payload send to the references) are stored in INSTANCE_PAYLOAD(the actual XML payload is kept in XML_DOCUMENT table) table.

By querying the INSTANCE_PAYLOAD, XML_DOCUMENT and COMPOSITE_INSTANCE we can retrieve the binary input payload for a particular composite instance.After receiving the XML payload as binary we can use the java code to transform the same to string format.

import java.io.StringWriter;
import java.sql.*;
import java.util.Hashtable;
import javax.naming.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import oracle.xml.binxml.*;
import oracle.xml.parser.v2.*;
import oracle.xml.scalable.InfosetReader;

public class GetPayload {
    public static Connection getConnection() throws Exception {
        Context ctx = null;
        Hashtable ht = new Hashtable();
        ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:8000");
        ctx = new InitialContext(ht);
        javax.sql.DataSource ds =(javax.sql.DataSource)ctx.lookup("jdbc/SOADataSource");
        return ds.getConnection();
    }

    public static String getPayload() {
        Statement stmt = null;
        Connection connection = null;
        ResultSet rs = null;
        String query =
            "select xmldoc.document DOC " + "from xml_document xmldoc,instance_payload inspay,composite_instance cmpins " +
            "where xmldoc.document_id = inspay.payload_key " +
            "and inspay.instance_id = cmpins.id " +
            "and inspay.instance_type='composite' " +
            "and xmldoc.DOCUMENT_TYPE = 2 " +
            "and inspay.instance_id = 7648669";      
   
        String payload = "";
        XMLDocument doc = null;
        try {
            connection = getConnection();
            stmt = connection.createStatement();
            rs = stmt.executeQuery(query);
            XMLDOMImplementation xmldomimpl = new XMLDOMImplementation();
            while (rs.next()) {                    
                BinXMLProcessor xmlprocessor =BinXMLProcessorFactory.createProcessor();
                BinXMLStream xmlstream =xmlprocessor.createBinXMLStream(rs.getBlob("DOC"));
                BinXMLDecoder xmldecoder = xmlstream.getDecoder();
                InfosetReader xmlreader = xmldecoder.getReader();
                doc = (XMLDocument)xmldomimpl.createDocument(xmlreader);
                TransformerFactory tf = TransformerFactory.newInstance();
                Transformer transformer;
                transformer = tf.newTransformer();
                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes");
                StringWriter writer = new StringWriter();
                transformer.transform(new DOMSource(doc),new StreamResult(writer));
                payload =writer.getBuffer().toString().replaceAll("<", "&lt;").replaceAll(">","&gt;");      
           }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null)
                    rs.close();
                if (stmt != null)
                    stmt.close();
                if (connection != null)
                    connection.close();
            } catch (Exception e) {

            }
        }
        return payload;

    }
}

The same query will not work in Oracle SOA Suite 12c to retrieve the payload as some of the tables are decommissioned in Oracle SOA Suite 12c e.g. INSTANCE_PAYLOAD and COMPOSITE_INSTANCE

If the process is asynchronous then the input payload is stored into the XML_DOCUMENT, the below query can be used to retrieve the BLOB data from XML_DOCUMENT table(modify the query in java code to parse the BLOB data)

SELECT XMLDOC.DOCUMENT DOC FROM XML_DOCUMENT XMLDOC , DLV_MESSAGE DLV,DOCUMENT_DLV_MSG_REF DLVREF WHERE DLVREF.MESSAGE_GUID=DLV.MESSAGE_GUID AND MLDOC.DOCUMENT_ID=DLVREF.DOCUMENT_ID AND DLV.CIKEY=10048;

If the payload size of the synchronous process is more than the threshold the input payload is stored in AUDIT_DETAILS table as BLOB data, the following query can be used to retrieve the blob data

SELECT BIN FROM AUDIT_DETAILS WHERE CIKEY=10102

Refer the following post with more details on retrieving the data from AUDIT_DETAILS -https://www.albinsblog.com/2014/04/getting-xml-form-auditdetails-table.html

Use the xmlparserv2.jar file from the following location $MIDDLE_HOME/oracle_common/modules/oracle.xdk_11.1.0(the xmlparserv2.jar downloaded from Google may not have some of the class files included)


Enable the ClusterConstraints in weblogic server - Oracle SOA Suite 11g

Enable the ClusterConstraints in weblogic server - Oracle SOA Suite 11g :

It is possible to change WebLogic Server’s default deployment behavior for clusters by setting the ClusterConstraintsEnabled option when starting the WebLogic Server domain. The ClusterConstraintsEnabled option enforces strict deployment for all servers configured in a cluster. A deployment to a cluster succeeds only if all members of the cluster are reachable and all can deploy the specified files.

This post will explain the different approaches to change Cluster Constraint.

Through EM console:

Login to EM console 
Right click on soa-infra-->Admiistration-->System MBean browser
Enter com.bea:Name=SOACoreDomain,Type=Domain in the MBean browser filter and click ok


Change the ClusterConstraintEnabled attribute accordingly and click on Apply button




Getting the XML form AUDIT_DETAILS table through Java- Oracle SOA Suite

Getting the XML form AUDIT_DETAILS table through Java- Oracle SOA Suite

In Oracle SOA Suite 11g or  Oracle SOA Suite 12c when the Audit trail sizeof the BPEL instance is more then the configured Threshold value then the audit trails are stored in AUDIT_DETAILS table.The single instance will have multiple audit details.


The XML documents in the AUDIT_DETAILS are compressed, this post will explain how to retrieve the XML documents from AUDIT_DETAILS through java.

package getpayloadweb;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;

public class GetPayload {
    public GetPayload() {
        super();
    }

    public static Connection getConnection() throws Exception {
        Context ctx = null;
        Hashtable ht = new Hashtable();
        ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:8000");
        ctx = new InitialContext(ht);
        javax.sql.DataSource ds =(javax.sql.DataSource)ctx.lookup("jdbc/SOADataSource");
        return ds.getConnection();
    }

    public static String getPayload() {
        Statement stmt = null;
        Connection connection = null;
        ResultSet rs = null;
     
     String query="select  UTL_COMPRESS.LZ_UNCOMPRESS(b.bin) DOC from audit_details b where cikey='5148077' and rownum<2";
     
        String payload = "";
        try {
            connection = getConnection();
            stmt = connection.createStatement();
            rs = stmt.executeQuery(query);
           while (rs.next()) {
                 
                 Blob blob=rs.getBlob("DOC");
                  byte[] sdata = blob.getBytes(1, (int) blob.length());;
                  payload = new String(sdata);
         
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null)
                    rs.close();
                if (stmt != null)
                    stmt.close();
                if (connection != null)
                    connection.close();
            } catch (Exception e) {

            }
        }
        return payload;

    }
}