-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetty 12 - Introduce PathMappingsHandler #8748
Conversation
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
If we are ok with the idea of this, I'll write up some better javadoc for that class. (add some better tests for contexts other than |
|
||
PathMappingsHandler pathMappingsHandler = new PathMappingsHandler(); | ||
pathMappingsHandler.setHandler(new SimpleHandler("WrapperFoo Hit")); | ||
pathMappingsHandler.addMapping(new ServletPathSpec("*.php"), new SimpleHandler("PhpExample Hit")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example 1 (of 2) that might be useful for FCGI (to PHP) Proxy.
This one relies on no-match behavior to fallback to the wrapper (which would be the ResourceHandler in the FCGI case)
pathMappingsHandler.addMapping(new ServletPathSpec("/"), new SimpleHandler("FakeResourceHandler Hit")); | ||
pathMappingsHandler.addMapping(new ServletPathSpec("/index.html"), new SimpleHandler("FakeSpecificStaticHandler Hit")); | ||
pathMappingsHandler.addMapping(new ServletPathSpec("*.php"), new SimpleHandler("PhpHandler Hit")); | ||
contextHandler.setHandler(pathMappingsHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example 2 (of 2) that might be useful for FCGI (to PHP) Proxy.
This one relies on default servlet pathspec behavior to use the resource handler for non-php requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a bad idea, but needs some work.
Maybe there should be a common ancestor of this and ContextHandlerCollection
that handles the whole Handler.Container
conversation about descendants and bean management. Then some abstract methods can be used to make it either a ContextHandlerCollection
or a PathMapHandlerCollection
?
Maybe Handler.Collection
is already that common ancestor?
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Outdated
Show resolved
Hide resolved
See also the vaguely related #8676 |
Perhaps we should look at the feedback I've given in this PR and put it into a "How to write a Handler" guide documentation? Calling all tech writers!!!! |
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/PathMappingsHandler.java
Outdated
Show resolved
Hide resolved
+1 for extending |
Not a fan of Mainly because the word "Sequence" here has meaning that the PathMappingsHandler isn't doing. |
But |
Extending from public void addHandler(Handler handler);
public void addHandler(Supplier<Handler> supplier);
public List<Handler> getHandlers();
public List<Handler> getDescendants();
public <T extends Container> T getContainer(Handler handler, Class<T> type); |
Also, why does |
They can all have reasonable meanings for your handler:
Handler.Wrapper is a Container because it is a See Having all this stuff correct is important, so we can dump, find, manipulate handlers in a consistent way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got one niggle, but will approve as I'm out of office for rest of today.
Niggle is make sure you remove the bean of any replaced handlers.
throw new IllegalStateException("addMapping loop detected: " + handler); | ||
} | ||
|
||
mappings.put(pathSpec, handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this return an old handler that was replaced? If so, then that needs to be removed as a bean and probably returned from this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no replacement, the mappings are a Set
or Index
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened Issue #8764 to address this later
New Handler allowing sub-handlers to be selected via a PathMappings configuration.