Search in sources :

Example 6 with GwtRpcProxyException

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);
    }
}
Also used : SerializationException(com.google.gwt.user.client.rpc.SerializationException) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) Method(java.lang.reflect.Method) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 7 with GwtRpcProxyException

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);
    }
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) BeansException(org.springframework.beans.BeansException) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 8 with GwtRpcProxyException

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));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IOException(java.io.IOException) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

Example 9 with GwtRpcProxyException

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

Example 10 with GwtRpcProxyException

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));
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

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