Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Those Jenkins classes are bound to URLs by using Stapler. The singleton Hudson instance is bound to the context root (e.g. "/") URL, and the rest of the objects are bound according to their reachability from this root object. For Stapler uses reflection to recursively determine how to process any given URL. A few examples of how the URL /foo/bar could be processed:

  • A getFoo(String) is defined on the Jenkins object, and Stapler passes bar as a parameter. The object returned has a method called doIndex(…) that gets called and renders the response.
  • getFoo() or doFoo() are defined. They return an object that has a getBar or doBar method. The object returned from that has an associated index.jelly or index.groovy view.
  • getFoo() or doFoo() are defined. The object return has a view named bar.jelly or bar.groovy defined.

A number of additional ways to handle requests exist, but these are the most common.

As a real-world example, there's the Hudson.getJobJenkins#getJob(String) method. So the URL /job/foo/ will be bound to the object returned by Hudson.getJobJenkins#getJob("foo") (which would be a Project named foo.

Additionally, objects can implement one of two interfaces to further control how Stapler processes URLs:

  • StaplerProxy allows delegating the processing of a URL to another object

...

  • . So, for /foo/bar, if getFoo() returns an object x that implements StaplerProxy's getTarget() method, Stapler will call x.getTarget() and continue using that to process the rest of the URL (bar). This has the highest priority among all possible URL processing options.
  • StaplerFallback allows delegating the processing of a URL to another object, similar to StaplerProxy, but has the lowest priority among all possible URL processing options.

See stapler documentation for more about how it binds Java object model to a URL hierarchy.

Views

Jenkins model objects have multiple "views" that are used to render HTML pages about each object. Jenkins uses Jelly as the view technology (which is somewhat similar to JSP+JSTL.) Views are really like methods, and each of them work against a particular class. So the views are organized according to classes that they belong to, just like methods are organized according to classes that they belong to. Again, see the stapler project for more about how this works.

...