You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by msalman <mo...@yahoo.com> on 2014/09/10 23:03:12 UTC

Handling page refresh or redirect when the server reboots

So we have this feature of online server upgrade in which the user can start
an upgrade on the server while still logged into the (wicket) web app.  This
starts some scripts in the bacground which bring the  jboss server down,
upgrade the db, upgrade the ear file, etc., and then restart the jboss
server.  When the server comes back up we would like the user to be
redirected to the login page of the app automatically.  The last part does
not work.  At this time we just have a message telling the user to refresh
the page and when everything is ready he will be sent to the login page.

Is there a good robust way to make sure that the page is automatically
refreshed and the login page is presented?  Is it even possible to do it? 
Personally I don't think this is not a good idea but this feature is a
requirement and I want to explore it as much as possible.


Appreciate any help.

Thanks.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Handling page refresh or redirect when the server reboots

Posted by msalman <mo...@yahoo.com>.
myproject.zip
<http://apache-wicket.1842946.n4.nabble.com/file/n4668210/myproject.zip>  


I finally got it working.  And just in case some one needs to do something
similar I am attaching the proof of concept project.  Any feedback would be
highly appreciated.  

Thanks to Sebastian and Martin for their inputs.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4668210.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Handling page refresh or redirect when the server reboots

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

HttpXmlRequest is asynchronous by default.
It is not finished by the time you return from your function.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Oct 21, 2014 at 8:37 AM, msalman <mo...@yahoo.com> wrote:

> Sebastian, thanks for your response and idea.
>
>
> Taking your idea  myproject.zip
> <http://apache-wicket.1842946.n4.nabble.com/file/n4667990/myproject.zip>
> I
> am trying to use the following javascript code in wicket:
>
>
>
> Http.Get = function(theUrl)
> {
>     var xmlHttp = null;
>         try
>         {
>                 xmlHttp = new XMLHttpRequest();
>                 return xmlHttp.open("GET", theUrl, true );
>                 xmlHttp.send();
>                 return xmlHttp.statusText;
>                 //return xmlHttp.responseText;
>         }
>         catch (error)
>         {
>                 return 'error in my code: ' + error;
>         }
> }
>
>
> The above code is called via:
>
>                 add(new AjaxLink("link")
>                 {
>
>
>                         @Override
>                         public void onClick(AjaxRequestTarget target)
>                         {
>                                 target.add(testLabel);
>                         }
>
>
>                         @Override
>                         protected IAjaxCallDecorator getAjaxCallDecorator()
>                         {
>                                 return new IAjaxCallDecorator()
>                                 {
>                                         private static final long
> serialVersionUID = 1L;
>
>                                         public CharSequence decorateScript(
>                                                 Component component,
>                                                 CharSequence script)
>                                         {
>                                                 return
> "document.getElementById('testlabel').innerHTML = 'plain '  +
> Http.Get('http://www.cnn.com') ;" + script;
>                                         }
>
>
>                                         public CharSequence
> decorateOnSuccessScript(
>                                                 Component component,
>                                                 CharSequence script)
>                                         {
>                                                 return
> "document.getElementById('testlabel').innerHTML = 'on success '
> + Http.Get('http://www.cnn.com') ;" + script;
>                                         }
>
>
>                                         public CharSequence
> decorateOnFailureScript(
>                                                 Component component,
>                                                 CharSequence script)
>                                         {
>                                                 return
> "document.getElementById('testlabel').innerHTML = 'on Failure '
> +  Http.Get('http://www.cnn.com') ;" + script;
>                                         }
>                                 };
>                         }
>
>                 });
>
>
> The problem is that when I use it in wicket the xmlHttp.statusText or
> xmlHttp.responseText returns nothing.
> Can any one please tell me what I might be doing wrong?
> Does the code or calling it even makes sense?
>
> I am attaching  quickstart project.  Please see:
> com.mytest.javascript.*
>
>
> Thanks.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4667990.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Handling page refresh or redirect when the server reboots

Posted by msalman <mo...@yahoo.com>.
Sebastian, thanks for your response and idea.


Taking your idea  myproject.zip
<http://apache-wicket.1842946.n4.nabble.com/file/n4667990/myproject.zip>  I
am trying to use the following javascript code in wicket: 



Http.Get = function(theUrl)
{
    var xmlHttp = null;
	try
	{
		xmlHttp = new XMLHttpRequest();
		return xmlHttp.open("GET", theUrl, true );
		xmlHttp.send();
		return xmlHttp.statusText;
		//return xmlHttp.responseText;
	}
	catch (error)
	{
		return 'error in my code: ' + error;
	}
}


The above code is called via:

		add(new AjaxLink("link")
		{


			@Override
			public void onClick(AjaxRequestTarget target) 
			{
				target.add(testLabel);				
			}
			
			
			@Override
			protected IAjaxCallDecorator getAjaxCallDecorator()
			{
				return new IAjaxCallDecorator()
				{
					private static final long serialVersionUID = 1L;

					public CharSequence decorateScript(
						Component component,
						CharSequence script) 
					{
						return "document.getElementById('testlabel').innerHTML = 'plain '  +
Http.Get('http://www.cnn.com') ;" + script;
					}

					
					public CharSequence decorateOnSuccessScript(
						Component component, 
						CharSequence script) 
					{
						return "document.getElementById('testlabel').innerHTML = 'on success '
+ Http.Get('http://www.cnn.com') ;" + script;
					}

					
					public CharSequence decorateOnFailureScript(
						Component component, 
						CharSequence script) 
					{
						return "document.getElementById('testlabel').innerHTML = 'on Failure '
+  Http.Get('http://www.cnn.com') ;" + script;
					}
				};
			}
			
		});


The problem is that when I use it in wicket the xmlHttp.statusText or
xmlHttp.responseText returns nothing.  
Can any one please tell me what I might be doing wrong? 
Does the code or calling it even makes sense?

I am attaching  quickstart project.  Please see:
com.mytest.javascript.*


Thanks.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4667990.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Handling page refresh or redirect when the server reboots

Posted by Sébastien Gautrin <sg...@telemetris.com>.
I don't have a "wicket-way" for this. However, if I had to do something like that, I'd try the following simple and extremely basic approach (which would need to be refined to be more than just an ugly hack)

 1. after the action triggering the upgrade process, trigger a javascript on the client side
 2. this javascript would poll a given url (e.g. current page or application home or a specific bookmarkmable page, the latter being probably better)
     1. as long as the polled url does not return (within a short timeout) or returns an error code (depending on your setup: if the app is behind a proxy, you'd expect a 502/503 error as long as the app is not up)
     2. once the poll returns a non-error, the javascript would trigger the redirect (it could also probably trigger a modal login form on the current page instead)

Note that I myself feel this approach would be very hacky and is most likely not the best way to do it with wicket, but this should at least work for your purpose, and maybe give you an idea on how to do it better.

On 10/09/14 23:03, msalman wrote:
> So we have this feature of online server upgrade in which the user can start
> an upgrade on the server while still logged into the (wicket) web app.  This
> starts some scripts in the bacground which bring the  jboss server down,
> upgrade the db, upgrade the ear file, etc., and then restart the jboss
> server.  When the server comes back up we would like the user to be
> redirected to the login page of the app automatically.  The last part does
> not work.  At this time we just have a message telling the user to refresh
> the page and when everything is ready he will be sent to the login page.
>
> Is there a good robust way to make sure that the page is automatically
> refreshed and the login page is presented?  Is it even possible to do it?
> Personally I don't think this is not a good idea but this feature is a
> requirement and I want to explore it as much as possible.
>
>
> Appreciate any help.
>
> Thanks.
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>