aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Need HTTP API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Need HTTP API" Watch "Need HTTP API" New topic
Author

Need HTTP API

nige whit
Greenhorn

Joined: May 30, 2002
Posts: 7
I am writing a server program that needs to process HTTP requests.
I COULD just write a servlet, and get the webserver to parse the HTTP headers, and bundle all the info up for me, but there will be no other servlets, this will be the only class that receives HTTP requests, so it doesn't seem worth having a whole webserver in the way just to pass HTTP requests to a single class! In fact I don't think the client will accept that.
What I need is an API which can parse an HTTP request, and allow me to extract all the info from it, and then allow me to construct and send a response.
This needs to be able to operate on SSL sockets.
Anyone know of where I can find one?
nige whit
Greenhorn

Joined: May 30, 2002
Posts: 7
OK, thanks again. This IS a useful forum!
I found an open-source HTTP server at http://jigsaw.w3.org
The classes there can be persuaded to parse HTTP for you.
If anyone ever wants to know more.... well, just ask... it won't do you any good though!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Hmm. I don't know quite why you didn't get any answers, but in my case I didn't reply because I only visit each forum maybe once a week, and have only just seen your question. Most on-line systems are slower at the weekends, too.
Anyway. If you are really looking for a very simple HTTP server component, you might find that the one from Jigsaw is too heavyweight. At its heart HTTP is an extremely simple protocol. The complexity only comes with all the later additions: cookies, keep-alive, etc. etc.
For an ultra-simple starting point, take a look at something like:
http://examples.oreilly.com/jenut/HttpMirror.java
If you don't need multi-threading, and just want to return a quick, simple result (like a status page), this is pretty much all you need.
For a slightly more complex threaded example, you could check out:
http://pont.net/socket/java/prog/httpServer.java
If you need much more than that, then you really ought to check out some of the better open source servlet servers. I recommend Jetty and paperclips as well-factored and thoughful implementations. Either of these will probably be easier to cannibalize for parts or strip down for your use than the big name open-source servers like Tomcat, Resin or Jigsaw.
I hope that helps.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
nige whit
Greenhorn

Joined: May 30, 2002
Posts: 7
Thanks Frank,
I will check those other things out. You're right, I need something very lightweight.
It's a little user authentication server. The username and URL are passed as parameters in the URL in a GET request, and I return the content as "true" or "false". All through SSL of course.
I realize that HTTP is quite simple. I could have knocked up a little class to read the headers, but parsing CR/CRLF/LF/space/":" delimited text can be just time consuming to get right, and I wanted to use something that already works.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Nigel -
Please change your screen name to conform to JavaRanch's naming policy.
Thanks,


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
nige whit
Greenhorn

Joined: May 30, 2002
Posts: 7
I've done that, but I don't see why I should.
The policy is that fictitious first and last names are OK. I gave a fictitious first/last name pair as "bike" and "rider" because that describes me.
What's the problem?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need HTTP API