Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What sort of Java to use with my Tomcat server?

 
Isla Haper
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This site kept appearing in my google quest for information so I thought I'd ask here directly.

I have spent the last few weeks figuring out how to deploy a tomcat6 server on a linux machine and it has an ajp connector set up also. Its all up and running now and I've played with some of the examples and they are all working.

What I am trying to do next is to make a standard java program to run on a client machine, not a browser based client.

I want this java program to send a simple String to the tomcat server where it will be processed and return a string.

I've looked at the sun tutorial on sockets but couldn't get it working and was told it wasn't an ideal solution. Could someone advise or link to some tutorials for something suitable?

Thanks in Advance,

Isla
 
Tim Moores
Bartender
Pie
Posts: 2496
10
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If for some reason you're set on using Tomcat as the server, then using HTTP makes more sense than using raw TCP/IP sockets. Here's an example of how a Java desktop app might access a servlet running inside Tomcat: http://www.exampledepot.com/egs/java.net/ReadFromURL.html. The URL can contain parameters so that the servlet's response can vary according to the input it gets.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also read http://www.exampledepot.com/egs/java.net/Post.html (which is linked to from that page) for how to do a POST request instead of a GET request.
 
Isla Haper
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys, I'll try out the HTTP method.

But if I really really wanted to do sockets could I do it?
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends what you want to connect to. You can always implement HTTP requests with raw sockets but you really don't want to. You can connect to the AJP connector directly if you understand its communication protocol. You can have a web application start a separate server socket and connect to that. However, the simplest way remains using URL and HttpURLConnection (or a library with a higher abstraction level like Apache's HttpClient) to connect to an existing HTTP servlet or JSP page.
 
Isla Haper
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, sorry if I sound a bit dumb, its all very new.

The functionality I want is identically to that shown in in the knock knock tutorial: http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html

Is there a tutorial showing a similar thing for HTTP?

Edit: Also seen as the client program will be a GUI run locally on the desktop will HTTP still be the right tool for the job?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main reason why you'd want to use the Http connection classes instead of brute-force socket communications is the extra support you'll get.

The HTTP classes use the raw sockets as their underpinning, but they automatically handle the unique requirements of the HTTP protocol. They automatically manage headers and cookies, they parse out HTTP objects and response codes, and they make it simpler to construct a POST data stream.

It really doesn't matter about the form and nature of the client. Regardless of whether the client is a stand-alone Application, an applet, a mobile app or something else entirely (including another server), you'll benefit by using the Http classes if you intend to talk to an HTTP server like Tomcat.
 
Isla Haper
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, half the battle is understanding the different methods.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic