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);
}
}
}
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));
}
}
}
Aggregations