0

Web service + Server push

asked 2011-03-22 05:26:23 +0800

vinhvo gravatar image vinhvo
369 3

Hi,

I am having a web application and a web service to update data in database. Can I use the webservice to do a server push to all web clients to refresh the UI?

I am aware that we can use the timer in web application to check changes from database and update the UI. However, this seems not to be the right way to do it. Can the web service somehow broadcast an event to the web application to do a server push rather than the web application has to always make query to check changes from DB.

Thank you for your supporting.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2011-03-22 06:46:41 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

If we guess that the web application (frontend) is separated from the webservice (backend) than i think no one will have frontend libs in the backend project. Only my 10 cent.

link publish delete flag offensive edit

answered 2011-03-22 09:05:20 +0800

vinhvo gravatar image vinhvo
369 3

Yes, you are right. However, I probably found a way around. I create this zul file

<?page title="Refresh" contentType="text/html;charset=UTF-8"?>
<zk>
<window   >
<zscript>
	import fi.uwasa.netmes.zkossController.*;
	String lineId=Executions.getCurrent().getParameter("lineId");
	EventQueue que = EventQueues.lookup(WorkQueueController.REFRESH_EVENT_HOST_NAME, EventQueues.APPLICATION, true);
	que.publish(new Event(WorkQueueController.REFRESH_EVENT_NAME, null,lineId));
</zscript>

</window>
</zk>

Then in the webservices I only need to invoke the zul file and it will publish event to refresh browser. However, I am stuck at invoking the zul file. Can you provide some more help.
Thank you.

link publish delete flag offensive edit

answered 2011-03-22 09:09:24 +0800

vinhvo gravatar image vinhvo
369 3

@Resource
	private WebServiceContext context;
	
	private void doServerPush(String lineId) throws IOException{
		ServletContext servletContext =
		    (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
		URL url = servletContext.getResource("/public/refresh.zul");
		URLConnection conn=url.openConnection();
		conn.connect();
		
	}

This code does not work, the zscript does not excecute

link publish delete flag offensive edit

answered 2011-03-22 10:31:14 +0800

vinhvo gravatar image vinhvo
369 3

This will work:

	@Resource
	private WebServiceContext context;
	
	private void doServerPush(String lineId) throws IOException{
		HttpServletRequest  request =
		    (HttpServletRequest ) context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
		String uri=request.getScheme()+"://"+request.getLocalAddr()+":"+request.getLocalPort()+request.getContextPath()+REFRESH_PAGE+"?lineId="+lineId;
		System.out.println(uri);
		HttpClient httpclient = new DefaultHttpClient();
		HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpclient.execute(httpget);

	}

Thank you very much.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-22 05:26:23 +0800

Seen: 368 times

Last updated: Mar 22 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More