How do I add a type to GWT's Serialization Policy whitelist?

后端 未结 9 586
离开以前
离开以前 2020-11-30 01:30

GWT\'s serializer has limited java.io.Serializable support, but for security reasons there is a whitelist of types it supports. The documentation I\'ve found,

9条回答
  •  北海茫月
    2020-11-30 01:36

    To anyone who will have the same question and doesn't find previous answers satisfactory...

    I'm using GWT with GWTController, since I'm using Spring, which I modified as described in this message. The message explains how to modify GrailsRemoteServiceServlet, but GWTController calls RPC.decodeRequest() and RPC.encodeResponseForSuccess() in the same way.

    This is the final version of GWTController I'm using:

    /**
     * Used to instantiate GWT server in Spring context.
     *
     * Original version from this tutorial.
     * 
     * ...fixed to work as explained in this tutorial.
     * 
     * ...and then fixed to use StandardSerializationPolicy as explained in
     * this message to allow
     * using Serializable instead of IsSerializable in model.
     */
    public class GWTController extends RemoteServiceServlet implements Controller, ServletContextAware {
    
     // Instance fields
    
     private RemoteService remoteService;
    
     private Class remoteServiceClass;
    
     private ServletContext servletContext;
    
     // Public methods
    
     /**
      * Call GWT's RemoteService doPost() method and return null.
      * 
      * @param request
      *            The current HTTP request
      * @param response
      *            The current HTTP response
      * @return A ModelAndView to render, or null if handled directly
      * @throws Exception
      *             In case of errors
      */
     public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
      doPost(request, response);
      return null; // response handled by GWT RPC over XmlHttpRequest
     }
    
     /**
      * Process the RPC request encoded into the payload string and return a string that encodes either the method return
      * or an exception thrown by it.
      * 
      * @param payload
      *            The RPC payload
      */
     public String processCall(String payload) throws SerializationException {
      try {
       RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass, this);
    
       // delegate work to the spring injected service
       return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy());
      } catch (IncompatibleRemoteServiceException e) {
       return RPC.encodeResponseForFailure(null, e);
      }
     }
    
     /**
      * Setter for Spring injection of the GWT RemoteService object.
      * 
      * @param RemoteService
      *            The GWT RemoteService implementation that will be delegated to by the {@code GWTController}.
      */
     public void setRemoteService(RemoteService remoteService) {
      this.remoteService = remoteService;
      this.remoteServiceClass = this.remoteService.getClass();
     }
    
     @Override
     public ServletContext getServletContext() {
      return servletContext;
     }
    
     public void setServletContext(ServletContext servletContext) {
      this.servletContext = servletContext;
     }
    }
    

提交回复
热议问题