Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Information Between Web Applications (Alternative to Web Services)  RSS feed

Ludwin Barbin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this article, I will show you how to pass information from one web application to another and getting the response back.

The technologies used are:
- Java Network and I/O
- Java Security - Keystores and certificates
- Spring, Servlet, HTTP

This is similar to the concept of Web Services REST-style without using its annotations and related APIs. This means, it is much simpler to code.

So if you have a requirement for interoperability between two (or more) websites, you might find these codes helpful and scale them for your specific needs.

Here is how it works:

== SEND PHASE (source web application) ==
1. A client code SendController (Spring object) is invoked from browser (e.g., http://localhost:9081/exchangesource/send.htm?
2. SendController creates a User object (Java Bean) from the HttpRequest and marshall it to XML
3. SendController passes the XML (now the payload) to ExchangeService object (Business Facade) for sending
4. ExchangeService does the following:
a. the payload is signed which produces byte[] signature
b. the payload is encoded to UTF-8 and signature is encoded to Base64
c. the encoded payload and signature are concatenated to become the query string
5. NetworkService writes the query string to the receiving URL (e.g., http://localhost:9081/exchangetarget/receive.htm)
6. NetworkService pauses for execution

== RECEIVE PHASE (target web application) ==
1. ReceiveController (Spring object) extracts the HttpRequest object for the payload (in XML) and signature
2. ReceiveController passes the payload and signature to ExchangeService for receiving
3. ExchangeService does the following:
a. decode the payload and signature
b. verify signature against the payload
c. if signature is match, returns the decoded payload, otherwise returns an error message
4. ReceiveController unmarshall the payload (in XML) to create a User object
5. ReceiveController write the message 'success' to HttpResponse

== SEND PHASE (back to source web application) ==
7. NetworkService continues execution and reads the response
8. SendController interprets the response and do further actions

Deployment options:
1. You can deploy the attached source code into two web applications, just change their context roots
2. You can deploy as a single web application just to see the flow from one object to the next

Sample console output:

Sending user data = email:; firstName: ludwin; lastName: barbin
Received user data = email:; firstName: ludwin; lastName: barbin
Response >>> success

Jar list (in addition to your java/j2ee jars):


Here is the source code:




To generate the keystore file that contains the self-signed certificates, execute the following in the command prompt:

KeyStore password = mypwd123
alias password = mycertpwd123
first & last name = Ludwin
organizational unit = MyOrg
name of organization = MyCompany
City = Toronto
State or Province = Ontario
2-letter country code = CA

alias password = partnercertpwd123
first & last name = James
organizational unit = James Unit
name of organization = James Company
City = New York
State or Province = New York
2-letter country code = US

Ludwin Barbin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe this method is more commonly referred to as "XML over HTTP" as mechanism to integrate distinct software components
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!