Archive for the ‘OC4J’ Category

MDB deployment in OC4J

December 24, 2006

1. Create the MDB(normal java class with @MessageDriven annotation). Set the ActivationConfigs.

@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName=”connectionFactoryJndiName”, propertyValue=”jms/TopicConnectionFactory”),
@ActivationConfigProperty(propertyName=”destinationName”,
propertyValue=”jms/demoTopic”),
@ActivationConfigProperty(propertyName=”destinationType”, propertyValue=”javax.jms.Topic”),
@ActivationConfigProperty(propertyName=”messageSelector”, propertyValue=”RECIPIENT = ‘MDB’”) } )

2. Create EJB jar deployment profile(MDBServer.deploy) for the above MDB and deploy it to OC4J server(application name = MDBServer)

3. In same project, create the MDBClient. Inject the resources @Resource(name=”jms/demoQueue”) and @Resource(name=”jms/TopicConnectionFactory”). Use connectionFactory and create connection, then session, message and send the message using producer.

4. In Jdeveloper create jndi.properties file with:

java.naming.factory.initial= oracle.j2ee.naming.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost:23791/MDBServer
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=welcome

5. Create client Jar deployment profile from Jdeveloper. This creates application-client.xml. Modify application-client.xml and add following lines for the resource reference entries(Make sure to mention the main class file name in descriptor creation)

<application-client xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd” version=”1.4″ xmlns=”http://java.sun.com/xml/ns/j2ee“>
<display-name>MDB1-app-client</display-name>
<resource-env-ref>
<resource-env-ref-name>jms/demoTopic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/TopicConnectionFactory </resource-env-ref-name>
<resource-env-ref-type>javax.jms.TopicConnectionFactory </resource-env-ref-type>
</resource-env-ref>
</application-client>

6. Deploy the deployment profile MDBClient.deploy to MDBClient.jar.

7. From command prompt containing the jar file, set class path and run :

D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>set CLASSPATH =.\;D:\installs\oc4j\j2ee\home\oc4jclient.jar;D:\installs\oc4j\j2ee\home\lib\javax77.jar;

D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>java oracle.oc4j.appclient.AppClientContainer MDBClient.jar

Output from the application server log will contain:

06/12/24 20:26:44 onMessage() – Message[ID:Oc4jJMS.Message.krishnamoorthy.64e0c3
ab:10fb4f6b670:-8000.4]

onMessage method of the MDB just does a system.out.println(message)

Note: Without creating jar of client files and if I directly run using:

D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\classes>java  -Djava.naming.factory.initial=oracle.j2ee.naming.ApplicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost:23791/MDBServer -Djava.naming.security.principal=oc4jadmin -Djava.naming.security.credentials=welcome myJMSClient.TestJMSClient

I get

Exception in thread “main” java.lang.NullPointerException
at myJMSClient.TestJMSClient.main(TestJMSClient.java:22)

So, should a JMS client be run always using AppClientContainer as :

java oracle.oc4j.appclient.AppClientContainer MDBClient.jar

Typical JCA 1.5 architecture application

September 5, 2006

arch.gif

OC4J – Connector Sample configuration

September 5, 2006

This is an example of how a oracle JMS provider is accessed by application server through the JCA architecture.

First the JMS provider is configured in application.xml through the following lines:

<resource-provider class=”com.evermind.server.jms.Oc4jResourceProvider” name=”oc4jjms”>
<description>oc4j-jms loop back resource provider</description>
<property name=”dummy” value=”dummy”/>
</resource-provider>

This is a loop back resource provider. Setting some additional properties like addressList pointing to JMS provider service URL in other machine will cause the message, connection etc., to be created in other machine.

This resource provider is accessed using JCA by means of resource adapters. In J2EE_home/config directory: oc4j-connectors.xml will have:

<connector name=”OracleASjms” path=”OracleASjms.rar”>
<config-property name=”lookupMethod” value=”resourceProvider”/>
<config-property name=”resourceProviderName” value=”oc4jjms”/>
..

</connector>

The resource adapter archive for the above OracleASjms.rar is :

  1. META-INF
    1. oc4j-ra.xml
    2. ra.xml
  2. grja.jar

In ra.xml, we have:

<connector>

<!– resourceadapter –>

<resourceadapter>
<resourceadapter-class>oracle.j2ee.ra.jms.generic.JMSResourceAdapter

</resourceadapter-class>
<config-property>
<config-property-name>lookupMethod</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>resourceProvider</config-property-value>
</config-property>
<config-property>
<config-property-name>resourceProviderName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>oc4jjms</config-property-value>
</config-property>
..

..

</connector>

Using the configuration property in the oc4j-connectors.xml, the above connector in the resource adapter(ra.xml) is instantiated which will be the resource adapter object taking care of connecting to the JMS provider(in this case the oracle JMS, loop-back connection).

JMS – Java Messaging Service

September 5, 2006

JMS API allows applications to create, send, receive, and read messages.

When to choose JMS

  1. Provider wants the components not to depend on information about other components’ interfaces, so that components can be easily replaced.
  2. The provider wants the application to run whether or not all components are up and running simultaneously.
  3. The application business model allows a component to send information to another and to continue to operate without receiving an immediate response.

How JMS Provider fits with AS:

JMS Provider integrated with application server through the JCA. Access the JMS provider through the resource adapter. So, multiple JMS providers can be created by multiple vendors and can be fitted into different application servers.

In OC4J, default JMS Provider implementation class is com.evermind.server.jms.Oc4jResourceProvider exposed by name : oc4jjms(application.xml). This is a loop-back JMS provider. Set the additional configuration property(addressList) for connection to other machines.

<resource-provider class=”com.evermind.server.jms.Oc4jResourceProvider” name=”oc4jjms”>
</resource-provider>
This resource provider is accessed by AS components through JCA(configured in oc4j-connectors.xml)

<connector name=”OracleASjms” path=”OracleASjms.rar”>

<config-property name=”resourceProviderName” value=”oc4jjms”/>

..

</connector>

OracleASjms.rar is the resource adapter archive which will contain the resource adapter deployment descriptor.

From SUN tutorial : JMS Provider is accessed like : mq://sysname:7676/
This is connection implementation specific. Above is just an example
Thus, we have a provider exposing the service at some port.

Configuring JMS in Sun One AS

  1. Create Connection factory. Just choose type as javax.jms.ConnectionFactory and expose it through some JNDI name(like: jms/ConnectionFactory)
  2. Create Physical destinations(queue connection for point-to-point, topic for publish-subscribe).Select name as some valid name(MyPhysicalQueue or MyPhysicalTopic) and choose type as queue or topic.
  3. Create destination resource for the above destination. Expose this resource through a JNDI name for the clients.

Coding

  1. Create connection factory
  2. Create connection using connection factory
  3. Create session using connection
  4. Using session create producer passing the destination object as parameter
  5. Using producer send message.
  6. From the consumer side, create consumer passing the destination object.
  7. Call the connection.start to start the message delivery process
  8. use consumer.receive to receive message.
  9. Additionally create message listeners and register with consumer so that consumer will call the onMessage method of the consumer when message arrives. No need to code consumer.receive to receive and process message.

Configuration for setup JMS across systems

Earth is local system and Jupiter is remote system. Setup the following configuration:

  1. Create connection factory named jms/JupiterConnectionFactory in jupiter.
  2. create connection factory in earth with same name, but set the AddressList property for this connection factory to the name of remote system (like :mq://sysname:7676/e).
  3. Create queue in Jupiter and in earth with same name.
  4. Now, when earth creates connection, it will be a connection to remote system(jupiter) and hence message creation, session etc will take place in jupiter for process running in earth. queue creation in earth is for compilation purpose only as it doesn’t hold anything in this case. It is the queue of jupiter that is used as destination in this case.

OC4J – JCA – Resource Adapters

September 5, 2006

JCA : J2EE Connector Architecture for minimizing the efforts between the EIS(Enterprise Information Systems: which can be ERP, database or legacy applications) vendors with the application server vendors.

Resource Adapter :Software driver for connecting the application server components or the client to an EIS. Provides : connection pooling, transactiion management, security etc.,

CCI : Common Client Interface – Standard client API for application components to access EISs.

Packaging of resource adapter: 

  1. /META-INF/ra.xml (deployment descriptor for resource adapter)
  2. /ra.jar
  3. /cci.jar

Deploying resource adapter:

  • Standalone deployment
  • Embedded deployment : RA first assembled in to J2EE application and then application(.ear) deployed to AS

For embedded deployment:

<application>

<module> <connector>embedded_ra.rar</connector></module>

</application>

 Lookup Resource Adapter in application :

Context ic = new InitialContext();

DataSource ds = (DataSource)ic.lookup(“java:comp/env/eis/MyEIS”);

oc4j-ra.xml

Specifying the following in oc4j-ra.xml

<resource-ref-mapping name=”eis/EIS” location=”eis/MyEIS” />

the resource adapter can be looked up using logical name as :

DataSource ds = (DataSource)ic.lookup(“java:comp/env/eis/EIS”);