-
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
Unable to get ContextHandlerCollection from server #12653
Comments
Have you tried to use See documentation:
Don't try to modify Jetty classes, very likely there is a better approach -- you are not the first one that is asking to redirect with a different status code. It's not clear if you use Jetty embedded or as a standalone server, but the above documentation should cover both cases. If still does not work, you have to be more precise to describe what the problem is. |
@sbordet Thanks for the response. I have tried Am using standalone jetty server. Details about the approach. I have written a CustomContextHandler extends ContextHandler. Within this handler, If the path equals /aaa and if webapp loaded then set status code to 302 Now to check if webapp loaded or not, i'm trying to check if there is any ContextHandler associated with "/aaa" contextPath. To get the server handlers am using server.getHandlers() return a
Note : I want to return 503 incase /aaa webappcontext failed to load. and 302 incase it loaded. |
How do you deploy the web application? Is it a Do you have a custom Jetty Context XML file? Is And the redirect is to Look at It should be enough for you to override that method, although we can certainly make it more easily configurable. If your web application is a |
@HemanthKarniyana in addition to the questions from @sbordet can you please explain how you have configured your custom BTW your code which is looking for List<WebAppContext> webapps = getServer().getDescendants(WebAppContext.class); I am somewhat perplexed that you've used a |
@sbordet A.xml
As you mentioned
I tried doing as below
Now i have added this ContextHandler to server in jetty-home/jetty.xml. But this is not able to override the webAppContext's contextHandler and still returning 301.
|
Ok, let's try a simpler solution first, i.e. disabling the redirect. In <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="Hello" class="org.eclipse.jetty.ee8.webapp.WebAppContext">
<Set name="contextPath">/hello</Set>
...
<Set name="allowNullPathInfo">true</Set>
...
</Configure> Let us know if this is enough. |
@sbordet Quick Update : Am able to achieve the requirement. I followed the below approach.
I have three conditions here - With this setup. I'm able get 302 for /aaa (loaded) and 503 /aaa (not loaded). But i have some performance concern here. Lets say a normal request comes to the server and it reaches CustomContextHandler and return false. Then the server start the cycle again ? Do you see any performance issues or any improvements. There are much simplier approach but those i found doesn't check if webappcontext is loaded or not. Simply return 302 even if the context load failed which is a false positive. |
@janbartel I think we should just have a setter with the redirect code, i.e. The approach taken by @HemanthKarniyana may work, but seems way too complicated to just change a redirect code. Thoughts? |
@HemanthKarniyana your examples are very confusing because you keep swapping the relevant context paths. Please explain precisely what it is you are trying to do. What I have understood from your previous postings is this:
Is this correct? If not, please state clearly the situation you are trying to achieve using the above @sbordet until we achieve clarity of what @HemanthKarniyana is wanting to achieve I do not see any reason to change any implementation of any class. |
@janbartel Sorry my bad posted with a confusing example before. I have updated all the code mentioned with right example. Any way am explaining here again. Webapp A is deployed and its context path is /aaa. If we receive a request to /aaa it returns 301 currently. I want to redirect to 302 instead. But the constraint here is i want to redirect only if the webapp A is successfully loaded. If webapp A successfully loaded then /aaa status code is 302 RewriteHandler and other methods return 302 irrespective of webapp loaded or not. This is the main reason i have to go through all this complex handler approach. I achieved this using two methods, Method-1 : Add a leaf handler (CustomContextHandler) Mentioned above. (Updated with webapp A contextpath /aaa for better understanding.) Method-2 : Add a root handler (CustomHandlerWrapper) and every request goes through it.
jetty.xml
Both methods are same the difference is one is sitting at the root level and other is sitting at the leaf level. |
@HemanthKarniyana I've only just tuned into this issue and to be honest I've not read anything but your most recent post. As for the 301 vs 302, why not simply extend the |
Ah - I see you may be using EE8 or EE9, where we hide the core context handler. Hmmm perhaps we need to expose those methods better... investigating... |
There is indeed more we could to to make the EE8/EE9 ContextHandler more extensible. However, there is still an alternative that might be simpler. Install two contexts at '/aaa', with the first being a simple extension of the core |
Hi @gregw , yeah i mentioned the same in method-1. Also if you maintain something like |
Jetty Version
12.0.14
Jetty Environment
EE8
Java Version
JDK17
Question
Hi, i have deployed a webapplication in jetty12 ee8.
/aaa
return 301 status code. Am trying to redirect it to 302 due to some requirements. I followed the below approach and got stuck, if some can help it would be great!I have written a customContextHandler.java and set this handlers to server with /aaa contextPath.
It return 302 as expected but Now the problem is even if the webAppContext is not loaded it return 302 which should be 503.
To achieve this am trying to get the contextHandlerCollection from server and check if there is a contextHandler for /aaa then i can confirm the webappcontext is loaded. So the condition should be
Am trying to get handlers from server.getHandler() and its returning a monitoring handler (statisticsHandler) instead of handler collection/tree.
Am i missing something? How can i achieve this.
The text was updated successfully, but these errors were encountered: