2

I want to step through the jetty source code as it responds to a typical servlet request.

How can I do this?

Do I need to download the source code?

Where is the entry point where I should be setting the breakpoint?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

2 Answers2

4

Yes you can do it.

Yes, you need to download the source (unless you like to read bytecode in your debugger :) ), if you're using Maven, then you can let maven do the downloading for you

It's possible to do it with a "standard" Jetty setup, but I find it much easier to build a quick embedded-jetty server for these tasks. Even if you're not familiar with embedding jetty, it's not hard to learn, and will help you to get your head around how Jetty handles servlets. See the embedding jetty documentation

The location for the breakpoint will depend on exactly which version of Jetty you're using, and how far into Jetty's internals you want to go.

You can set a breakpoint in the constructor for HttpConnection that will allow you to look at how Jetty reads from a raw TCP/IP socket, parses the HTTP headers, and then creates a request and response object for each HTTP request.

If you just want to see how the dispatching to servlets works (the matching of requested URLs against path mappings, the instantiation of new servlets, etc) then try a breakpoint in ServletHandler.doHandle

If you want something in between, then Server.handle is a good place - that will happen after the incoming stream has been parsed, but before Jetty has made any decisions about how the request should be handled.

Tim
  • 6,406
  • 22
  • 34
1

yes, you would need to download the source code (unless you want to step through javap output). Last time i checked, i think there was a Server.handle() method which was the "main" entry point.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118