Posts Tagged ‘Weblogic 10’
WebLogic: use a startup and/or a shutdown class in a WAR
Abstract
WebLogic offers you to specify a startup and/or a shutdown class for an application. Anyway, this feature is restrained to EARs, and is not available for applications deployed as WARs. For EARs, Oracle WebLogic Server’s documentation is complete and gives basic examples: Programming Application Life Cycle Events
Yet, sometimes you need such a class even for a WebApp. You have two ways to handle this case.
Solutions
Full Weblogic!
Base
The first solution is not elegant. Open WebLogic console, go to Startup And Shutdown Classes
, then add the classes names of which main()
methods will be run on startup and shutdown, let’s say JonathanWeblogicStartup
. These classes must be available in WebLogic classpath, which is surely different from your application classpath, eg in a library $DOMAIN_HOME/lib/customized-weblogic.jar
.
Advantage of this means: if your startup/shutdown class does not evoluate often, then write it once and forget, it will be OK. Unlike, you will have to manage different versions of the JAR on each release… I assume your exploitation team may get angry at playing with classpaths and lib folders 😀
Suggestion
To improve the basic solution (and avoid your exploitation guy burst in your office), I had the following idea, that I did not experiment, but that should work:
- Keep
JonathanWeblogicStartup
- Create another class
JonathanConcreteStartup
, locate as a source in your application code. - In
JonathanStartup.main()
, callJonathanConcreteStartup
This way,
- You keep a unique JAR in classpath that you do not need to update and you can forget.
- You can add, update or remove features in your very source code.
- The exploitation teams does not become hateful at you.
Add a Listener
The second one requires a bit more work.
- Create a class implementing
javax.servlet.ServletContextListener
interface, let’s sayMyLifecycleListener
. - Implement methods
contextInitialized()
andcontextDestroyed()
. - Edit your web.xml, add the following block:
<listener> <listener-class>lalou.jonathan.MyLifecycleListener</listener-class> </listener>
- Rebuild and deploy. It should be OK
WebLogic: Unresolved Webapp Library references for … coherence-web-spi
Case
I have to integrate Oracle Coherence, or more accurately Coherence*Web, within an application deployed as a WAR in WebLogic 10.3.
Since Oracle bought both BEA and Tangosol, increasing their integration, using Coherence jars implicitely is allowed. Anyway I decided to add the following block in weblogic.xml
<library-ref> <library-name>coherence-web-spi</library-name> <specification-version>1.0.0.0</specification-version> <implementation-version>1.0.0.0</implementation-version> <exact-match>false</exact-match> </library-ref>
Then I get this error:
Caused By: weblogic.management.DeploymentException: Error: Unresolved Webapp Library references for ""ServletContext@25681165[app:risklayer-web module:jonathan-lalou.war path:/jonathan-lalou spec-version:null]"", defined in weblogic.xml [Extension-Name: coherence-web-spi, Specification-Version: 1, Implementation-Version: 1.0.0.0, exact-match: false]
Fix
Indeed, I had to deploy Coherence*Web WAR in WebLogic, in the console:
Deployments > Install > select Coherence WAR, eg: C:\jonathan\bea\coherence_3.5\lib\coherence-web-spi.war
> Next> Install this deployment as a library > Next > Target your server > Finish
Mule / MQJE001 / MQJMS2007
Case
In a Mule ESB workflow, the endpoint is a <jms:outbound-endpoint>, pointing to a JMS queue hosted on MQ Series and accessed through WebLogic 10.3.3.
I get the following stracktrace
Exception stack is: 1. MQJE001: Completion Code 2, Reason 2027 (com.ibm.mq.MQException) com.ibm.mq.MQQueue:1624 (null) 2. MQJMS2007: failed to send message to MQ queue(JMS Code: MQJMS2007) (javax.jms.JMSException) com.ibm.mq.jms.services.ConfigEnvironment:622 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/JMSException.html) 3. Failed to create and dispatch response event over Jms destination "queue://MQSERVER/AMQ.4C8A5E112285475605?persistence=1". Failed to route event via endpoint: null. Message payload is of type: JMSObjectMessage (org.mule.api.transport.DispatchException) org.mule.transport.jms.JmsReplyToHandler:154 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/transport/DispatchException.html)
Fix
On Mule config file, explicitly set the attribute disableTemporaryReplyToDestinations
at true
in the JMS outbound tag:
<jms:outbound-endpoint queue="jonathan.lalou.jms.queue" connector-ref="jmsConnector" transformer-refs="foo" disableTemporaryReplyToDestinations="true"/>
Tutorial: from an application, make a clustered application, within WebLogic 10
Abstract
You have a non-clustered installation, on the host with DNS name jonathanDevDesktop
, with an admin (port: 7001), a muletier (port: 7003) and a webtier (port: 7005) instances.
You need set your muletier as a clustered installation, with two nodes, on the same server. The second node will dedeployed on port 7007.
We assume you have a configured JMS Modules (in our case: JmsMqModule, even though the bridge between WebLogic and MQ has no impact here).
Process
Batches
- Copy
$DOMAINS\jonathanApplication\start-muletier-server.bat"
as$DOMAINS\jonathanApplication\start-muletier-server-2.bat"
- Edit it:
- Possibly, modify the debug port (usually:
5006
) - Replace the line
call "%DOMAIN_HOME%\bin\startManagedWebLogic.cmd" muletier t3://jonathanDevDesktop:7001
with
call "%DOMAIN_HOME%\bin\startManagedWebLogic.cmd" muletier2 t3://jonathanDevDesktop:7001
- Possibly, modify the debug port (usually:
Second Node Creation
- Following points are not required.
- Copy the folder
%DOMAIN_HOME%\servers\muletier
as%DOMAIN_HOME%\servers\muletier2
- Delete the folders
%DOMAIN_HOME%\servers\muletier2\cache
and%DOMAIN_HOME%\servers\muletier2\logs
- Copy the folder
- Stop the server
muletier
- On WebLogic console:
- Servers > New > Server Name:
muletier2
, Server Listen Port:7007
> CheckYes, create a new cluster for this server.
> Next - Name:
jonathanApplication.cluster.muletier
> Messaging Mode:Multicast
, Multicast Address:239.235.0.4
, Multicast Port:5777
- Clusters >
jonathanApplication.cluster.muletier
> Configuration > Servers > Select a server:muletier
- Clusters >
jonathanApplication.cluster.muletier
> Configuration > Servers > Select a server:muletier2
- Servers > New > Server Name:
- Start the instances of
muletier
andmuletier2
in MS-DOS consoles. - On the WebLogic console:
- Deployments >
jonathanApplication-web
(the mule instance) > Targets > check “jonathanApplication.cluster.muletier
” and “All servers in the cluster
” > Save
- Deployments >
- On the
muletier2
DOS console, you can see the application is deployed.
JMS Configuration
The deployment of JMS on clustered environment is a little tricky.
- On WebLogic console: JMS Modules >
JmsMqModule
> Targets > check “jonathanApplication.cluster.muletier
” and “All servers in the cluster
“ - Even though it is not required, restart your muletiers. Then you can send messages either on port 7003 or 7007, they will be popped and handled the same way.
Tutorial: Use WebShere MQ as JMS provider within WebLogic 10.3.3, and Mule ESB as a client
Abstract
You have an application deployed on WebLogic 10 (used version for this tutorial: 10.3.3). You have to use an external provider for JMS, in our case MQ Series / WebSphere MQ.
The client side is a Mule ESB launched in standalone.
Prerequisites
You have:
- a running WebLogic 10 with an admin instance and an another instance, in our case: Muletier.
- a file
file.bindings
, used for MQ.
JARs installation
- Stop all your WebLogic 10 running instances.
- Get the JARs from MQ Series folders:
providerutil.jar
fscontext.jar
dhbcore.jar
connector.jar
commonservices.jar
com.ibm.mqjms.jar
com.ibm.mq.jar
- Copy them in your domain additional libraries folder (usually:
user_projects/domains/jonathanApplication/lib/
) - Start WebLogic 10 admin. A block like this should appear:
<Oct 15, 2010 12:09:21 PM CEST> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath: C:\win32app\bea\user_projects\domains\jonathanApplication\lib\com.ibm.mq.jar;C:\win32app\bea\user_projects\domains\jonathanApplication\lib\com.ibm.mqjms.jar;C:\win32app\bea\user_projects\domains\jonathanApplication\lib\commonservices.jar;C:\win32app\bea\user_projects\domains\jonathanApplication\lib\connector.jar;C:\win32app\bea\user_projects\domains\jonathanApplication\lib\dhbcore.jar;C:\win32app\bea\user_projects\domains\jonathanApplication\lib\fscontext.jar;C:\win32app\bea\ user_projects\domains\jonathanApplication\lib\providerutil.jar>
Config
- Get
file.bindings
, copy it intouser_projects/domains/jonathanApplication/config/jms
, rename it as.bindings
(without any prefix) - Launch the console, login
JMS
>JMS Modules
>Create JMS System Module
>Name
: JmsMqModule. Leave other fields empty. >Next
> target serverMuleTier
>Finish
- Select
JmsMqModule
>New
>Foreign Server
> Name:MQForeignServer
> keep check MuleTier >Finish
- Select MQForeignServer >
- JNDI Initial Context Factory: replace
weblogic.jndi.WLInitialContextFactory
with:com.sun.jndi.fscontext.RefFSContextFactory
- JNDI Connection URL: set the URI of the folder containing the
.bindings
file, eg:file://c/win32app/bea/user_projects/domains/jonathanApplication/config/jms
- JNDI Initial Context Factory: replace
- Tab
Connection Factories
> New >- Name:
MQForeignConnectionFactory
- Local JNDI Name: the JNDI name on WebLogic side, eg:
jonathanApplication/jms/connectionFactory/local
(convention I could observe: separator on WebLogic: slash'/'
; unlike clients for which the separator in a dot'.'
) - Remote JNDI Name: the JNDI name on MQ side, eg:
JONATHAN_APPLICATION.QCF
- OK
- Name:
- Tab
Destinations
> New >- Queue of requests:
- Name:
JONATHAN.APPLICATION.REQUEST
- Local JNDI Name:
JONATHAN.APPLICATION.REQUEST
- Remote JNDI Name:
JONATHAN.APPLICATION.REQUEST
- Name:
- Queue of response:
- Name:
JONATHAN.APPLICATION.REPONSE
- Local JNDI Name:
JONATHAN.APPLICATION.REPONSE
- Remote JNDI Name:
JONATHAN.APPLICATION.REPONSE
- Name:
- NB: usually, MQ data are upper-cased and Java’s JNDI names are low-cased typed ; anyway (because of Windows not matching case?) here we use uppercase in for both names.
- Queue of requests:
- Select MQForeignServer >
Mule
This part of the tutorial deals with a case of Mule ESB being your client application (sending and/or receiving JMS messages).
- Get the archive
wlfullclient.jar
(56MB). Alternatively, you can generate it yourself: go to the server/lib directory of your WebLogic installation (usually:C:\win32app\bea\wlserver_10.3\server\lib
, and run:java -jar wljarbuilder.jar
- Copy the archive into
$MULE_HOME/lib/user
- Copy the seven jars above (
providerutil.jar
,fscontext.jar
,dhbcore.jar
,connector.jar
,commonservices.jar
,com.ibm.mqjms.jar
,com.ibm.mq.jar
) into the same folder:$MULE_HOME/lib/user
- You can launch the mule. The config file is similar to any other configuration using standard JMS.