Using JNBridgePro

Chapter 4, “Interoperability Technologies: Point to Point,” shows how JNBridgePro lets you create .NET Framework proxies for Java classes. These .NET Framework proxies allow your .NET Framework application to interact with the native Java classes. One technique of providing asynchronous interoperability is to create proxy classes for the JMS classes on Java. This technique provides the ability to make JMS message calls from .NET Framework. This solution is somewhat different to those discussed so far, because .NET Framework would not be directly interacting with the message queues; it would be communicating through Java. Therefore, you need a running J2EE application server to provide .NET Framework with JMS access.

Figure 9.4 shows the role of JNBridge in asynchronous communications.

click to expand
Figure 9.4: The role of JNBridge in asynchronous communications


Because JNBridgePro wraps JMS, there is no special configuration required other than configuring the JMS support for WebSphere MQ.

Deciding on a Data Format for JNBridgePro

JNBridgePro wraps the JMS functionality, allowing you to place a Java object directly into the message queue. The only task from a data perspective is to create a .NET Framework proxy of the Java data object, populate this with the data from .NET Framework, and then use this object to write the message.

Creating the Message Consumer for JNBridgePro

Because the JNBridgePro adapter places a JMS message in WebSphere MQ, you can use standard JMS code for reading the message. JMS with a JNBridgePro wrapping determines the format of the message you read, so there is no need to change the data that you can send directly to the resource application. The following code example shows how to read the message from JMS.

 InitialContext ic = new InitialContext(); QueueConnectionFactory factory = (QueueConnectionFactory) ic.lookup(connectionName); QueueConnection connection = factory.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ic.lookup(queueName); QueueReceiver receiver = session.createReceiver(queue); connection.start(); ObjectMessage message = (ObjectMessage) receiver.receive(); order = (OrderData) message.getObject(); DalServiceFacade facade = getFacadeHome().create(); return facade.saveOrder(order); 

Creating the Asynchronous Interoperability Adapter for JNBridgePro

To create the asynchronous interoperability adapter, you need to expose the JMS classes from J2EE into the .NET Framework application. You can do this using the JNBridgePro proxy generation tool, in the same way that you used it to achieve interoperability as described in Chapter 7.

To create the proxy, add the j2ee.jar, jndi.jar, and jms.jar packages as well as any application-specific data classes you require to the JNBridgePro classpath. You must create proxies for the following classes:

  • javax.naming.InitialContext

  • javax.naming.NamingException

  • javax.jms.QueueConnectionFactory

  • javax.jms.QueueConnection

  • javax.jms.QueueSession

  • javax.jms.Session

  • javax.jms.Queue

  • javax.jms.QueueSender

  • javax.jms.ObjectMessage

  • javax.jms.JMSException

  • javax.jms.DeliveryMode

  • javax.jms.InvalidDestinationException

In the XBikes sample application, this list also included the classes from the package.

After you generate the proxy and configure the .NET Framework application, the .NET Framework interoperability adapter calls the proxy classes in a similar way that the J2EE application would use them. The following code sample shows how to create a new JMS message in WebSphere from .NET Framework.

 InitialContext ic = new InitialContext(); QueueConnectionFactory factory = (QueueConnectionFactory) ic.lookup(connectionName); QueueConnection connection = factory.createQueueConnection(); connection.start(); QueueSession session = connection.createQueueSession(false,    SessionConstants.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = (javax.jms.Queue) ic.lookup(queueName); QueueSender sender = session.createSender(queue); ObjectMessage message = session.createObjectMessage(order); sender.send(message); 


This it is almost identical to sending a JMS message from Java, but the language is C#.

The next section covers the same techniques but using Ja.NET instead of JNBridgePro.

Application Interoperability. Microsoft. NET and J2EE
Application Interoperability: Microsoft .NET and J2EE: Microsoft(r) .Net and J2ee (Patterns & Practices)
ISBN: 073561847X
EAN: 2147483647
Year: 2003
Pages: 104 © 2008-2017.
If you may any questions please contact us: