How to access one web application from another web application (jsp) - java

I have two web applications in jsp:
1st application is running on tomcat 6
2nd is running on tomcat 7 which resides on different machine
now I want to call the jsp of 2nd web application from 1st web application and also want to pass some data during run-time.
So how can I achieve that, please suggest me some solution.

It was very simple both will be running on some URL alone so redirect that to other. The major thing you should concentrate on the passing data should accomplish a same data store i.e., both should point a same database or any other data storing technique. You have to design a database such that both should use the same data without any conflict.
If you want to use without any central repo you can pass the data by building it on an XML,JSON or any other technique that can act as a data carrier between two applications.

You can't directly access JSPs on a different server for various reasons (security among one of them).
What you can do:
Use an iframe to display a remote URL inline
Use a HTTP client library on one server to access the second server via HTTP
Add a JSON servlet to the second server which gives you access to the data you need. This allows you to use JSONP to access the data directly from the client or to process it with a JSON framework on the first server.

Related

Java Standalone Program to JSP communication

The following programs exist:
1. I have a java application which accepts bio potential data every second or two and stores it in the database. This is a socket server which accepts this data from multiple clients and spawns a new thread for processing it to store in the db.
2. I have a jsp page on tomcat server which reads historic client data from database (stored by application 1) and displays it on the page.
The socket server program in 1.) above is not running inside of tomcat server.
The new requirement now is : Display all of the human data coming in live on the jsp page.
Now the problem:
I will now need to pass the live data from socket server (which is stand alone) to the jsp which is running on a tomcat server.
Possible solutions:
APPROACH 1: Run the socket server in the tomcat instead of stand alone and store the frequently incoming data in a java object so the jsp can access this object every second and display it on a graph.
PROBLEM : The stand alone java application does not need to be included in a tomcat server except for the fact that the jsp needs access to the live data. Also, I have read that this is not the best way.
APPROACH 2: Expose the stand alone java application as a web service and communicate with the jsp using REST architecture.
PROBLEM : The complication of using this method is that it will not have the flexibility offered by websockets or server sent events (SSE) of auto updating the latest data. The jsp will have to keep polling for new data every one second which is also not a very good option.
I need suggestions on which is a better method for accomplishing my task. Or is there a third better way which I have completely missed.
I have a java application which accepts bio potential data every
second or two and stores it in the database
You already have the answer: just display required data from this database in your jsp page. This will be easiest solution.
I undestand that you're trying to display realtime data, but JSP itself is not designed for realtime output, you will have the delay anyway and because you already have required data in database - no need to transport it to Tomcat server.

Using a single C# SOAP webservice client access the same webservice on multiple servers

The project this concerns is about uploading structured information from Excel to a java based webserver for further processing. As the least common denominator i have chosen SOAP for the job.
For this i have written a C# add-in that accesses a SOAP service on the target server. It uses a web reference to do so. This works on a test system.
In production the client will have to access three servers and these will change over time (not daily, just normal maintenance intervals). The content of a web reference is tied to a specific server, so i will need three web references and a recompile for each server change.
My goal would be a single copy of the (restructured) web reference content so the variable content can be put in a configuration file and a server change can be effected by maintenance.
The question is the following: Has anyone of you built a solution for this? Hints and tips are welcome.

Sending the data from one webapplication to different web application?

