Romi Kuntsman
asked on
Embedded Jetty Server Example
Hi,
I need a working example of Jetty web server, embedded inside my application.
Tried the example from here:
http://jetty.mortbay.org/xref/org/mortbay/jetty/example/OneContext.html
But it doesn't work, possibly because it is for v6, and I have v7.
I want one (multithreaded) method to handle all the HTTP requests.
Thanks!
I need a working example of Jetty web server, embedded inside my application.
Tried the example from here:
http://jetty.mortbay.org/xref/org/mortbay/jetty/example/OneContext.html
But it doesn't work, possibly because it is for v6, and I have v7.
I want one (multithreaded) method to handle all the HTTP requests.
Thanks!
ASKER
Doesn't work: waiting for the response forever.
Opening another port shows nobody is listening.
Opening the port I attached the server to causes the browser to wait forever and never show any page.
Opening another port shows nobody is listening.
Opening the port I attached the server to causes the browser to wait forever and never show any page.
Well certainly a default maven build creates a lot of stuff, but i got it started with the following command (your paths will start differently, but should end the same) and don't forget to include servlet.jar:
java -classpath /bk/goose/tecra8000/home/java/java-libraries/httpunit-1.6.2/jars/servlet.jar:/home/goose/.m2/repository/org/mortbay/jetty/jetty/6.1.18/jetty-6.1.18.jar:/home/goose/.m2/repository/org/mortbay/jetty/jetty-embedded/6.1.18/jetty-embedded-6.1.18.jar:/home/goose/.m2/repository/org/mortbay/jetty/jetty-util/6.1.18/jetty-util-6.1.18.jar org.mortbay.jetty.example.OneContext
Java comes with a http server if you weren't aware
http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html
http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html
ASKER
:-)
Yes, I know.
And it is leaking connections.
And you are trying to help me here:
https://www.experts-exchange.com/questions/24416845/com-sun-net-httpserver-HttpServer-leaking-HTTP-connections.html
So now I'm also trying to use Jetty instead, maybe this will help.
Yes, I know.
And it is leaking connections.
And you are trying to help me here:
https://www.experts-exchange.com/questions/24416845/com-sun-net-httpserver-HttpServer-leaking-HTTP-connections.html
So now I'm also trying to use Jetty instead, maybe this will help.
> And it is leaking connections.
I'm not yet convinced it is :)
I'm not yet convinced it is :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sounds good.
>>Found out myself I needed to close and flush the output buffer
Can you explain that please?
Can you explain that please?
ASKER
Yeah sure. When I moved the code to Jetty, and started in, the connection number started climbing too.
I opened the browser on that page and it said "Waiting for [server]..." and the animation kept running, that is it was still running the page. However, I wrote all what I wanted and finished processing it.
So I realized that if my handler doesn't flush and close the output stream, then the server thread that calls it won't either. Frankly I expected more from it, especially since no example I've seen implicitly does that.
So basically I added, in the end of the handle(...) method in my Handler, the following code.
I opened the browser on that page and it said "Waiting for [server]..." and the animation kept running, that is it was still running the page. However, I wrote all what I wanted and finished processing it.
So I realized that if my handler doesn't flush and close the output stream, then the server thread that calls it won't either. Frankly I expected more from it, especially since no example I've seen implicitly does that.
So basically I added, in the end of the handle(...) method in my Handler, the following code.
ServletOutputStream out = response.getOutputStream();
out.flush();
out.close();
response.flushBuffer();
>>
Look buddy, "doesn't work" is a vague statement. Does it sit on the couch all day long? Does it procrastinate doing the
dishes? Does it beg on the street for change? Please be specific! Define 'it' and what it isn't doing. Give us more
details so we can help you without needing to ask basic questions like "what's the error message?".
>>