Tuesday, August 11, 2009

Passing Parameters in GWT RPC (Server-side)

Continued from Passing Parameters in GWT RPC (Client-side)


The server-side code
The server-side servlet must extend RemoteServiceServlet, remember?
However, to allow a JSP to be the servlet servicing the RPC request, the JSP must implement the HttpJspPage interface. JspServiceBeanable, which does that, is an abstract class (provided by the courtesy of this author) to be extended by a JSP.

package org.synthful.gwt.http.servlet.server;
...
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

abstract public class JspServiceBeanable
extends RemoteServiceServlet
implements HttpJspPage
{
 ....



protected String doJspService( HashMap<String, String> parameters) { this.parameters = new Hashtable<String, String>(parameters); JspFactory.setDefaultFactory(new JspFactoryShunt()); this.jspFactory = JspFactory.getDefaultFactory(); try{ this._jspService( this.getThreadLocalRequest(), this.getThreadLocalResponse()); } catch (Exception e){ e.printStackTrace(); } this.jspContext.popBody(); return this.jspOut.Body.toString(); }
.... }


But, wait another minute. Shouldn't it also implement HashedParameterService in order to recognise the HashMap datatype being passed by the RPC requester?

Wokay dokay, here's JspServiceParametricBeanable, the abstract class to be extended by any JSP with ambitions to service an RPC request that comes with a HashMap argument. It over-rides the empty doServiceResponse method in GWT-supplied RemoteServiceServlet so that instead of ignoring the response output, it diverts RemoteServiceServlet to perform doJspService mandated by HttpJspPage interface.

package org.synthful.gwt.http.servlet.server;
import java.util.HashMap;
abstract public class JspServiceParametricBeanable
extends JspServiceBeanable
{
 public String doServiceResponse(
  HashMap<String, String> parameters){
  return this.doJspService(parameters);
 }
}


Oopsie doops, wait one more final minute. Shouldn't the JSP implement TableMgrService which the application-specific client-side in the previous page has required to define the target URL? So here's the actual abstract class to be implemented by the RPC service JSP.
package com.blessedgeek.gwt.gdata.server;
import
org.synthful.gwt.http.servlet.server.
JspServiceParametricBeanable;
import com.blessedgeek.gwt.gdata.client.TableMgrService;

abstract public class TableMgrServiceImplJspBeanable
 extends JspServiceParametricBeanable
 implements TableMgrService{}



So here's the header for TableActionService.gwtrpt.jsp as targeted by TableMgrService interface. Notice that it extends TableMgrServiceImplJspBeanable.


<%@ page
language="java"
extends="com.blessedgeek.gwt.gdata.server.
TableMgrServiceImplJspBeanable"

import="
com.blessedgeek.gwt.gdata.client.TableMgr,
com.blessedgeek.gwt.gdata.server.MrBean,
....
com.google.gdata.data.spreadsheet.Column,
com.google.gdata.data.spreadsheet.Field"%>


When using JspServiceBeanable as the means to allow JSPs to be used as GWT RPC service responders, the servicing JSP name must end with ".gwtrpc.jsp". JspServiceBeanable detects that a JSP is a GWT RPC service responder by detecting if its name ends of ".gwtrpc.jsp".


Continue next GWT RPC - How Server-side JSP Service Works

1 comment:

  1. The best house cleaning company in Khobar
    Home cleaning company in Fujairah is one of the best companies that provide services to its customers in terms of modern equipment and advanced labor and detergents that are imported from abroad free of chemicalsشركة النجوم لخدمات التنظيف
    شركة تنظيف فلل بجدة
    شركة تنظيف بيوت بجدة
    شركة تنظيف شقق بجدة

    ReplyDelete