Sending the data from one webapplication to different web application? - java

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.

Related

HTML Interface for Java based Server Management

Say I have a Java HTTP server which serves REST APIs like GET/PUT/POST etc based on Jetty. I want to create a HTML interface for this server so that I can turn on/off certain features, control settings, surface server metrics etc through it.
Is there any such Java library I can use for this purpose?
I can see 2 main directions to go:
Jetty has a built-in servlet-jsp engine support that you can use for your dynamic configuration HTML pages. You can make your configuration in jsp supported forms and dispatch their processing to servlets to make the configuration model change.
An other way is to extend your REST API with the configuration relevant part and interact with it from javascript from config HTML pages.
You do not need to deploy further jars neither for 1 nor for 2.
1. is built in
2. is already deployed by you because you are using a REST implementation already
If you have a complex configuration logic with more HTML pages you might consider using JSF instead of JSP.

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.

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

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.

Communication between rest services hosted on different tomcat servers

I have a scenario where i am hosting different java Rest Services on different Tomcat instances (different machines). These projects running on the tomcats do not have any UI. For simplicity's sake, lets assume that the user will directly enter some URL in the browser (or curl) to avail these services. Now I need this service to be able to talk to (call functions) the services available in the other tomcat instance.
For eg. If TomcatInstance1 gets the call, and all this does is act as a 'router' to the different services, i want it to be able to place the Rest call for the other 'service' available on, say, TomcatInstance2. Is this possible?. If so, how to achieve that? (Tried searching for similar questions on SO, couldnt find any). Are there any online reference for the same?
PS: Hosting the services in the same Tomcat Instance is against the requirement that I'm having.
That is completely possible. You can use (for example) Jersey-client (http://jersey.java.net/) to make the queries to the other RESTful web services in the other Tomcat instances. Only need to define the correct URIs of the end points and query them according the the API exposed and call it (like you were a client from a browser, or curl).
See here a nice example of using Jersey-client to do that: http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-jersey-client/
I would suggest Spring Restful api ( http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch18s02.html , http://www.mkyong.com/spring-mvc/spring-3-rest-hello-world-example/ ).
As #emgsilva mentioned the only thing you need to do is to point correct uris between each other.
The beauty of spring restful api is it is simple to use and you don't deal with any serialization - deserialization.

reading web.xml init-params from client gwt

I have a gwt appengine app that I am building. It has a web.xml file with some init-params in it. On the client side I am using a java class with an 'onLoad()' method. This is a plain 'EntryPoint'. I would like to read those init-params from the web.xml file when the page is loading. I know I can read them from the server side using getServletConfig().getInitParameter("string") but what I want to do is to read that init-param from the client side. Is there a simple way? Everything I read tells about doing this from a Servlet. Any help would be appretiated.
You are client side and you want information which are server side, so you need to use a technology to do so ,the servlet is the one that will allow you to collect information and send back the result to you client which will be processing it asynchrously.
You can fetch those values from Server ( servlet ) by either GWT-RPC or GWT JSON
GWT JSON Turorial - https://developers.google.com/web-toolkit/doc/latest/tutorial/JSON
GWT RPC Tutorial - https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC
You can find tutorial examples in the sample folder of the GWT zip files.
Note : Both approaches have pros and cons and you can decide on their feasibility based on you application scope.
GWT-RPC is widely used if it is complete end to end java on client and server.
GWT-JSON is used more often when fetching data from non java server.

Categories

Resources