Friday, September 7, 2012

Java code to retrieve the node data from a XML string received from a web URL

Java code to retrieve the node data from a XML string received from a web URL:

Code:

import java.io.*;
import java.net.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

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

    public static void getResponse(String city) {

        HttpURLConnection connection = null;
       
        String url="http://feeds.feedburner.com/burrp/"+city+"-events/weekend?format=xml";

        try {
            connection =
                    (HttpURLConnection)new URL(url).openConnection();
            connection.setRequestProperty("content-type",
                                          "text/xml;charset=utf-8");
            connection.setRequestMethod("GET");
            connection.setDoInput(true);
            connection.setDoOutput(true);

            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));

            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
           
            rd.close();
           
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            docBuilderFactory.setNamespaceAware(false);
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            InputStream is1 = new ByteArrayInputStream(response.toString().getBytes());
            Document doc = docBuilder.parse (is1);
            doc.getDocumentElement ().normalize ();
            NodeList listOfChannels = doc.getElementsByTagName("description");
            String description=listOfChannels.item(1).getFirstChild().getNodeValue();
            System.out.println(description);

        } catch (FileNotFoundException e) {
           
        }
        catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }

    public static void main(String[] args) {

        getResponse("Chennai");

    }
}


Modifying the targets of JDBC datasources through WLST script in weblogic server

Modifying the targets of JDBC datasources through WLST script in weblogic server

This tutorial explains the details on WLST script to change or add the targets for JDBC data sources in weblogic server.

The targeting can be enabled through weblogic admin console but the script helps us to automate the server configurations and reduce the manual effort if multiple data-sources need to be configured.
wlst-modify-jdbc-datasource-targets
The script will target the server MS3 and the Cluser1 to the data source with name “CRM6EAIReference”

Define JDBCProperties.properties with required configurations(sample script to show the configuration for multiple data-sources)

domain1.total.DS=2
domain1.prefix.1=om
domain1.om.datasource.name.1=CRM6EAIReference
domain1.om.datasource.target.1=Clusters/Cluster1,Servers/MS3
domain1.prefix.2=soa
domain1.soa.datasource.name.2=CRM6EAISOAMetadataSource
domain1.soa.datasource.target.2=Clusters/SOACluster

Before executing the script change the properties as required.If the target is a Server then it should be added like Servers/ServerName and if it is a cluster then it should be defined as Clusters/ClusterName. Configure domain1.total.DS with total number of data sources need to be configured.

Let us now define a WLST script file to change the targets using the property file defined above.

import re
from java.io import FileInputStream   

def UntargetTargetJDBCResources():
    edit()
    startEdit()
    propInputStream = FileInputStream('JDBCProperties.properties')
    configProps = Properties()
    configProps.load(propInputStream)    

    totalDataSource_to_untargetTarget=configProps.get("domain1.total.DS")
    
    server='AdminServer'
    cd("Servers/"+server)
       
    i=1
    while (i <= int(totalDataSource_to_untargetTarget)) :
    prefix = configProps.get("domain1.prefix."+ str(i))
    dsName = configProps.get("domain1."+prefix+".datasource.name."+ str(i))
    datasourceTargets = re.split(",",configProps.get("domain1."+prefix+".datasource.target."+ str(i)))
    targetArray=[] 
    
    for datasourceTarget in datasourceTargets:
   print 'DataSourceTargets',datasourceTargets
   print 'DataSourceTarget',datasourceTarget
   if datasourceTarget=='':
    print ''
   else:
    cd ('/JDBCSystemResources/'+dsName)
    set('Targets',jarray.array([], ObjectName))
    target=datasourceTarget[datasourceTarget.index("/")+1:len(datasourceTarget)]       
    if datasourceTarget.startswith('Cluster'):
     targetArray.append(ObjectName('com.bea:Name='+target+',Type=Cluster'))     
    elif datasourceTarget.startswith('Server'):
     targetArray.append(ObjectName('com.bea:Name='+target+',Type=Server'))         
   
    print 'Targets: ',targetArray
    set('Targets',jarray.array(targetArray, ObjectName))
    print 'DataSource: ',dsName,',Target has been updated Successfully !!!'
    print '========================================='    
    i = i + 1

    print '========================================='
    save()
    activate()
def main():
    adminURL='t3://localhost:7001'
    adminUserName='weblogic'
    adminPassword='weblogic1'
    connect(adminUserName, adminPassword, adminURL)
    UntargetTargetJDBCResources();
    print 'Successfully Modified the JDBC resources'
    disconnect()
main()

Script - 

The above script update the JDBC data source targets based on the configurations enabled in the property file.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd ModifyJDBCResourcesTargets.py
wlst-modify-jdbc-datasource-targets
The JDBC data source targets changed now with the enabled configurations,the WLST script can be used to automate the server configurations and reduce the manual effort need for configurations.


Wednesday, September 5, 2012

Creating Socket Adapter connection factories through WLST script - Oracle SOA Suite

Creating Socket Adapter connection factories through WLST script - Oracle SOA Suite

The below WLST script will help us to create the Socket adapter connection factories in Oracle SOA Suite 11g or Oracle SOA Suite 12c

Change the Socket/SOA server details accordingly in the script.

Before executing the script make sure the SocketAdapter is targeted to the servers.

socket_adapter_target_servers

CreateSocketConnectionFactory.py

TargetServerName='AdminServer'

soaHome='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1'

appPathSock=soaHome+'\soa\connectors\SocketAdapter.rar'
appNameSock='SocketAdapter'
moduleOverrideNameSock=appNameSock+'.rar'
SockJNDIName = 'eis/socket/SocketAdapterBlog'
#Socket Sever Details
HostName='101.63.203.129'
Password='blogenv1'
Port='7001'
UserName='weblogic'

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathSock='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1\soa\connectors\Plan_Soket.xml'

def createSocketConnectionFactory(): 

        edit()
        startEdit()
        startApplication(appNameSock)
        myPlanSock=loadApplication(appPathSock, planPathSock)
        makeDeploymentPlanVariable(myPlanSock,'ConnectionInstance_eis/Socket_JNDIName_13102979357209', SockJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/jndi-name',moduleOverrideNameSock)
        makeDeploymentPlanVariable(myPlanSock, 'ConfigProperty_eis/Socket_JNDIName_Host_Name_13102979357210', HostName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/connection-properties/properties/property/[name="Host"]/value',moduleOverrideNameSock)
        makeDeploymentPlanVariable(myPlanSock, 'ConfigProperty_eis/Socket_JNDIName_Port_13102979357212', Port,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/connection-properties/properties/property/[name="Port"]/value',moduleOverrideNameSock)
               
        myPlanSock.save();
        save();
        cd('/AppDeployments/SocketAdapter/Targets');
        updateApplication(appNameSock, planPathSock);
        startApplication(appNameSock);
        activate(block='true');
      
   
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       #SOA Server Details
       adminURL='t3://localhost:7001'
       adminUserName='weblogic'
       adminPassword='blogenv1'
       connect(adminUserName, adminPassword, adminURL)
       createSocketConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd CreateSocketConnectionFactory.py




DOWNLOAD  CreateSocketConnectionFactory.py


Tuesday, September 4, 2012

Creating Oracle BAM Adapter connection factories through WLST script in Oracle SOA Suite

Creating Oracle BAM Adapter connection factories through WLST script in Oracle SOA Suite

The below WLST script will help us to create the Oracle  BAM adapter connection factories in Oracle SOA Suite.
Change the BAM/SOA server details accordingly.

Before executing the script make sure the OracleBamAdapter is targeted to the server.

oraclebamadapter_target_server

CreateBAMConnectionFactory.py

TargetServerName='AdminServer'

soaHome='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1'

appPathBAM=soaHome+'\soa\connectors\OracleBamAdapter.rar'
appNameBAM='OracleBamAdapter'
moduleOverrideNameBAM=appNameBAM+'.rar'
BAMJNDIName = 'eis/BAM/Connection'
#BAM Server Details
HostName='localhost'
Password='blogenv1'
Port='7001'
UserName='weblogic'

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathBAM='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1\soa\connectors\Plan_BAM.xml'

def createBAMConnectionFactory(): 

        edit()
        startEdit()
        startApplication(appNameBAM)
        myPlanBAM=loadApplication(appPathBAM, planPathBAM)
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_13102979357209', BAMJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/jndi-name',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConfigProperty_eis/BAM/BAM_JNDIName_Host_Name_13102979357210', HostName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="HostName"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_Password_13102979357211', Password , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="Password"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConfigProperty_eis/BAM/BAM_JNDIName_Port_13102979357212', Port,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="PortNumber"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_UserName_13102979357211', UserName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="UserName"]/value',moduleOverrideNameBAM)
       
        myPlanBAM.save();
        save();
        cd('/AppDeployments/OracleBamAdapter/Targets');
        updateApplication(appNameBAM, planPathBAM);
        activate(block='true');
      
   
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       #SOA Server Details
       adminURL='t3://localhost:7001'
       adminUserName='weblogic'
       adminPassword='blogenv1'
       connect(adminUserName, adminPassword, adminURL)
       createBAMConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd CreateBAMConnectionFactory.py




The same script will not work in Oracle SOA Suite 12c - the connection-factory-interface javax.resource.cci.ConnectionFactory is not working with 12c. Refer the attached script specific to 12c

DOWNLOAD CreateBAMConnectionFactory.py    CreateBAMConnectionFactory_12c.py


Monday, September 3, 2012

Importing the Oracle BAM objects from 10g to 11g

Importing the Oracle BAM objects from 10g to 11g


The icommand utility will be used to export and import the Oracle BAM objects between environments.

This blog will explain how to import the Oracle BAM objects exported from the 10g environment.

Before executing the icommand to import the BAM objects make sure the BAM port name (the default port name is 9001) configured properly in $MIDDLE_HOME/ORACLE_SOA1/bam/config/BAMICommandConfig.xml file.


Import the data object:

icommand -cmd import -file D:\Albin\Docs\SavingsAccountOpeningBAM\SavingsAccountOpening.do -mode preserveid