Access MSMQ from Java Using J-Integra® for .NET |
This example demonstrates how to access MSMQ from Java client. J-Integra® for .NET is a Java interoperability component that bridges Java/J2EE and Microsoft .NET. It provides bi-directional access of Java objects and .NET components.
Use this example as a guideline to show you how to access a MSMQ Singleton from Java using J-Integra for .NET.
The Steps to Follow will show you how to deploy J-Integra for .NET correctly for this example. Refer to the diagram below for an overview of the scenario:
A platform with Microsoft Visual Studio .NET 2003 (7.1.3088 or higher) installed, or at least the .NET Framework 1.0.3705 or higher. This will be known throughout the example as the .NET platform.
A platform with J-Integra for .NET 1.5.1295 (or higher) installed. This will be known throughout the example as the Java platform.
A version of JDK (1.3.1 or higher) installed on the Java platform, and the bin directory included in the path. This required to compile and run the Java client.
Verify that GenService is installed correctly on the .NET platform.
Perform this step on the .NET platform.
In this step, you will need to compile the .NET code.
Load MSMQ.sln located in C:\Program Files\J-Integra\.NET\examples\java_MSMQ\MSMQ with Visual Studio .NET 2003. Press Ctrl + Shift + B to build. If successful, this should build MSMQ.exe in the bin\Debug directory.
Perform this step on the Java platform.
In this step, you will use the GenJava tool to generate Java proxies from the .NET Assembly.
Launch GenJava from the Start Menu.
Change directory to C:\Program Files\J-Integra\.NET and then enter:
java -jar lib\genjava.jar
The first screen of GenJava
prompts for the location of the .NET assembly along with the output directory
where the Java proxies will go. They should be (respectively):
- C:\Program Files\J-Integra\.NET\examples\java_MSMQ\MSMQ\bin\Debug\MSMQ.exe
- C:\Program Files\J-Integra\.NET\examples\java_MSMQ\java_client
Move on to the next step by clicking Next.
You should see a message that the proxy generation was successful. Click Finish to exit GenJava.
To compile the Java proxies, at the command-line, change directory to C:\Program Files\J-Integra\.NET\examples\java_MSMQ\java_client and enter:
javac -classpath C:\Program Files\J-Integra\.NET\lib\janet.jar;. csharp_server\*.java
Perform this step on the .NET platform.
In this step, you will need to configure and start the .NET server so it can respond to incoming TCP requests.
Along with Java proxies, GenJava generates .NET configuration files to be used as templates - one for the HTTP channel (web.config) and one for the TCP channel (remoting_tcp.config). As we will be using TCP binary, we will use remoting_tcp.config. You can find this in the same directory that the proxies were generated in.
Modify remoting_tcp.config to look like:
<configuration> <system.runtime.remoting> <application> <service> <wellknown type="csharp_server.myMSMQ, MSMQ" objectUri="csharp_server.myMSMQ.soap" mode="Singleton"/> </service> <channels> <channel port="7561" ref="tcp"> <serverProviders> <formatter ref="binary" typeFilterLevel="Full"/> </serverProviders> </channel> </channels> </application> <!-- *** IMPORTANT - Use of the customErrors element is specific to .NET 1.1 or later. *** --> <!-- *** Remove the customErrors element if running under .NET 1.0 *** --> <customErrors mode="off"/> </system.runtime.remoting> </configuration> |
Note also: The <customErrors mode="off"/> element is required in order to configure .NET Remoting to return complete exception information to both local and remote callers. Otherwise, by default it will only return complete custom exception information to callers running on the same host - details can be found here. Use of the customErrors element is specific to .NET 1.1 or later. Remove or comment out the customErrors element if you are running under .NET 1.0.
Copy remoting_tcp.config to the bin\Debug directory (where MSMQ.exe should be).
Launch MSMQ.exe and you should see the console output:
Host is ready to process remote messages. Press ENTER to exit
Perform this step on the Java platform.
In this step, you will need to configure J-Integra for .NET to act as a client to access the .NET objects. This is done through the Janetor tool.
Launch Janetor from the Start Menu.
java -jar C:\Program Files\J-Integra\.NET\lib\janetor.jar
Go to File - Open and open janet.xml located in C:\Program Files\J-Integra\.NET\java_MSMQ\java_client.
Install your J-Integra for .NET product license. See Installing the J-Integra® for .NET license for further information.
Select default under Remote Objects. Here you see that J-Integra for .NET is configured as a client to access a Singleton at the given URI and Assembly name, using TCP binary.
Before you exit Janetor, save the configuration by going to File - Save.
Perform this step on the Java platform.
In this final step, you will compile and run the Java client.
At the command-line, change directory to C:\Program Files\J-Integra\.NET\examples\java_MSMQ\java_client and enter:
javac -classpath C:\Program Files\J-Integra\.NET\lib\janet.jar;. Client.java
To run the client, in the same directory enter:
java -cp C:\Program Files\J-Integra\.NET\lib\janet.jar;. Client
You should see the following output in the Client console:
Message "Hello World!" sent. Press Enter to recieve msg...
In the Client console, press ENTER to continue the example.
You should see the following output in the Client console:
Hello World!
And should see the following output in the Server console:
myMSMQ Created. Sending message: Hello World! Receiving message: Hello World! myMSMQ Closed.