Search in sources :

Example 1 with IncompatibleRemoteServiceException

use of com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException 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)

Example 2 with IncompatibleRemoteServiceException

use of com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testGetRequestLogsAndWrapsThrownIncompatibleRemoteServiceException.

@Test
public void testGetRequestLogsAndWrapsThrownIncompatibleRemoteServiceException() {
    String requestPayload = "REQUEST_PAYLOAD";
    // new Object would have a null class loader!
    Object target = this;
    IncompatibleRemoteServiceException error = new IncompatibleRemoteServiceException();
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
    doReturn(requestPayload).when(gwtRpcSpy).getRequestPayload();
    doReturn(target).when(gwtRpcSpy).resolveTarget();
    try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
        rpc.when(() -> RPC.decodeRequest(eq(requestPayload), eq(null), any())).thenThrow(error);
        try {
            gwtRpcSpy.getRequest();
            fail();
        } catch (GwtRpcProxyException ex) {
            assertEquals(error, ex.getCause());
            verify(loggerMock).error(nullable(String.class), eq(error));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RPC(com.google.gwt.user.server.rpc.RPC) IncompatibleRemoteServiceException(com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Aggregations

IncompatibleRemoteServiceException (com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException)2 SerializationException (com.google.gwt.user.client.rpc.SerializationException)1 RPC (com.google.gwt.user.server.rpc.RPC)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 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 GwtRpcProxyException (org.pentaho.platform.web.servlet.GwtRpcProxyException)1