6

I'm writing an application which needs to be able to handle HTTP requests from an external source (in this case, it's actually a script from Second Life). I started out by using HTTPComponents by Apache, which worked great as long as the Java server only had to respond to GET requests. Now it needs to be able to receive data from the body of POST requests, and I don't see any way to do so with HTTPComponents. Is there a superior library to use for this?

I did find through some Googling that there is a basic HTTP server included in the Sun packages. For the purposes of this application, it could be required that it only run on an actual Sun/Oracle JVM implementation -- but that's still a code smell to me, and I'd probably only do so if the only option was to write my own HTTP server library from scratch, working up from sockets and such. Any suggestions for an alternative?

3 Answers 3

6

You can access the entity if the request is a HttpEntityEnclosingRequest. There is a simple example demonstrating the use of this class.

Sign up to request clarification or add additional context in comments.

Comments

2

Use Apache Tomcat. It's the standard Java web server.

5 Comments

+1 - Yeah, why not? Or Jetty - it's pretty lightweight, too. Why write anything?
I wasn't considering Tomcat or Jetty because the application isn't really serving standard HTML pages or anything similar -- it's just taking advantage of the fact that Second Life scripts can make HTTP requests. It's more of a hacked-together RMI, if anything.
Tomcat and Jetty are servlet engines; servlets are HTTP listeners. What does HTML have to do with it?
@duffymo: I remember you from the Sun Java forums back when I was a kid! I suppose they aren't around anymore with Oracle taking over...
"kid"? Oh, my. Nice to see you again, ktm5124.
0

If you want something minimal, NanoHTTPD is good. It uses only core java libraries and is a single file.

https://github.com/NanoHttpd/nanohttpd/blob/efb2ebf85a2b06f7c508aba9eaad5377e3a01e81/webserver/src/main/java/org/nanohttpd/webserver/SimpleWebServer.java

The disadvantage is that it doesn't seem to take advantage of NIO, which can really speed up network throughput.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.