java - Where can I find the JBoss source for the implementation of 12.1 and 12.2 of the servlet spec? -


http://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-oth-jspec/servlet-3_0-final-spec.pdf

this under chapter 12: mapping requests servlets. reviewed maven repository jboss, , although spec interface available can't seem find underlying implementation of 12.1 , 12.2 regard servlet url pattern matching. i'm interested in reviewing how expressions mapped rules project.

i'm considering tomcat 7.0.42. links in below answer point 7.0.42 source code in grepcode.com.

the servlet mappings during application startup parsed , added wrapper inside org.apache.tomcat.util.http.mapper.mapper#addwrapper() source code copypasted here (note: term "wrapper" stands here "a mapped servlet"):

360     protected void addwrapper(contextversion context, string path, 361             object wrapper, boolean jspwildcard, boolean resourceonly) { 362  363         synchronized (context) { 364             wrapper newwrapper = new wrapper(); 365             newwrapper.object = wrapper; 366             newwrapper.jspwildcard = jspwildcard; 367             newwrapper.resourceonly = resourceonly; 368             if (path.endswith("/*")) { 369                 // wildcard wrapper 370                 newwrapper.name = path.substring(0, path.length() - 2); 371                 wrapper[] oldwrappers = context.wildcardwrappers; 372                 wrapper[] newwrappers = 373                     new wrapper[oldwrappers.length + 1]; 374                 if (insertmap(oldwrappers, newwrappers, newwrapper)) { 375                     context.wildcardwrappers = newwrappers; 376                     int slashcount = slashcount(newwrapper.name); 377                     if (slashcount > context.nesting) { 378                         context.nesting = slashcount; 379                     } 380                 } 381             } else if (path.startswith("*.")) { 382                 // extension wrapper 383                 newwrapper.name = path.substring(2); 384                 wrapper[] oldwrappers = context.extensionwrappers; 385                 wrapper[] newwrappers = 386                     new wrapper[oldwrappers.length + 1]; 387                 if (insertmap(oldwrappers, newwrappers, newwrapper)) { 388                     context.extensionwrappers = newwrappers; 389                 } 390             } else if (path.equals("/")) { 391                 // default wrapper 392                 newwrapper.name = ""; 393                 context.defaultwrapper = newwrapper; 394             } else { 395                 // exact wrapper 396                 if (path.length() == 0) { 397                     // special case context root mapping 398                     // treated exact match 399                     newwrapper.name = "/"; 400                 } else { 401                     newwrapper.name = path; 402                 } 403                 wrapper[] oldwrappers = context.exactwrappers; 404                 wrapper[] newwrappers = 405                     new wrapper[oldwrappers.length + 1]; 406                 if (insertmap(oldwrappers, newwrappers, newwrapper)) { 407                     context.exactwrappers = newwrappers; 408                 } 409             } 410         } 411     } 

while dealing incoming http requests, magic of finding servlet mapping starts in org.apache.catalina.connector.coyoteadapter#postparserequest().

647        connector.getmapper().map(servername, decodeduri, version, 648                                  request.getmappingdata()); 649        request.setcontext((context) request.getmappingdata().context); 650        request.setwrapper((wrapper) request.getmappingdata().wrapper); 

line 647 invokes indirectly org.apache.tomcat.util.http.mapper.mapper #internalmapwrapper() mapping data of current http request been filled context , wrapper (essentially, available servlet instance). it's quite lot of code, won't copypaste here, click grepcode link.

then, lines 649 , 650 sets mapped context , wrapper on current request. context holds concrete servletcontext instance , wrapper holds concrete servlet instance property, org.apache.catalina.core.wrapper#instance.

finally, after invoking filters, applicationfilterchain invoke servlet's service() method.


for own project, omnifaces jsf utility library, i've ever implemented matching checks according servlet spec 12.1 in webxml utility class (in rather simplified form). may helpful well, source code here, relevant extract below:

private static boolean isexactmatch(string urlpattern, string url) {     return url.equals(urlpattern.endswith("/*") ? urlpattern.substring(0, urlpattern.length() - 2) : urlpattern); }  private static boolean isprefixmatch(string urlpattern, string url) {     return urlpattern.endswith("/*") ? url.startswith(urlpattern.substring(0, urlpattern.length() - 2)) : false; }  private static boolean issuffixmatch(string urlpattern, string url) {     return urlpattern.startswith("*.") ? url.endswith(urlpattern.substring(1)) : false; } 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -