GeeCON Prague 2014*
The moose likes Servlets and the fly likes Communication between 2 applications - Servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Communication between 2 applications - Servlets?" Watch "Communication between 2 applications - Servlets?" New topic
Author

Communication between 2 applications - Servlets?

antonio nunes
Greenhorn

Joined: Mar 06, 2012
Posts: 3
Hi guys. I have two distinct applications, one is a Web application running in Tomcat, which uses Spring and JSF, and this application has a class with a method that does a insert operation in a Postgre database. The other application is a simple desktop application, which I use to do some text files manipulation and conversion. They both are in the same network (right now in the same machine, but I want to be able to run each one in different machines). What I need to do is: when I execute the desktop application, I want to get the data from the text file, and pass this data as variables to the Web application and run the method from the Web application that does the insert, inserting this data into the database. I know I can do this with RMI and with Servlets, but I don't know how. My preference is to use Servlets. Could you give me any hint on how to do this? Thank you!

PS: I'm sorry for my poor english (I'm from Brazil)!
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

"URL" and "URLConnection" approach to contact the Servlet from the thick client application.

http://docs.oracle.com/javase/6/docs/api/java/net/URLConnection.html

1.) Set the URL of the servlet in URL class instance and open the URLConnection.
2.) Establishing the OutputStream to the Servlet URL. The text content can be sent in OutputStream and
consumed in InputStream in Servlet side...

Without affecting the existing Servlet code logic, you can write some Adapter class(try Filters) which intercept the text input from Thick Client and does some process and sends to the Servlet.

Otherwise, Web Services approach... which will make the applications in different platforms to interact each other...


SCJP 6 [SCJP - Old is Gold]
antonio nunes
Greenhorn

Joined: Mar 06, 2012
Posts: 3
Ram Narayan.M wrote:"URL" and "URLConnection" approach to contact the Servlet from the thick client application.

http://docs.oracle.com/javase/6/docs/api/java/net/URLConnection.html

1.) Set the URL of the servlet in URL class instance and open the URLConnection.
2.) Establishing the OutputStream to the Servlet URL. The text content can be sent in OutputStream and
consumed in InputStream in Servlet side...

Without affecting the existing Servlet code logic, you can write some Adapter class(try Filters) which intercept the text input from Thick Client and does some process and sends to the Servlet.

Otherwise, Web Services approach... which will make the applications in different platforms to interact each other...



Hi. Thank you for your reply. Ok, so in my Web Application I will create a Servlet class, and then Filters or Adapter class to intercept the data, which will be send by the client application, trough the URL Connection. I got that, but I'm kind of starting with Servlets, so if I'm not asking too much, could you give me some code examples, or maybe point to a tutorial where I could read more about this?
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Just searched this Tutorial...

http://www.frank-buss.de/echoservlet/index.html

This is based on Applet-Servlet Communication... Since Applet is also standalone Java class, replace Applet with your Thick Client Java Class and you can get the touch of using URLConnection class to contact the Servlet
antonio nunes
Greenhorn

Joined: Mar 06, 2012
Posts: 3
Ram Narayan.M wrote:Just searched this Tutorial...

http://www.frank-buss.de/echoservlet/index.html

This is based on Applet-Servlet Communication... Since Applet is also standalone Java class, replace Applet with your Thick Client Java Class and you can get the touch of using URLConnection class to contact the Servlet


Ram, I understood how I could do it manually with an Applet, or JSP, etc. Now the challenge is doing it automatically. Could you give me more information on how to do this using Adapters, or Filters, or other way? Thank you again!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

paddy smith, your post was moved to a new topic. Please do no hijack other peoples' topics.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Communication between 2 applications - Servlets?