use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class AbstractGwtRpc method invoke.
// endregion
// region Invocation
/**
* Makes the remote call on the target object and returns the serialized response.
*
* @return The serialized response.
* @throws GwtRpcProxyException if the call does not succeed.
*/
@NonNull
public String invoke() {
Object target = getTarget();
Class<?> targetClass = target.getClass();
RPCRequest rpcRequest = getRequest();
try {
Method targetMethod = getTargetMethod(targetClass, rpcRequest);
return GwtRpcUtil.withClassLoaderThrowing(// Making it this way, effectively repeating getTarget(), makes it easier to test.
getTargetClassLoader(), () -> invokeCore(target, targetMethod, rpcRequest));
} catch (NoSuchMethodException | SerializationException ex) {
String message = Messages.getInstance().getErrorString("AbstractGwtRpcProxyServlet.ERROR_0003_RPC_INVOCATION_FAILED", targetClass.getName());
logger.error(message, ex);
throw new GwtRpcProxyException(message, ex);
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class SystemGwtRpc method resolveTarget.
@NonNull
@Override
protected Object resolveTarget() throws GwtRpcProxyException {
ApplicationContext beanFactory = createAppContext();
String beanId = getTargetBeanId();
if (!beanFactory.containsBean(beanId)) {
throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcProxyServlet.ERROR_0001_NO_BEAN_FOUND_FOR_SERVICE", beanId, getServletContextPath()));
}
try {
return beanFactory.getBean(beanId);
} catch (BeansException ex) {
throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcProxyServlet.ERROR_0002_FAILED_TO_GET_BEAN_REFERENCE", beanId), ex);
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetRequestPayloadLogsAndWrapsThrownIOException.
@Test
public void testGetRequestPayloadLogsAndWrapsThrownIOException() {
IOException error = mock(IOException.class);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenThrow(error);
try {
gwtRpc.getRequestPayload();
fail();
} catch (GwtRpcProxyException ex) {
assertEquals(error, ex.getCause());
verify(loggerMock).error(nullable(String.class), eq(error));
}
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException 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));
}
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetRequestPayloadLogsAndWrapsThrownServletException.
@Test
public void testGetRequestPayloadLogsAndWrapsThrownServletException() {
ServletException error = mock(ServletException.class);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenThrow(error);
try {
gwtRpc.getRequestPayload();
fail();
} catch (GwtRpcProxyException ex) {
assertEquals(error, ex.getCause());
verify(loggerMock).error(nullable(String.class), eq(error));
}
}
}
Aggregations