Tuesday, 9 July 2013

Deploying JAR as a shared library

Deploying a JAR as shared library and accessing it from a Web Application.

I am on this project which requries me

1> Deploy a JAR file as a library

2> Deploy a .war application which references this library.

Simple right! wrong it actually took me 6-8 hours to figure out that it will not work.

So below are the general steps that you would do.

1> Creating a .jar library

create a folder for e.g. library and then create a sub folder

library/META-INF

and create files

library/META-INF/MANIFEST.MF

in the MANIFEST have the below attributes

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 19.1-b02 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle
Implementation-Title: Test
Implementation-Version: 1.0
Product-Name: Test
Specification-Version: 1.0
Extension-Name: Test

In the above files some/most of them are optional

see link http://docs.oracle.com/cd/E17904_01/web.1111/e13706/libraries.htm#i1070938

then copy the class files or packages to the library directory

from the library directory execute the below (M adds the manifest already created so that it does not create a defaul manifest)

jar -cvfM Test.jar *

so this gives us a jar file Test.jar

Deploy this to through the Administration console (http://docs.oracle.com/cd/E17904_01/apirefs.1111/e13952/taskhelp/library/DeployLibrary.html) or use the below syntax for wldeploy

java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password @Kka110480 -deploy -library D:\\Application\\shared\\library\\Test.jar

The above will deploy the library to the AdminServer

To deploy it to another server or cluster use -target option and specify server name seperated by commas.

Additionaly use -libspecver 1.0 -libimplver 2.0

libspecver to specify specification version if not specified in manifest
libimplver to specify implementation version if not specified in manifest.

So my library is installed and I am ready to deploy the application.

In the application WAR file I have the weblogic.xml have the below configuration

<library-ref>
<library-name>Test</library-name>
<specification-version>1.0</specification-version>
<implementation-version>1.0</implementation-version>
    </library-ref>

However while deploying I would always get this error

Caused By: weblogic.management.DeploymentException: Error: Unresolved Webapp Library references for "ServletContext@XXXXX[app:XXXX module:XXXX.war path:/XXXX spec-version:2.5]", defined in weblogic.xml [Extension-Name: Test, Specification-Version: 1, Implementation-Version: 1.0, exact-match: false]
        at weblogic.servlet.internal.WebAppServletContext.processWebAppLibraries(WebAppServletContext.java:2754)
        at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:415)
        at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:493)
        at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:418)
        at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:972)
        at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:382)
        at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
        at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
        at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)


And all the documents you would search on the interbet would tell you that the library is not deployed or not active.

But my library is deployed and active .(I tried re-starting a couple of times).

So I went back to basics reading the documentation.

And finally found what I was looking for EJB, Enterprise applications or JAR files deployed as shared libraries cannot be referenced from weblogic.xml they have to be referenced from weblogic-application.xml

So the above would mean that I can use a shared library in a WAR file.

So then why do we have this library-ref tag in weblogic.xml well that is becuase you can refernce WAR libraries from it. Huh!

So below are the options we have incase we want to use JAR's as shared libraries

1> Reference it from EAR file weblogic-application.xml

2> Use optional packages very clearly explained in the below link

http://middlewaremagic.com/weblogic/?p=231

Thursday, 4 July 2013

My Tryst with SOA

For a long time I have been trying to learn SOA but to no avail.

I go through several documents but they are more of a bouncer.

So I thought lets do it the regular way starting with Installation.

So this post covers my issues with SOA.

Prerequisite

1> Download Oracle Weblogic Server ( :) I already had it installed)

2> A database (I already have an Oracle XE database installed)

XE database is not supported but then I am sure it will work for a development environment for testing purpose

3> RCU.

All available for download from OTN (Oracle technology Network).

The document is going to cover several issues that I faced on the install.

Starting with creating an RCU on oracle XE database.
While Installing the RCU on Oracle XE Database.

The first problem that I faced is creating a SYSDBA user I tried using SYS but it would just not connect.

I know many of you folks out there are experienced DBA’s and you might laugh out on my knowledge but then I am from the middle ware team.
So, out of several things that I tried was using the apex GUI but could not get around it.

So I was back to the usual SQL Plus using SQL J.




So now I have a user named user1 which is a SYSDBA.

I though I could go ahead with it but turns out I was wrong.

I got two of the below errors.

ERROR rcu: oracle.sysman.assistants.rcu.backend.action.AbstractAction::handleNonIgnorableError: Received Non-Ignorable Error: Error creating PL/SQL Object WRITE_LINE:PROCEDURE

