Solved

Embedded Jetty Server Example

Posted on 2009-05-19
10
824 Views
Last Modified: 2012-05-07
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!
0
Comment
Question by:Romi Kuntsman
  • 4
  • 4
  • 2
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24419601
To quote dpkg:

>>
 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?".
>>
0
 
LVL 4

Author Comment

by:Romi Kuntsman
ID: 24419642
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24420407
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

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 92

Expert Comment

by:objects
ID: 24420438
0
 
LVL 4

Author Comment

by:Romi Kuntsman
ID: 24420592
:-)

Yes, I know.
And it is leaking connections.
And you are trying to help me here:
http://www.experts-exchange.com/Programming/Languages/Java/Q_24416845.html

So now I'm also trying to use Jetty instead, maybe this will help.
0
 
LVL 92

Expert Comment

by:objects
ID: 24420664
> And it is leaking connections.

I'm not yet convinced it is :)

0
 
LVL 4

Accepted Solution

by:
Romi Kuntsman earned 0 total points
ID: 24422645
Moved to Jetty v6 and it works like in the example.

To close HTTP connection, I added a call to flush() and close() on the output stream.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24422671
Sounds good.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24422898
>>Found out myself I needed to close and flush the output buffer

Can you explain that please?
0
 
LVL 4

Author Comment

by:Romi Kuntsman
ID: 24423020
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.

ServletOutputStream out = response.getOutputStream();
out.flush();
out.close();
response.flushBuffer();

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 45
SHA2 certs for IIS AND Java? 2 113
eclipse buid path vs tomcat lib path 10 34
Bot application - advice 3 37
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question