How can I clear a UISession? - eclipse

From this link I saw that For every instance of a RAP UI, a separate UISession is created. That means that when a user accesses an entry point, that’s a new UISession. When the user reloads the page in the browser, that’s also a new UISession.
And in my application when the browser is refreshed (usually by hitting F5 or close browser and open again) and from MAT (Memory Analyzer Tool) report I see that something call UISessionImpl is created as much as the time browser refreshed. That means new UISession is created but the old sessions is still there.
So my question is "How can I clear session every time the browser refresh?".
EDIT
My code:
RWT.getUISession(myDisplay).exec(new Runnable() {
#Override
public void run() {
RWT.getRequest().getSession().setMaxInactiveInterval(1);
}
});

Have a look at this link:
https://wiki.eclipse.org/RAP/FAQ#How_do_I_get_notified_when_the_browser_window.2Ftab_is_closed.3F
"In most recent browsers, the UI session is automatically destroyed when the client's browser window/tab is closed. For older browsers, the HTTP session timeout is used to detect whether the user has left the application."
"Note that when using the RAP launcher, by default a HTTP session never expires. To change the timeout value, adjust the setting on the "Main" tab."
The link you refere to writes about RAP 2.0, maybe you need to update to the latest version 2.3.
You can reduce session timeout value like this:
RWT.getRequest().getSession().setMaxInactiveInterval(...);
To clear the session on refresh, maybe you can do:
RWT.getRequest().getSession().setMaxInactiveInterval(0);

Related

E2E test Protractor issue: redirect to another page in the same window

The website I need to test requires login. However, you have to stay in the same window to keep your login information, which means if you close the window of this page, you need to login again. This gives me the problem: when I am using protractor to test the websites, it seems like each time I use browser.get(url). It will turn off the browser and open another one for the test, then I lost my login information. So I can't test the pages I want to test. Can anybody give me some suggestions, I have not figured it out for one days. Crazy!
describe('Sample List page test', function(){
beforeEach(function(){
browser.driver.get('http://localhost:8600/#/login');
browser.driver.sleep(2000);
browser.driver.findElement(by.id('google-login')).click();
});
it('should list all the items in samples',function(){
browser.get("#/osctr/sample");
expect(browser.getTitle()).toBe("Sample");
}
});
});
In the above codes, I can't get information in the sample page because I used brower.get(url), it will open a new page which I will lose my login information.
When you do browser.driver.get(), it would open a new windown. That's how selenium-webdriver works. There was an issue opened longtime back to attach webdriver instance to an existing browser window which is now marked as NotFeasible.
If you want to keep the browser session intact, you can do browser.driver.get() in before() method instead of beforeEach() and have multiple tests that work on the same browser instance and quit the browser in after method.

How to redirect to an external url with Selenium, and come back?

I am working in perl with Selenium RC, server version 2.19.0-b09 and I cannot figure out whether it is even possible to redirect to an external URL and come back to my application. I am trying to test Facebook OAuth in my application, which means I have to go to Facebook and come back to my app.
use Test::WWW::Selenium::Catalyst 'MyApp', -selenium_args => 'injectProxyMode -trustAllSSLCertificates -debug -log /home/me/browserlog.txt -firefoxProfileTemplate /home/me/.mozilla/firefox/SeleniumUser.default/';
my $selenium = Test::WWW::Selenium::Catalyst->start({
browser => '*chrome',
});
The reason I think this is possible at all is because a custom Firefox profile and the -injectProxyMode, *chrome browser and -trustAllSSLCertificates options enable me to post to and see all the redirects in my debug log, but my Remote Control window always disappears after the redirects. I can see the PROXY URL to which Facebook is trying to send me back, e.g., a URL on my own base domain. But it looks like there is no window for it to return to. In multiWindow mode I am left with my application in a Firefox window. In singleWindow mode my tests just end and all the windows close.
I have tried both -singleWindow and -multiWindow mode. I have gotten the list of windows after I make my post to https://www.facebook.com:443/login.php... and before all the redirects. I see a single window that is never available to select_window, and it always disappears on the second iteration if I run get_all_window_names in in a while loop: a window with a name like "_e_0RWG".
So, how could I conceivably do what I am trying to accomplish with Selenium? It seems so near and yet so far.

GWT Fragment Identifier works in hosted mode and not in compiled mode (Tomcat)

I have this code below which works when running in hosted/debug mode however it does not work when deployed in Tomcat.
History.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
// call update model, and eventually app will show the appropriate view...
}
});
I code above responsibility is to catch the event when user type something like this in the browser:
http://http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997#user123
Works well in hosted mode, but when deployed in Tomcat and accessed via the browser:
http://127.0.0.1:8888/index.html#user123
it shows blank page.
EDIT: Unless gwt app is first loaded and typing FI works.
Please read this: What is need History.fireCurrentHistoryState() in GWT History?
When you load http://127.0.0.1:8888/index.html#user123 for the first time, you registered your history handler after the history event has already happened. If you reload the page then it will fire.
You need to call History.fireCurrentHistoryState() after you registered the history handler to "re-fire" the event.

GWT - gwt.codesvr= tag being removed

I'm working on a GWT application.
I wish to debug the client side Java code.
I start up the application from Eclipse in debug mode.
The app starts in the browser with the gwt.codesvr= set correctly.
I can debug at this stage.
The app then redirects to the a different jsp page.
The gwt.codesvr= parameter in the URL is dropped.
The app uses History.newItem("xx") quite a bit (as described in http://code.google.com/webtoolkit/articles/mvp-architecture.html#history)
The problem is that I can't now debug the client side code.. as the
gwt.codesvr= parameter has been dropped from the URL.
When I attempt to add it back in, the app History handling code runs,
and the parametes is immediately dropped again.
I checked this on another PC and the same behaviour occurs.
I checked in Chrome and IE8 and the same..
What is the solution ?
Thanks A million,
Fergal.
History.newItem() keeps the query string intact (in this case, the ?gwt.codesvr=... part), so these calls shouldn't be the problem here.
You say, that the app redirects to a different jsp page. Find out, how it does that - it may use something like Window.Location.replace(newURL). Make sure, that newURL contains the gwt.codesvr=... part in its query string.
If the server performs a redirect itself (e.g. if it redirects after a POST request), then make sure, that the server adds the query string in the redirect URL. (You will probably have to submit your codeserver URL with the POST parameters in this case - because this is a client-side concept, and the server cannot simply guess it.)

FB.getLoginStatus not calling its callback

The title really says it all. Under some (undetermined) conditions FB.getLoginStatus() just stops working and won't invoke the callback I gave it. The only interesting clues I've found are
FB.Auth._loadState is stuck on "loading" -- whatever is supposed to make it click over to "loaded" isn't happening
slight delays like putting in alert() calls tend to make it start working
Any hints at all about even how to investigate this welcome.
This usually happens for me when I am running the page under a different domain from what has been registered in Facebook. Typically this is when I am developing locally.
If you are running locally, you'll have to set up a local web server and then modify your hosts file to point the the registered domain to 127.0.0.1 in order to test on your local machine. Don forget to remove that line from the hosts file when you want to test it on the server.
According to:
https://developers.facebook.com/bugs/240058389381072
You cannot put your application under sandbox mode, or else it won't work. Go into your app settings, advanced, and switch it. This stumped me for a couple hours until I happened upon the bug report.
I had similar problem with FB API. It turned out, that my Facebook App was misconfigured. Please make sure that this is not the case for you. My problem was that my "Site URL" param in FB application was pointing to https, but I was using http protocol for development. Any call against FB api after FB.init was not calling my callback functions. So the first thing to do should be to double check App config.
Now, if some reason you depend on FB api but you wish to have a fallback option in case it;s inoperative - workaround with timer should be ok for you. Just set up a timer and disable it if FB Api gives you proper response. If not - fallback to some custom function which will perform some additional logic.
function callFbApi() {
var timeoutHandler = setTimeout(function() { requestFailed(); }, 1000);
function requestFailed() {
// When this happens, it means that FB API was unresponsive
doSomeFallbackWork();
alert('hey, FB API does not work!');
}
FB.getLoginStatus(function(response) {
clearTimeout(timeoutHandler); // This will clear the timeout in case of proper FB call
doSomeUsualWorkAfterFbReplies();
return false;
}, true);
}
If your application is in sandbox mode, Facebook acts as if your application is invisible to anyone who is not listed as an application developer. If you're not logged in, then it would stand to reason that your app is now invisible.
The callback will only fire if you're initializing with a visible application. Otherwise the following response is returned:
<span>Application Error: There was a problem getting data for the application you requested. The application may not be valid, or there may be a temporary glitch. Please try again later. </span>
For more info please see my comment on this bug ticket:
https://developers.facebook.com/bugs/240058389381072
Maybe you are using the asynchronous call. The same thing happened when I called FB.init with window.fbAsyncInit. All I did was delay the FB.getLoginStatus with a setTimeout function
window.setTimeout(checkLogStatus, 1000);
function checkLogStatus(){
alert("check");
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
}
It seemed to work after that
On the new version of the Developer app, you have to make sure to have put the correct URL you are using to access the application in the Website field under the
Select how your app integrates with Facebook
section.
Make sure the protocol is HTTPS and not HTTP.
I had a similar problem. The site worked every time when I was opening the browser, but fails when I tried to reload.
The cause was the missing "www" on the site name on Facebook configurations. Note that putting "www" (like www.yoursite.com) works on both situations (yoursite.com or www.yoursite.com).
As others have posted, you must be accessing your site at the same URL that facebook expects. For example if facebook has a callback "example.com" but you're browser has "www.example.com", that can cause this problem.
In addition, if third-party cookies are not allowed by your browser, you may also see this problem. Or you may see the callback erroneously reporting the user is not connected.
Just posting a situation I had were calling FB.getLoginStatus got absolutely no response.
My application is designed to run in a tab, and I only entered the Page Tab URLs on the app admin page, and not the App On Facebook (i.e. Canvas) URLs. The tab loads perfectly, but any calls to the FB JS SDK provoke no response.
In Facebook App Settings, go to Client OAuth Settings, look at Valid OAuth redirect URIs
Make sure you have listed all URIs which are the domains from which Facebook SDK is being invoked. For example:
I develop at localhost:5000 and deploy to Heroku. Notice the format: http://domain.name/