Search in sources :

Example 1 with StandardSerializationPolicy

use of com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy in project pentaho-platform by pentaho.

the class AbstractGwtRpcProxyServlet method processCall.

@Override
public String processCall(String payload) throws SerializationException {
    Map<Class<?>, Boolean> whitelist = new HashMap<Class<?>, Boolean>();
    whitelist.put(GwtRpcProxyException.class, Boolean.TRUE);
    Map<Class<?>, String> obfuscatedTypeIds = new HashMap<Class<?>, String>();
    StandardSerializationPolicy policy = new StandardSerializationPolicy(whitelist, whitelist, obfuscatedTypeIds);
    String servletContextPath = getServletContextPath();
    Object target = null;
    try {
        target = resolveDispatchTarget(servletContextPath);
    } catch (GwtRpcProxyException ex) {
        logger.error(Messages.getInstance().getErrorString("AbstractGwtRpcProxyServlet.ERROR_0001_FAILED_TO_RESOLVE_DISPATCH_TARGET", servletContextPath), // $NON-NLS-1$
        ex);
        return RPC.encodeResponseForFailure(null, ex, policy);
    }
    final ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
    final ClassLoader altLoader = target.getClass().getClassLoader();
    try {
        // class specified in the request
        if (altLoader != origLoader) {
            Thread.currentThread().setContextClassLoader(altLoader);
        }
        RPCRequest rpcRequest = RPC.decodeRequest(payload, null, this);
        onAfterRequestDeserialized(rpcRequest);
        // don't require the server side to implement the service interface
        Method method = rpcRequest.getMethod();
        try {
            Method m = target.getClass().getMethod(method.getName(), method.getParameterTypes());
            if (m != null) {
                method = m;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RPC.invokeAndEncodeResponse(target, method, rpcRequest.getParameters(), rpcRequest.getSerializationPolicy());
    } catch (IncompatibleRemoteServiceException ex) {
        logger.error(Messages.getInstance().getErrorString("AbstractGwtRpcProxyServlet.ERROR_0003_RPC_INVOCATION_FAILED", target.getClass().getName()), // $NON-NLS-1$
        ex);
        return RPC.encodeResponseForFailure(null, ex);
    } finally {
        // reset the context classloader if necessary
        if ((altLoader != origLoader) && origLoader != null) {
            Thread.currentThread().setContextClassLoader(origLoader);
        }
    }
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) SerializationException(com.google.gwt.user.client.rpc.SerializationException) IncompatibleRemoteServiceException(com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) StandardSerializationPolicy(com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy) IncompatibleRemoteServiceException(com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException)

Aggregations

IncompatibleRemoteServiceException (com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException)1 SerializationException (com.google.gwt.user.client.rpc.SerializationException)1 RPCRequest (com.google.gwt.user.server.rpc.RPCRequest)1 StandardSerializationPolicy (com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1