Pages

Wednesday, November 3, 2010

Deploy your AQ , DB or JMS Resource Adapter to Weblogic and use it in OSB & SOA Suite

When you are familiar with SOA Suite 11g or Oracle Service Bus then you know, that sometimes you need to configure some Resource Adapters in WebLogic. This is necessary when you use the Database, AQ , JMS or Applications adapter in your Composite application or Proxy / Business Service. This task can't be scripted with WLST, The first time you need to generate a Deployment Plan and after that, you can add your EIS entries. In a Cluster environment you need to put this Deployment Plan on a shared storage or copy this to every server.
In this blogpost I will you show that you can deploy your own Resource Adapter with your EIS entries to the SOA Server or Cluster. This way you can separate EIS entries in their own Resource Adapter, so you don't have one big Deployment Plan. Reduce the human factor and just deploy it, no manual tasks after you SOA Composites deployments. And you can deploy it to a cluster and add these Resource Adapter files to your Subversion system.

Basically I do the following steps.
  • Extract the WebLogic Resource Adapters files to a local folder
  • Remove the jars, because these jars are already loaded in the original Resource Adapters
  • Edit the weblogic-ra.xml and remove the default entries and add your own
  • Pack the Resource Adapter
  • Undeploy the Resource Adapter on the WebLogic Server
  • Deploy the Resource Adapter
  • Set the deployment order after the original Resource Adapter
Here a picture of my JDeveloper project where I can do these tasks with the help of ANT and WLST.
 To make this work you need to add your WebLogic jar to the classpath of the ANT environment.


Change the weblogic-ra.xml with your own Entries.

And at last deploy all the Resource Adapters or just one

Here is the ANT properties file. With changing the EnvironmentName you can create a different set of Resource Adapters
FMW.home=C:/oracle/Soa11gPS2
WLS.home=${FMW.home}/wlserver_10.3
SOA.home=${FMW.home}/Oracle_SOA1
SOA.adapters.home=${SOA.home}/soa/connectors

WLS.fullclient=C:/java/wlfullclient.jar

AQ=AqAdapter
DB=DbAdapter
JMS=JmsAdapter

EnvironmentName=MyAdap

build.folder=build

serverURL=t3://laptopedwin:7001
user=weblogic
password=weblogic1

targets=soa_server1

The ANT Build file
<?xml version="1.0" encoding="UTF-8" ?>
<project default="init">

  <property file="build.properties"/>

  <taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
  <taskdef name="wlst"     classname="weblogic.ant.taskdefs.management.WLSTTask"/>

  <target name="initAdapters">
     <!-- make an environment folder   -->
     <delete dir="${EnvironmentName}" failonerror="true" />
     <mkdir  dir="${EnvironmentName}"/>
     <!-- unpack the adapters   -->
     <unjar src="${SOA.adapters.home}/${AQ}.rar" dest="${EnvironmentName}/${AQ}" />
     <unjar src="${SOA.adapters.home}/${DB}.rar" dest="${EnvironmentName}/${DB}" />
     <unjar src="${SOA.adapters.home}/${JMS}.rar" dest="${EnvironmentName}/${JMS}" />     
     <!-- remove the jars   -->
     <delete>
       <fileset dir="${EnvironmentName}" includes="**/*.jar"/>
     </delete>
  </target>

  <target name="packAdapters">
     <!-- make a build folder   -->
     <delete dir="${build.folder}"/>
     <mkdir dir="${build.folder}"/>
     <jar basedir="${EnvironmentName}/${AQ}" destfile="${build.folder}/${EnvironmentName}_AQAdapter.rar" />
     <jar basedir="${EnvironmentName}/${DB}" destfile="${build.folder}/${EnvironmentName}_DBAdapter.rar" />
     <jar basedir="${EnvironmentName}/${JMS}" destfile="${build.folder}/${EnvironmentName}_JMSAdapter.rar" />
  </target>

  <target name="deployAll" depends="packAdapters">
     <!-- deploy AQ   -->
     <antcall target="deployAQ"/>
     <antcall target="deployDB"/>
     <antcall target="deployJMS"/>
  </target>  

  <target name="deployAQ" depends="packAdapters">
     <!-- deploy AQ   -->
     <antcall target="undeploy" >
       <param name="deployment" value="${EnvironmentName}_AQAdapter"/>
     </antcall>
     <antcall target="deploy" >
       <param name="deployment" value="${EnvironmentName}_AQAdapter"/>
     </antcall>     
     <antcall target="changeDeploymentOrder" >
       <param name="deployment" value="${EnvironmentName}_AQAdapter"/>
     </antcall>     
  </target>  

  <target name="deployDB" depends="packAdapters">
     <!-- deploy AQ   -->
     <antcall target="undeploy" >
       <param name="deployment" value="${EnvironmentName}_DBAdapter"/>
     </antcall>
     <antcall target="deploy" >
       <param name="deployment" value="${EnvironmentName}_DBAdapter"/>
     </antcall>     
     <antcall target="changeDeploymentOrder" >
       <param name="deployment" value="${EnvironmentName}_DBAdapter"/>
     </antcall>     
  </target>  

  <target name="deployJMS" depends="packAdapters">
     <!-- deploy AQ   -->
     <antcall target="undeploy" >
       <param name="deployment" value="${EnvironmentName}_JMSAdapter"/>
     </antcall>
     <antcall target="deploy" >
       <param name="deployment" value="${EnvironmentName}_JMSAdapter"/>
     </antcall>     
     <antcall target="changeDeploymentOrder" >
       <param name="deployment" value="${EnvironmentName}_JMSAdapter"/>
     </antcall>  
  </target>  

  <target name="changeDeploymentOrder" >
    <wlst failonerror="true" debug="true" arguments="${user} ${password} ${serverURL} ${deployment}">
      <script>
          adminUser=sys.argv[0]
          adminPassword=sys.argv[1]
          adminUrl=sys.argv[2]
          deploymentAdapter='/AppDeployments/'+sys.argv[3]

          connect(adminUser,adminPassword,adminUrl)

          edit()
          startEdit()

          cd(deploymentAdapter)
          cmo.setDeploymentOrder(500)
         
          activate()
          disconnect()    
       </script>
    </wlst>
  
  </target>

  <target name="undeploy">
     <wldeploy action="undeploy" 
               name="${deployment}"
               user="${user}"
               password="${password}"
               adminurl="${serverURL}"
               targets="${targets}"
               failonerror="false">
     </wldeploy>
  </target>

  <target name="deploy">
     <wldeploy action="deploy" 
               name="${deployment}"
               source="${build.folder}/${deployment}.rar"
               user="${user}"
               password="${password}"
               adminurl="${serverURL}"
               targets="${targets}"
               upload="true"
               failonerror="true">
     </wldeploy>
  </target>



</project>

Here you can download my workspace.

6 comments:

  1. Hi,

    Nice post. I followed your steps and found issues in starting up AppsAdapter while starting domain.

    Error i am getting is:
    class 'oracle.tip.adapter.apps.IAppsConnection' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/IDBConnection

    [2] The ra.xml class 'oracle.tip.adapter.apps.AppsConnection' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/IDBConnection

    [3] The ra.xml class 'oracle.tip.adapter.apps.AppsManagedConnectionFactory' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/DBManagedConnectionFactory

    [4] The ra.xml class 'oracle.tip.adapter.apps.AppsConnectionFactory' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/DBConnectionFactory.

    weblogic.application.ModuleException: [1] The ra.xml class 'oracle.tip.adapter.apps.IAppsConnection' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/IDBConnection

    [2] The ra.xml class 'oracle.tip.adapter.apps.AppsConnection' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/IDBConnection

    [3] The ra.xml class 'oracle.tip.adapter.apps.AppsManagedConnectionFactory' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/DBManagedConnectionFactory

    [4] The ra.xml class 'oracle.tip.adapter.apps.AppsConnectionFactory' could not be loaded from the resource adapter archive/application because of the following error: java.lang.NoClassDefFoundError: oracle/tip/adapter/db/DBConnectionFactory

    at weblogic.connector.deploy.ConnectorModule.prepare(ConnectorModule.java:229)

    at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)

    at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:507)

    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)

    at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:149)

    Truncated. see log file for complete stacktrace

    Same error i get when i try to access this jndi from BPEL.

    I think it is not able to find classfiles which came along with AppsAdapter.jar which we removed file creating new rar file.

    Please help.

    ReplyDelete
  2. just to tell about before issue sonehow i undeployed original resourceAdapter and with same name i created new resource adapater. And i tried both without placing jar file in application and with placing jar file but it didn;t help.

    ReplyDelete
  3. Hi,

    The original resource adapter should exists /deployed and must have a lower deployment number then your resource adapter. else it won't find the jar.

    thanks

    ReplyDelete
  4. Hi Edwin, I am trying to run the Adapter creation code but I am unable to find the WLS.fullclient=C:/java/wlfullclient.jar jar on my machine, Do you have any idea where I can get this from ?

    Also does the undeploy task undeploy the existing Adapters or only the ones we deploy after executing the build.xml.

    ReplyDelete
  5. Thanks that's worked I used weblogic.jar instead of the wlfulclient.jar and I just had to run this from cmd prompt and had to run the setWLSEnv.cmd before executing the build, which I am sure was due to some classpath settings I dont have in jdev

    ReplyDelete