Class AbstractGwtRpc

  • Direct Known Subclasses:
    PluginGwtRpc, SystemGwtRpc

    public abstract class AbstractGwtRpc
    extends Object
    The AbstractGwtRpc class is the base abstract class of classes that represent a GWT Remote Procedure Call which is made via HTTP.

    One instance of this class is initialized with the HttpServletRequest instance which represents a GWT-RPC request.

    The class exposes functionality to:

    1. obtain the target object of the GWT-RPC request, via getTarget();
    2. obtain the class loader which should be current when the call is performed, via getTargetClassLoader();
    3. obtain the serialized request payload from the HTTP request, via getRequestPayload(); this is useful for low-level integration with RemoteServiceServlet;
    4. obtain the parsed request, via getRequest();
    5. invoke the target method on the target object within its class loader and to return a serialized response.

    Concrete specialized classes exist that can handle GWT-RPC requests for services of:

    • PluginGwtRpc - services of Pentaho Platform plugins, e.g. /gwtrpc/serviceName;
    • SystemGwtRpc - services of the Pentaho Platform itself, e.g. /ws/gwt/serviceName.
    • Field Detail

      • HTTP_GWT_RPC_ATTRIBUTE

        protected static final String HTTP_GWT_RPC_ATTRIBUTE
    • Constructor Detail

      • AbstractGwtRpc

        protected AbstractGwtRpc​(@NonNull
                                 javax.servlet.http.HttpServletRequest httpRequest)
        Creates an instance given an HTTP request.
        Parameters:
        httpRequest - An HTTP request.
    • Method Detail

      • setSerializationPolicyCache

        public void setSerializationPolicyCache​(@Nullable
                                                IGwtRpcSerializationPolicyCache serializationPolicyCache)
        Sets the serialization policy cache which will be used to load a serialization policy before creating one, or to store the created one if none exists.

        The serialization policy is used to safely deserialize the GWT-RPC request and serialize the GWT-RPC response of this call.

        Parameters:
        serializationPolicyCache - A serialization policy cache instance, or null.
      • getSerializationPolicyCache

        @Nullable
        public IGwtRpcSerializationPolicyCache getSerializationPolicyCache()
        Gets the serialization policy cache instance used by this GWT-RPC call.
        Returns:
        The serialization policy cache instance, if any; null, otherwise.
      • getServletRequest

        @NonNull
        public javax.servlet.http.HttpServletRequest getServletRequest()
        Gets the associated HTTP request.
        Returns:
        An HTTP request.
      • getServletContext

        @NonNull
        protected javax.servlet.ServletContext getServletContext()
        Gets the associated servlet context.

        Syntax-sugar method equivalent to getServletRequest().getServletContext().

        Returns:
        A servlet context.
      • getAppContextPath

        @NonNull
        protected String getAppContextPath()
        Gets the associated web app context path.

        Syntax-sugar method equivalent to getServletRequest().getContextPath().

        Example value: /pentaho.

        Returns:
        The servlet context path.
      • getServletContextPath

        @NonNull
        protected String getServletContextPath()
        Gets the associated servlet context path.

        Example value: /gwt/rpc/serviceName?bar=foo.

        Returns:
        The servlet context path.
      • getTarget

        @NonNull
        public Object getTarget()
        Gets the target object on which the remote call will be made.
        Returns:
        The target object.
        Throws:
        GwtRpcProxyException - if the target object cannot be resolved.
      • getTargetClassLoader

        @NonNull
        public ClassLoader getTargetClassLoader()
        Gets the class loader which must be current to deserialize the request, invoke the method and serialize the response.
        Returns:
        The target class laoder.
        Throws:
        GwtRpcProxyException - if the target class loader cannot be resolved.
      • resolveTarget

        @NonNull
        protected abstract Object resolveTarget()
        Resolves the target object on which the remote call will be made.
        Returns:
        The target object.
        Throws:
        GwtRpcProxyException - if the target object cannot be resolved.
      • getRequestPayload

        @NonNull
        public String getRequestPayload()
                                 throws GwtRpcProxyException
        Gets the serialized request payload which is present in the HTTP request.
        Returns:
        The serialized request payload.
        Throws:
        GwtRpcProxyException - if the request is not valid.
        See Also:
        RPCServletUtils.readContentAsGwtRpc(HttpServletRequest)
      • getRequest

        @NonNull
        public com.google.gwt.user.server.rpc.RPCRequest getRequest()
        Gets the processed GWT-RPC request object.
        Returns:
        The processed request.
        Throws:
        GwtRpcProxyException - if the request is invalid.
        See Also:
        RPC.decodeRequest(String, Class, com.google.gwt.user.server.rpc.SerializationPolicyProvider)
      • getSerializationPolicy

        @NonNull
        protected com.google.gwt.user.server.rpc.SerializationPolicy getSerializationPolicy​(@Nullable
                                                                                            String moduleBaseURL,
                                                                                            @Nullable
                                                                                            String strongName)
      • loadSerializationPolicy

        @Nullable
        protected abstract com.google.gwt.user.server.rpc.SerializationPolicy loadSerializationPolicy​(@NonNull
                                                                                                      String moduleContextPath,
                                                                                                      @Nullable
                                                                                                      String strongName)
        Loads the serialization policy having the given GWT module context path and strong name.

        Typically, this method loads a serialization policy from a persistence medium.

        Parameters:
        moduleContextPath - The GWT module context path (e.g. /content/data-access/resources/gwt/).
        strongName - The serialization policy strong name.
        Returns:
        The associated serialization policy, if one can be loaded; null, otherwise, in which case the default serialization policy is assumed, as returned by getDefaultSerializationPolicy().
      • getDefaultSerializationPolicy

        @NonNull
        protected static com.google.gwt.user.server.rpc.SerializationPolicy getDefaultSerializationPolicy()
        Gets a serialization policy to use when no specific serialization policy is available.

        the default serialization policy is a legacy, 1.3.3 compatible, serialization policy and may result in SerializationException.

        Returns:
        The default serialization policy.
        See Also:
        RPC.getDefaultSerializationPolicy()
      • loadSerializationPolicyFromInputStream

        @Nullable
        protected static com.google.gwt.user.server.rpc.SerializationPolicy loadSerializationPolicyFromInputStream​(@NonNull
                                                                                                                   ThrowingSupplier<InputStream,​IOException> inputStreamSupplier,
                                                                                                                   @NonNull
                                                                                                                   String serializationPolicyFileName)
        Loads a serialization policy given an input stream whose content is in GWT-RPC serialization policy standard format.

        Helper method for custom implementations.

        Parameters:
        inputStreamSupplier - A supplier of an input stream of the serialization policy.
        serializationPolicyFileName - The serialization policy file name; used for logging purposes, only.
        Returns:
        The loaded serialization policy, if successfully loaded; null, otherwise.
      • invoke

        @NonNull
        public String invoke()
        Makes the remote call on the target object and returns the serialized response.
        Returns:
        The serialized response.
        Throws:
        GwtRpcProxyException - if the call does not succeed.
      • getInstance

        @NonNull
        protected static <R extends AbstractGwtRpc> R getInstance​(@NonNull
                                                                  javax.servlet.http.HttpServletRequest httpRequest,
                                                                  @NonNull
                                                                  Function<javax.servlet.http.HttpServletRequest,​R> factory,
                                                                  @Nullable
                                                                  IGwtRpcSerializationPolicyCache serializationPolicyCache)
        Gets the instance of a sub-class of AbstractGwtRpc, R, which is stored in the given HTTP request, if there is one already, or creates one and stores it if not.

        The GWT-RPC instance is stored in an HTTP request attribute, as per ServletRequest.getAttribute(String) and ServletRequest.setAttribute(String, Object).

        Helper method for custom implementations.

        Parameters:
        httpRequest - The HTTP request.
        factory - A function which creates an instance of class R given an HTTP request.
        serializationPolicyCache - A serialization policy cache instance to initialize a created instance with.
        Returns:
        The associated GWT-RPC instance.
        See Also:
        setSerializationPolicyCache(IGwtRpcSerializationPolicyCache)