I am using java/GWT/GXT/Spring and Hibernate. I have two webapplications deployed in tomcat as below.
WebApp1 - is webapplication with GWT/Spring/Hibernate
WebApp2 - is webapplication with JSF and spring
Now i have to send some data from WebApp1 to WebApp2 and that data has to be displayed in one screen which is there in WebApp2. For that i can provide a link in WebApp1 to WebApp2. My question is is it possible to send data from one web application to another web application?
WebApp1 will have a link to WebApp2
Thanks!
For platform independent data representation was invented the xml. Use it! A simple HTTP Post and is done.
If you want to optimize and take off the overhead, you can that too.
You will need a shared resource where you can store the information in between. For Example Database, File, System, JNDI-Tree, JMS, etc.
Be careful with accessing those resources, especially file system needs a synchronization.
a direct communication via JVM is not possible.
You can also use a REST Service to get the information transfered.
Example: WEB-APP2 needs infos from WEB-APP1, then WEB-APP2 calls Service inside WEB-APP1
If you try to build two independent views on the same dataset you have to use shared resource like I mentioned already.
Yes this is possible, try out Spring Web Services
http://static.springsource.org/spring-ws/sites/2.0/
It will allow you to speak in terms of java object from both ends. Internally it converts request to XML Soap messages but this is transparent to you as the programmer and won't have to worry about it.
I got it working using the JAXB Marshaller using STS. You can right click on the xml schema file and select the jaxb option to generate the object automatically for you. So in the end, the only thing you need to generate youself is the XML Schema file. Spring WebServices can automatically generate the .wdsl for you also.

Java application vs web service vs web application

I am developing a multi-platform (Android, iPhone, Windows and Blacbberry) mobile application. The application needs to communicate with our server for several tasks, such as retrieving buddy lists etc. The server interacts with data that is stored in a MySQL database. I intend to code the server element in Java, however I am confused by all the different types. So far, I think I have narrowed it down to three options:
1) I code the application using Jetty to accept http posts. I post XML to the server, handle it, interact with the DB and post a XML response back. I would save the application as a jar and leave it running on my server.
2)I develop a Java web service. REST/JSON/SOAP?
3)I develop a Java web application.
Whilst there are many questions already out there asking what the differences is, I am struggling to find a clear explanation as to what is the best approach in which situation. I have previously used the first approach but am assuming the second approach is the better option, I'm just not sure what the advantage is.
your 1-3 options are all variants of a "Web application".
Jetty is a Java based http server/servlet container. If you want to communicate between client and server using http, you are using an http server (although not necessarily Jetty).
A Web Service is part of a web application that conforms to a standard around how clients communicate with the server, and how the server offers up information to the clients.
A web application is a Java application that makes it services available over http.
So if you want to have your clients communicate with a server, and store info in a db, you are using a web-application.
I would recommend going with option 2 as it is more lightweight and can be parsed directly in you're web application. XML got more overhead and must be translated, while you can just serialize objects directly to JSON from you're Java application and then parse them in javascript at frontend

Process of webserver starting

This question is kind of related to our web application and it is bugging me from last few months. So we use linux server for database, application and we have our custom built java web server. If we do any change in source code of application, we build a new jar file and replace the existing jar file with new jar file. Now update to take place in live application, we just execute a HTML file which contains this kind of code :
<frameset rows="100%"?
<frame src="http://mydomain.com:8001/RESTART">
</frameset>
How does this opening of port make the application to use new jar file?
The webserver is instructed to give the /RESTART URL special treatment. This can either be through a mapping to a deployed servlet, or through a hardcoded binding to a web container action.
It is very common to have URLs with special meaning (usually protected by a password) allowing for remote maintainance, but there is no common rule set. You can see snapshots of the Tomcat Administration console at http://linux-sxs.org/internet_serving/c516.html
EDIT: I noticed you mentioned a "custom built web server". If this web server does not provide servlets or JSP's - in other words conforms to the Servlet API - you may consider raising the flag about switching to a web server which do.
The Servlet API is a de-facto industry standard which allows you to cherry-pick from a wide array of web servers from the smallest for embedded devices to the largest enterprise servers spreading over multiple physical machines, without changing your code. This means that the hard work of making your application scale has been done by others. In addition they probably even made the web server as fast as possible, and if not, you can pick another where they did.
You're sending an HTTP GET to whatever's listening on that port (presumably your web server). The servlet spec supports pre- and post-request filters, so the server may have one set up to capture this particular request and handle it in a special fashion.

Categories

Resources