Search in sources :

Example 1 with GwtRpcProxyException

use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testInvokeLogsAndThrowsIfServiceClassDoesNotHaveServiceInterfaceMethod.

@Test
public void testInvokeLogsAndThrowsIfServiceClassDoesNotHaveServiceInterfaceMethod() throws NoSuchMethodException {
    ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
    ClassLoader targetClassLoader = mock(ClassLoader.class);
    Method serviceSpecialMethod = ServiceInterface.class.getMethod("methodSpecial", String.class);
    Object[] rpcParameters = new Object[] { "id1" };
    SerializationPolicy policy = mock(SerializationPolicy.class);
    RPCRequest rpcRequest = new RPCRequest(serviceSpecialMethod, rpcParameters, policy, 0);
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
    doReturn(target).when(gwtRpcSpy).getTarget();
    doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
    try {
        gwtRpcSpy.invoke();
        fail();
    } catch (GwtRpcProxyException ex) {
        assertTrue(ex.getCause() instanceof NoSuchMethodException);
        verify(loggerMock).error(nullable(String.class), eq(ex.getCause()));
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) HttpServletRequest(javax.servlet.http.HttpServletRequest) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) Method(java.lang.reflect.Method) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Example 2 with GwtRpcProxyException

use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testGetTargetLogsAndRethrowsGwtRpcException.

@Test
public void testGetTargetLogsAndRethrowsGwtRpcException() {
    // Mocking the exception does not work with doThrow...
    // Spies require doThrow instead of thenThrow.
    // mock( GwtRpcProxyException.class );
    GwtRpcProxyException error = new GwtRpcProxyException();
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
    doThrow(error).when(gwtRpcSpy).resolveTarget();
    try {
        gwtRpcSpy.getTarget();
        fail();
    } catch (GwtRpcProxyException ex) {
        assertEquals(error, ex);
        verify(loggerMock).error(nullable(String.class), eq(ex));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Example 3 with GwtRpcProxyException

use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testGetRequestLogsAndWrapsThrownIllegalArgumentException.

@Test
public void testGetRequestLogsAndWrapsThrownIllegalArgumentException() {
    String requestPayload = "REQUEST_PAYLOAD";
    // new Object would have a null class loader!
    Object target = this;
    IllegalArgumentException error = new IllegalArgumentException();
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Example 4 with GwtRpcProxyException

use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testInvokeServiceClassLogsAndThrowsIfRPCThrowsSerializationException.

@Test
public void testInvokeServiceClassLogsAndThrowsIfRPCThrowsSerializationException() throws NoSuchMethodException {
    ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
    Method targetMethod = target.getClass().getMethod("method", String.class);
    ClassLoader targetClassLoader = mock(ClassLoader.class);
    Method serviceSpecialMethod = ServiceInterface.class.getMethod("method", String.class);
    Object[] rpcParameters = new Object[] { "id1" };
    SerializationPolicy policy = mock(SerializationPolicy.class);
    RPCRequest rpcRequest = new RPCRequest(serviceSpecialMethod, rpcParameters, policy, 0);
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
    doReturn(target).when(gwtRpcSpy).getTarget();
    doReturn(targetClassLoader).when(gwtRpcSpy).getTargetClassLoader();
    doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
    SerializationException error = new SerializationException();
    try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
        rpc.when(() -> RPC.invokeAndEncodeResponse(target, targetMethod, rpcParameters, policy)).thenThrow(error);
        try {
            gwtRpcSpy.invoke();
            fail();
        } catch (GwtRpcProxyException ex) {
            assertEquals(error, ex.getCause());
            verify(loggerMock).error(nullable(String.class), eq(error));
        }
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) SerializationException(com.google.gwt.user.client.rpc.SerializationException) RPC(com.google.gwt.user.server.rpc.RPC) Method(java.lang.reflect.Method) HttpServletRequest(javax.servlet.http.HttpServletRequest) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Example 5 with GwtRpcProxyException

use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.

the class PluginGwtRpc method resolveTarget.

@NonNull
@Override
protected Object resolveTarget() throws GwtRpcProxyException {
    IServiceManager serviceManager = PentahoSystem.get(IServiceManager.class, PentahoSessionHolder.getSession());
    String key = getServiceKey();
    if (serviceManager.getServiceConfig("gwt", key) == null) {
        throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcPluginProxyServlet.ERROR_0001_SERVICE_NOT_FOUND", key));
    }
    try {
        return serviceManager.getServiceBean("gwt", key);
    } catch (ServiceException e) {
        throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcPluginProxyServlet.ERROR_0002_FAILED_TO_GET_BEAN_REFERENCE", key), e);
    }
}
Also used : ServiceException(org.pentaho.platform.api.engine.ServiceException) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) IServiceManager(org.pentaho.platform.api.engine.IServiceManager) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

GwtRpcProxyException (org.pentaho.platform.web.servlet.GwtRpcProxyException)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 RPC (com.google.gwt.user.server.rpc.RPC)3 RPCRequest (com.google.gwt.user.server.rpc.RPCRequest)3 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 Method (java.lang.reflect.Method)3 SerializationException (com.google.gwt.user.client.rpc.SerializationException)2 RPCServletUtils (com.google.gwt.user.server.rpc.RPCServletUtils)2 SerializationPolicy (com.google.gwt.user.server.rpc.SerializationPolicy)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 IncompatibleRemoteServiceException (com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 IServiceManager (org.pentaho.platform.api.engine.IServiceManager)1 ServiceException (org.pentaho.platform.api.engine.ServiceException)1 BeansException (org.springframework.beans.BeansException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)1