File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How two different web application communicate with each other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How two different web application communicate with each other " Watch "How two different web application communicate with each other " New topic
Author

How two different web application communicate with each other

Gajen Pingalkar
Ranch Hand

Joined: Aug 29, 2006
Posts: 37
I am dealing with 2 web application (A1 and A2). In one scenario, I am sending request from A1 (Client) to A2 (Server). Now I want to send response to A1(client - Browser). How to send this response, please provide some code for understanding.
prasad guna
Ranch Hand

Joined: Feb 12, 2009
Posts: 43

Hi

We can communicate between two seperate webapplication through some ways,

1.append the parameters whaerver you need to send with "query string" like http://example.com/actionclass? name=value&name=value

2.use common XML file for get and set the values in common location,use sax parser od dom parser for parsing xml files.


thanks


Prasath.G
SCJP
Ravi C Kota
Ranch Hand

Joined: Jan 29, 2008
Posts: 61
The other option is to open a HTTP connection to the other webapplication. You can make use of HttpURLConnection class for this purpose. There are several posts in this forum which deal with inter servlet communication, which would certainly assist you.


Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Now I want to send response to A1(client - Browser). How to send this response, please provide some code for understanding.

You can invoke A2(Server) url from A1(Client) web application just like any other browser client. If A1 and A2 are deployed in a same container then that'll save you from proving relative path to the resource (ofcourse, direct url always works). One thing you might be interested in about is "Security".
1. Should A2 web application be authenticated before accessing any of its resources?
2. What authorization priveleges are provided to A1 application to access A2 resources?

If you also need to consider the above, you can refer web.xml and server specific descriptor files (e.g.JBoss - jboss-web.xml, WAS ibm-web-bnd.xmi, ibm-web-ext.xmi files,...) for security realms.

Hope I haven't made too complicated

Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Gajen Pingalkar
Ranch Hand

Joined: Aug 29, 2006
Posts: 37
Hi Naren and others,

Thanks for your reply,
As per my query, I want to identify the browser to whom I suppose to send response (the page could be in different application). Please provide some code.
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

As per my query, I want to identify the browser to whom I suppose to send response (the page could be in different application). Please provide some code.

Not sure if I understood your question correctly. What do you mean to identify a browser? If you want to display something (jsp or servlet content) on to browser, just invoke that servlet or jsp url. Can you put down detailed scenario what you are trying to achieve?

Martin joe
Greenhorn

Joined: Sep 20, 2007
Posts: 9
identifying browser type can be done thru' JS.

there are many ways to interact with other web app
- use HTTP post. HTTPUrlConnection
- use REST

I would prefer the http post.
Gajen Pingalkar
Ranch Hand

Joined: Aug 29, 2006
Posts: 37
Hi Naren,

Please go through the attached image, you will find request-response as per the numbering on the image.
Here B1 and B2 are 2 different browsers.
Here S1 and S2 are 2 different application.

As per the scenario, I want to recognise B1 from S1, how to send response to B1?



[Thumbnail for Scenario.JPG]

Alex Hurtt
Ranch Hand

Joined: Oct 26, 2010
Posts: 98
If you are able to send a request from B1 to S2 and get a response back from S2 to B1 in steps 1 and 2, then why can't you do the same for steps 3 and 6 between B1 and S1? It doesn't seem it would be any different...it might just take longer since you have to make a request from S1 to S2 and wait for that response before you can send the response back from S1 to B1...but it should be no different from whatever you did to send a response from S2 to B1 in the beginning.
Gajen Pingalkar
Ranch Hand

Joined: Aug 29, 2006
Posts: 37
As per the business logic and security concern, I have to send request number '3' to S1 than I can forward to S2.
Do you have any solution to recognise B1 from S1 in response no. '6'.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Do you have any solution to recognise B1 from S1 in response no. '6'.


It has been asked before and let me ask again - what exactly do you mean by 'recognise'? Or to put it in another way - what do you hope to achieve by being able to recognise B1? What is it that you would do if you could recognise B1 that you are unable to do so otherwise?
Maybe if you tell us that, you will find the answer to the bigger picture than in assuming that the answer to it lies in the ability to recognise the browser.

cheers,
ram.
Gajen Pingalkar
Ranch Hand

Joined: Aug 29, 2006
Posts: 37
Recognising browser means, identify client (browser) for sending response.
See, actually I want to send response to client B1 without refreshing page. That means when B1 send request no. 3 to S1, then S1 redirect this requst to S2 and forget about client B1. After some time S1 get data from S2. That time I want to send this data to Client B1, without loosing previous data on that page (B1).

Hope this explaination not cofusing ....

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Recognising browser means, identify client (browser) for sending response.

You do not have to. Whatever you write to the output stream of the response object goes back to whoever initiated the request which in this case is the browser

See, actually I want to send response to client B1 without refreshing page.

You will have to use ajax for that

That means when B1 send request no. 3 to S1, then S1 redirect this requst to S2 and forget about client B1. After some time S1 get data from S2. That time I want to send this data to Client B1, without loosing previous data on that page (B1).

You are confused how you would achieve the interaction. Let me try explain that.

1. A Servlet on S1 receives the request.

2. Within the scope of this request
i. The servlet makes a call to S2 (using either HttpURLConnection or HttpClient api)
ii. The servlet receives a response from s1 which is extracted out and transformed if necessary.

3. The servlet now flushes back the transformed response it received from s2 back to the browser.

The pseudo-code below may help you visualize better



As you would see above, you do not have to write code to recognise the browser. Anything written to the output stream of the response is flushed back to the browser.

cheers,
ram.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How two different web application communicate with each other
 
Similar Threads
Array declaration
How to make the map of object to be garbage collected
Servlet communication
Doubt over Garbage Collection
How to order the elements in soap message?