-
Notifications
You must be signed in to change notification settings - Fork 19
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
Redirect from HTTP filter does not work #6
Comments
RAP version used: 3.18 |
Thanks, RAP 3.18, or to be more precise, RAP <3.21 reflects my theory, because with 3.21 M1 we changed the implementation from XHR to fetch in order to support such use cases. I'll discuss this with @ifurnadjiev next week before building our M2. |
Please try the latest stable build 3.21 M1 from our download page [1] and let us know if it's working for you. |
I've tested with target platform https://download.eclipse.org/rt/rap/3.21/M1-20220415-1308/ The redirect with
|
Try: public class RedirectFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest r = (HttpServletRequest) request;
HttpSession session = r.getSession();
String url = (String) session.getAttribute("redirect");
Display display = (Display) session.getAttribute("display");
if (display != null && url != null) {
session.removeAttribute("redirect");
session.removeAttribute("display");
ProtocolMessageWriter messageWriter = new ProtocolMessageWriter();
messageWriter.appendHead("redirect", url);
messageWriter.createMessage().toJson().writeTo( response.getWriter() );
} else {
chain.doFilter(request, response);
}
}
} |
In your example |
Thanks Ivan, the method with the ProtocolMessageWriter is working fine. But it does not work in the UI thread. Something like this works in any circumstance: public static void redirect( ServletResponse response, String url )
throws IOException
{
if( Display.getCurrent() == null )
{
ProtocolMessageWriter messageWriter = new ProtocolMessageWriter();
messageWriter.appendHead( "redirect", url );
messageWriter.createMessage()
.toJson()
.writeTo( response.getWriter() );
}
else
{
ContextProvider.getProtocolWriter()
.appendHead( "redirect", url );
}
} |
The above code also works in RAP 3.18 |
But still there is one problem, when RAP is not yet loaded, the redirect does not work, because there is no script yet to execute the redirect. In this case I need to redirect with There are this three situations:
I can detect 2 and 3, but not 1. Is there a way to tell, that RAP has not yet loaded on the client from a server side filter? |
In this example, the first redirect then fails ( @Override
public void doFilter( ServletRequest request, ServletResponse response,
FilterChain chain ) throws IOException, ServletException
{
HttpServletRequest r = (HttpServletRequest)request;
HttpSession session = r.getSession();
Boolean first = (Boolean)session.getAttribute( "first" );
if( first == null )
{
session.setAttribute( "first", true );
Redirect.to( response, "http://some-auth-server:8080" );
}
else
{
String url = (String)session.getAttribute( "redirect" );
if( url != null )
{
session.removeAttribute( "redirect" );
Redirect.to( response, url );
}
else
chain.doFilter( request, response );
}
} Resulting with the page showing |
Usually the first request is a GET request, the other (after UI session is initialized) are POST. You could try to build something around it. Please note that ServerPush requests are also GET requests and you have to recognize them by "servicehandler" property. |
So I can use |
Copy of Bugzilla bug 579790
Example project showing the issue: example.redirect.zip (@mknauer: added target definition, launch configuration, modified dependencies)
When trying to redirect from an HTTP filter (extension
org.eclipse.equinox.http.registry.filters
), it fails with the following details:In the attached example project, there are four different methods for redirecting. But when called in the filter handler, even the JSON redirect does not work.
Is there some other way to make the redirect work from filter code (because this is needed for openID connect authentication)?
It would be best if
HttpServletResponse.sendRedirect()
would work in any circumstance.The text was updated successfully, but these errors were encountered: