Welcome!

Related Topics: Microsoft Cloud, Java IoT

Microsoft Cloud: Article

Java & .NET: SOAP Over JMS Interoperability

Exposing a Java Web Service via JMS using Apache Axis 1.4 and consuming it from both Java and .NET clients

.NET SOAP over JMS
Boiled down, this JMS solution hijacks the SOAP request before it goes over the wire, sends it over JMS, listens for a response via JMS then returns the SOAP response back to the caller, allowing it to finish processing. We only pass the SOAP through the system - we don't have to do anything special to generate it, process it, serialize it, or deserialize it. We let .NET do the heavy lifting that it was going to do anyway.

Normally, a Web Service will use an HTTP URI. When the Web Service proxy makes http calls, it causes the WebRequest.Create() method to produce an instance of HttpWebRequest. The proxy generates the SOAP, hands it off to the HttpWebRequest, which sends it over the wire, gets a response, and then sends that to the HttpWebResponse. Finally, the proxy takes over again.

We're going to take advantage of the "pluggable protocol" feature in .NET to make using JMS almost transparent. We say "almost" because we don't want to supersede HTTP in all cases - just for certain services. First, we'll need to know what flavor of JMS we're using. For this article, we're focusing on ActiveMQ because it's freely available and already has a pure .NET API. The .NET API we use is from Spring.NET. There are other options, such as OpenMQ and Tibco. Even if there were no .NET APIs already, we could wrap a dll. If the API existed only in Java, there are technologies such as JNBridge that can bridge technologies.

Once the JMS API is selected, we need to create several components: an ActiveMqWebResponse, an ActiveMqWebRequest, an ActiveMqWebRequestCreate, and an ActiveMqSoapStream - a specialized stream for hijacking the SOAP. These classes are custom versions of the components used in the normal flow of HTTP Web Services. Then, of course, we need a consumer.

ActiveMqSoapStream
The specialized stream is where we do the fancy footwork to hijack the SOAP. We don't want the proxy to realize it's dealing with a special stream. This class inherits System.IO.Stream and is mostly a pass-through to an encapsulated stream. The primary difference is that it overrides the Close() method called by the base WebRequest. Instead of closing the stream, this method rewinds the inner stream so our hijacking code can process the stream from the beginning. It also has an internal close method that our ActiveMqWebRequest will call to truly close the underlying stream when it's done with it, otherwise the stream would stay open indefinitely.

public class ActiveMqSoapStream : Stream
{
    private Stream m_Stream;
    public override void Close()
    { m_Stream.Position = 0;}
    internal void InternalClose()
    { if (this.CanSeek == true) m_Stream.Close();}
}

ActiveMqWebRequest
The ActiveMqWebRequest is where the bulk of the work happens. It inherits from System.NET.WebRequest and implements the abstract methods and properties. There are a few custom properties for JMS-specific information such as the address, username, password, and queue name. We also have a field of type ActiveMqSoapStream.

public class ActiveMqQueueWebRequest : WebRequest
{
    protected ActiveMqSoapStream m_RequestStream;
    private string _password;
    private string _username;
    private string _queueAddress;
    private string _queueName;
    ...

For brevity's sake, I won't go into the details of the property accessors or pass-through methods. The methods we're most interested in are GetRequestStream() and GetResponse(). GetRequestStream() is where we replace the default stream with our own.

public override Stream GetRequestStream()
{
    m_RequestStream = new ActiveMqSoapStream(new MemoryStream(), true, true, true);
    return m_RequestStream;
}

GetResponse() is where we send the request, listen for a response, and then put the response in a return stream. This is the workhorse of the class. The first thing we do is access the SOAP stream as an array of bytes.

public override WebResponse GetResponse()
{
    byte[] bytBody = new Byte[m_RequestStream.Length];
    m_RequestStream.Read(bytBody, 0, bytBody.Length);

Next we create the connections we're going to be using. We create a temporary queue as a response destination. This lets us have a request/response model instead of an asynchronous model. If we wanted an asynchronous model, we could listen to a permanent queue and then use the correlation ID to match the response to our request.

   ConnectionFactory connectionFactory = new ConnectionFactory(_queueAddress);
   try
   { using (IConnection connection = connectionFactory.CreateConnection())
     { using (ISession session = connection.CreateSession())
       {
         //Create a temporary queue so we can listen for the response
         ITemporaryQueue queue = session.CreateTemporaryQueue();
         using (IMessageConsumer consumer = session.CreateConsumer(queue))
         {


More Stories By Stanimir Stanev

Stanimir Stanev is a senior consultant at MomentumSI's Enterprise Architecture Solutions practice. He has many years of experience focusing on providing enterprise architecture and strategy expertise to companies looking to migrate to or maximize the advantages of SOA principles.

More Stories By Rob Bartlett

Rob Bartlett is a senior consultant at MomentumSI's Software Development Solutions practice. He has over a decade of experience in technical roles, guiding major corporations in the design, implementation, and integration of business solutions.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Latest Stories
As organizations shift towards IT-as-a-service models, the need for managing and protecting data residing across physical, virtual, and now cloud environments grows with it. Commvault can ensure protection, access and E-Discovery of your data – whether in a private cloud, a Service Provider delivered public cloud, or a hybrid cloud environment – across the heterogeneous enterprise. In his general session at 18th Cloud Expo, Randy De Meno, Chief Technologist - Windows Products and Microsoft Part...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
Andi Mann, Chief Technology Advocate at Splunk, is an accomplished digital business executive with extensive global expertise as a strategist, technologist, innovator, marketer, and communicator. For over 30 years across five continents, he has built success with Fortune 500 corporations, vendors, governments, and as a leading research analyst and consultant.
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
In this presentation, you will learn first hand what works and what doesn't while architecting and deploying OpenStack. Some of the topics will include:- best practices for creating repeatable deployments of OpenStack- multi-site considerations- how to customize OpenStack to integrate with your existing systems and security best practices.
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Archi...
Digital transformation has increased the pace of business creating a productivity divide between the technology haves and have nots. Managing financial information on spreadsheets and piecing together insight from numerous disconnected systems is no longer an option. Rapid market changes and aggressive competition are motivating business leaders to reevaluate legacy technology investments in search of modern technologies to achieve greater agility, reduced costs and organizational efficiencies. ...
"With Digital Experience Monitoring what used to be a simple visit to a web page has exploded into app on phones, data from social media feeds, competitive benchmarking - these are all components that are only available because of some type of digital asset," explained Leo Vasiliou, Director of Web Performance Engineering at Catchpoint Systems, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
It is ironic, but perhaps not unexpected, that many organizations who want the benefits of using an Agile approach to deliver software use a waterfall approach to adopting Agile practices: they form plans, they set milestones, and they measure progress by how many teams they have engaged. Old habits die hard, but like most waterfall software projects, most waterfall-style Agile adoption efforts fail to produce the results desired. The problem is that to get the results they want, they have to ch...
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
For far too long technology teams have lived in siloes. Not only physical siloes, but cultural siloes pushed by competing objectives. This includes informational siloes where business users require one set of data and tech teams require different data. DevOps intends to bridge these gaps to make tech driven operations more aligned and efficient.
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
Without a clear strategy for cost control and an architecture designed with cloud services in mind, costs and operational performance can quickly get out of control. To avoid multiple architectural redesigns requires extensive thought and planning. Boundary (now part of BMC) launched a new public-facing multi-tenant high resolution monitoring service on Amazon AWS two years ago, facing challenges and learning best practices in the early days of the new service.