ERROR rcu: oracle.sysman.assistants.rcu.backend.action.AbstractAction::handleNonIgnorableError: Received Non-Ignorable Error: Error creating PL/SQL Object DEBUG_PURGE:PROCEDURE

This was resolved after assistance from the blogpost


And the solution is to
1>     grant execute on sys.dbms_lock to user1 with grant option

2>     set the Environment variable
RCU_JDBC_TRIM_BLOCKS to TRUE

For Windows set it through
a>     right click on My Computer -> Properties -> Click On Advanced
b>    Click on Environment Variables towards the bottom
c>     Then in System Variables add in new
There is an easier way of doing it.
Instead of double clicking the rcu.bat open a command prompt and then run the below
set RCU_JDBC_TRIM_BLOCKS = TRUE

After this cd to the RCU directory and execute rcu.bat

After this installing RCU was pretty much a cake walk just with certain messages like below







And yes, you will have to remove certain components but then that is ok because all we want is SOA.



 So remove Oracle Identity Manager, Oracl Adaptive Access Manager, Spaces and Service, portal

For the custom variables screen this oracle document was very important




Then Click Next, Next Next and then finally you get the success screen











Tuesday, 12 February 2013

IBM DB2 type 2 Driver with weblogic


Had been facing an issue where while creating a datasource with DB2 9.7 and weblogic server 12c we were continuously facing the below error

<Error> <Console> <BEA-240003> <Administration Console encountered the following error:
java.lang.ClassNotFoundException: Cannot load driver: COM.ibm.db2.jdbc.app.DB2Driver

       at weblogic.jdbc.common.internal.DataSourceUtil.testConnection(DataSourc
eUtil.java:293)
       at com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:74
6)
       at com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJ
DBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:474)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)

The same was working with weblogic 8.1 and we were just trying an upgrade.

So we start the troubelshooting.

Firstly its classnotfound and not a noclassdef a big difference please Google it and you would understand.

So a classnotfound indicates classes not present apparently there are multiple ways of adding the jar file and most of them depend on how do you start the server.

Long story short we tried everything the jars were there we could see them in the logs.

So the next step. we used -verbose:class and to our surprise the class was getting loaded a couple of lines above when the server would throw the error.

See the snippet below

[Loaded COM.ibm.db2.jdbc.app.DB2Driver from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.jdbc.app.DB2Driver$1 from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.jdbc.app.DB2Driver$2 from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.mri.DB2Messages from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.mri.DB2ErrorMessages from file:/opt/IBM/db2/V9.7/java/db2java.zip]
<Error>
<Console> <BEA-240003> <Administration Console encountered the following error: java.lang.ClassNotFoundException: Cannot load driver:COM.ibm.db2.jdbc.app.DB2Driver

The above led us to belive there was something more to the issue.

We found this Doc ID 1431921.1 and we followed it however after following it the issue was the same only the classnotfound was on a different class

i.e COM.ibm.db2.jdbc.net.DB2Driver

Finally the Oracle Rep gave us a patch Bug 13870996which resolved the issue.

Turns out after all the handwork our client wants us to use Type 4 Driver hmm n ..what a waste of time but a great learning experience though.


Thursday, 24 January 2013

Download of a Large file fails on a slow connection (CompleteMessageTimeout)


I have been working on an issue where for certain users the download would just not complete.

The issue started after we had upgraded our application server.

While Debugging further we identified a common pattern the download would error out ~ 60 Seconds..

After a bit of research we identified that this was related to Complete Message Timeout on Weblogic Server.

That is if we increase the value to above 200 and if we have a slow connection and a large file size the download would stop ~ 200 Seconds.

And the Maximum limit for the same is 480 seconds.

This is what the official document says about Complete Message Timeout.

The maximum number of seconds that this server waits for a complete message to be received. If you configure network channels for this server, each channel can override this message timeout.

This timeout helps guard against a denial of service attack in which a caller indicates that it will be sending a message of a certain size which it never finishes sending.

MBean Attribute: 

ServerMBean.CompleteMessageTimeout

Minimum value: 0

Maximum value: 480

If I remember correctly we could set -1 for earlier versions of weblogic so that we disable the limit.

I can understand a limit on the Request to guard against DOS Attacks but why limit the Response time.

To Summarize we can apply the patch for Bug:13263584 and use the below flag

-Dweblogic.CompleteWriteTimeout=seconds