Comments (12)
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.
from org.eclipse.rap.
RAP version used: 3.18
from org.eclipse.rap.
Please try the latest stable build 3.21 M1 from our download page [1] and let us know if it's working for you.
[1] https://www.eclipse.org/rap/downloads/
from org.eclipse.rap.
I've tested with target platform https://download.eclipse.org/rt/rap/3.21/M1-20220415-1308/
The redirect with sendResponse
now seems to do nothing (no error message)
The redirect from the filter class now shows the message: The application terminated unexpectedly
with the following details:
Error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Stack: _handleSuccess@http://localhost:8080/rwt-resources/3210/rap-client.js:230:3729
setSuccessHandler/this._success@http://localhost:8080/rwt-resources/3210/rap-client.js:98:784
_sendWithFetch/
from org.eclipse.rap.
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);
}
}
}
from org.eclipse.rap.
In your example response.sendRedirect(url)
is not working because of CORS.
from org.eclipse.rap.
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 );
}
}
from org.eclipse.rap.
The above code also works in RAP 3.18
from org.eclipse.rap.
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 HttpServletRespone.sendRedirect
There are this three situations:
- RAP not yet loaded, filter must redirect with
HttpServletRespone.sendRedirect
- RAP loaded, code in UI-Thread must redirect with
ContextProvider
- RAP loaded, code in non UI-Thread must redirect with
ProtocolMessageWriter
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 the first case, a redirect with ProtocolMessageWriter
would then only show the JSON in the browser
from org.eclipse.rap.
In this example, the first redirect then fails (Redirect.to
contains the code from above):
@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
{"head":{"redirect":"http://some-auth-server:8080"},"operations":[]}
from org.eclipse.rap.
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.
from org.eclipse.rap.
So I can use HttpServletResponse.sendRedirect
on GET requests that do not have the parameter servicehandler set.
The GET criteria works in my sample, I'll fix my redirect in my actual code (that uses ServerPushes) next then. Thanks for the heads up for the server push, I would have certainly missed that
from org.eclipse.rap.
Related Issues (20)
- Support for SVG Images for Actions, Commands and Menu's for HighDPI and zooming support
- Missing RAP artifacts in maven central HOT 2
- JS crash in rwt.event.DomEvent.isAltGrPressed() while drag'n'drop HOT 1
- [Grid] Index out of bounds exception when using cell selection and setItemCount HOT 2
- org.eclipse.rap.rwt.client.service.ClientInfo.getClientTimezoneOffset() returns invalid value after a daylight saving change
- Infinite loop in RAPDragTracker
- Memory leaks using Display.timerExec with push session active
- RAP version which support jboss8 HOT 17
- BridgeServlet issue
- Replace dependency to org.eclipse.osgi.services HOT 4
- Which RAP version is supporting Java 21?
- Browser controls in tabs lose scroll position in Chromium based browers HOT 2
- ServerPushSession is interrupted after a period of inactivity HOT 4
- `NullPointerException`: Cannot invoke `IProgressMonitor.beginTask(String, int)` because `monitor` is null HOT 4
- Weakness in `FileDialog` may cause `Widget disposed` error HOT 4
- Auto Suggest demo is broken
- Add 'insertText' functionality to the Nebula RichTextEditor HOT 1
- Scrolling continues unexpectedly HOT 5
- Missing RAP artifacts in maven central HOT 6
- fixFocus works differently between SWT and RWT
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from org.eclipse.rap.