Example usage for com.google.gwt.user.server.rpc RPC invokeAndEncodeResponse

List of usage examples for com.google.gwt.user.server.rpc RPC invokeAndEncodeResponse

Introduction

In this page you can find the example usage for com.google.gwt.user.server.rpc RPC invokeAndEncodeResponse.

Prototype

public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
            SerializationPolicy serializationPolicy, int flags) throws SerializationException 

Source Link

Usage

From source file:com.brightedu.server.BrightServlet.java

License:Apache License

/**
 * Process a call originating from the given request. Uses the
 * {@link RPC#invokeAndEncodeResponse(Object, java.lang.reflect.Method, Object[])}
 * method to do the actual work./*from   w  ww  . j av  a  2s  .c o m*/
 * <p>
 * Subclasses may optionally override this method to handle the payload in
 * any way they desire (by routing the request to a framework component, for
 * instance). The {@link HttpServletRequest} and {@link HttpServletResponse}
 * can be accessed via the {@link #getThreadLocalRequest()} and
 * {@link #getThreadLocalResponse()} methods.
 * </p>
 * This is public so that it can be unit tested easily without HTTP.
 * 
 * @param payload
 *            the UTF-8 request payload
 * @return a string which encodes either the method's return, a checked
 *         exception thrown by the method, or an
 *         {@link IncompatibleRemoteServiceException}
 * @throws SerializationException
 *             if we cannot serialize the response
 * @throws UnexpectedException
 *             if the invocation throws a checked exception that is not
 *             declared in the service method's signature
 * @throws RuntimeException
 *             if the service method throws an unchecked exception (the
 *             exception will be the one thrown by the service)
 */
public String processCall(String payload) throws SerializationException {
    // First, check for possible XSRF situation
    checkPermutationStrongName();

    try {
        RPCRequest rpcRequest = RPC.decodeRequest(payload, delegate.getClass(), this);
        onAfterRequestDeserialized(rpcRequest);
        return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(), rpcRequest.getParameters(),
                rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
        log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
        return RPC.encodeResponseForFailure(null, ex);
    } catch (RpcTokenException tokenException) {
        log("An RpcTokenException was thrown while processing this call.", tokenException);
        return RPC.encodeResponseForFailure(null, tokenException);
    }
}

From source file:com.openforevent.gwt.gwtrpc.server.GwtRpcServiceImpl.java

License:Apache License

public String processCall(String payload) throws SerializationException {
    try {// w w w.j a v  a 2 s.com
        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
        onAfterRequestDeserialized(rpcRequest);
        return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(),
                rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
        log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
        return RPC.encodeResponseForFailure(null, ex);
    }
}

From source file:com.openforevent.gwt.gwtrpc.util.GwtRpcServletUtil.java

License:Apache License

public String invokeServlet(HttpServletRequest request, HttpServletResponse response, String requestPayload)
        throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException,
        ClassNotFoundException, SerializationException, IOException {

    RemoteService target = getRemoteServiceTarget("com.openforevent.gwt.gwtrpc.server.GwtRpcServiceImpl",
            request, response);//from w w w  . j a v  a 2s. com
    RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, target.getClass(), serializationPolicyProvider);

    String responsePayload = RPC.invokeAndEncodeResponse(target, rpcRequest.getMethod(),
            rpcRequest.getParameters(), serializationPolicy, rpcRequest.getFlags());
    return responsePayload;
}

From source file:fr.putnami.pwt.core.service.server.service.AbstractCommandService.java

License:Open Source License

@Override
protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    try {/*from ww  w  .  j a v  a2 s . c  om*/
        String requestPayload = this.readContent(request);
        RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, getClass(), this);

        String responsePayload = RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(),
                rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());

        boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request)
                && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload);

        RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode);
    } catch (Exception e) {
        logger.error("Request processing failed", e);
        throw Throwables.propagate(e);
    }
}

From source file:fr.putnami.pwt.core.service.server.service.BasicCommandService.java

License:Open Source License

@Override
protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    try {//from   www.  j a  v  a 2s .  c o  m
        String requestPayload = this.readContent(request);
        RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, this.getClass(), this);

        String responsePayload = RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(),
                rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());

        boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request)
                && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload);

        RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode);
    } catch (Exception e) {
        this.logger.error("Request processing failed", e);
        throw Throwables.propagate(e);
    }
}

From source file:fr.putnami.pwt.plugin.spring.rpc.server.controller.CommandController.java

License:Open Source License

@RequestMapping(value = "/commandService", method = RequestMethod.POST)
public void processPostRpc(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    try {/*from   w  ww  .j  a  v a2s.co  m*/
        String requestPayload = RPCServletUtils.readContentAsGwtRpc(request);
        RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, CommandService.class, this);

        String responsePayload = RPC.invokeAndEncodeResponse(commandService, rpcRequest.getMethod(),
                rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());

        boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request)
                && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload);

        RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode);
    } catch (Exception e) {
        this.logger.error("Request processing failed", e);
        throw Throwables.propagate(e);
    }
}

From source file:org.appverse.web.framework.backend.frontfacade.gxt.controllers.GwtRpcController.java

License:Appverse Public License

@Override
public String processCall(final String payload) throws SerializationException {
    try {//  w  w w . jav  a 2  s. co m
        Object presentationService = applicationContext.getBean(serviceName.get());
        if (!(presentationService instanceof RemoteService)) {
            throw new IllegalArgumentException(
                    "Requested Spring Bean is not a GWT RemoteService Presentation Service: " + payload + " ("
                            + presentationService + ")");
        }

        RPCRequest rpcRequest = RPC.decodeRequest(payload, presentationService.getClass(), this);
        if (presentationService instanceof AuthenticationServiceFacade && rpcRequest.getMethod()
                .equals(AuthenticationServiceFacade.class.getMethod("getXSRFSessionToken"))) {
            return RPC.encodeResponseForSuccess(rpcRequest.getMethod(),
                    SecurityHelper.createXSRFToken(getThreadLocalRequest()));
        }
        return RPC.invokeAndEncodeResponse(presentationService, rpcRequest.getMethod(),
                rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (Exception e) {
        GWTPresentationException pex = new GWTPresentationException(e.getMessage());
        return RPC.encodeResponseForFailure(null, pex);
    }
}

From source file:org.atmosphere.gwt.poll.AtmospherePollService.java

License:Apache License

/**
 * Process a call originating from the given request. Uses the
 * {@link RPC#invokeAndEncodeResponse(Object, java.lang.reflect.Method, Object[])}
 * method to do the actual work./*from w  w  w. j a v a 2 s  .c om*/
 * <p>
 * Subclasses may optionally override this method to handle the payload in any
 * way they desire (by routing the request to a framework component, for
 * instance). The {@link HttpServletRequest} and {@link HttpServletResponse}
 * can be accessed via the {@link #getThreadLocalRequest()} and
 * {@link #getThreadLocalResponse()} methods.
 * </p>
 * This is public so that it can be unit tested easily without HTTP.
 *
 * @param payload the UTF-8 request payload
 * @return a string which encodes either the method's return, a checked
 *         exception thrown by the method, or an
 *         {@link IncompatibleRemoteServiceException}
 * @throws SerializationException if we cannot serialize the response
 * @throws UnexpectedException if the invocation throws a checked exception
 *           that is not declared in the service method's signature
 * @throws RuntimeException if the service method throws an unchecked
 *           exception (the exception will be the one thrown by the service)
 */
public String processCall(String payload) throws SerializationException {
    try {
        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
        onAfterRequestDeserialized(rpcRequest);
        return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(),
                rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
        log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
        return RPC.encodeResponseForFailure(null, ex);
    }
}

From source file:org.javalite.activeweb.GWTAppController.java

License:Apache License

/**
 * Process a call originating from the given request. Uses the
 * {@link RPC#invokeAndEncodeResponse(Object, java.lang.reflect.Method, Object[])}
 * method to do the actual work./*  ww w . j  a v a2s . co  m*/
 * <p>
 * Subclasses may optionally override this method to handle the payload in any
 * way they desire (by routing the request to a framework component, for
 * instance). The {@link HttpServletRequest} and {@link HttpServletResponse}
 * can be accessed via the {@link #getThreadLocalRequest()} and
 * {@link #getThreadLocalResponse()} methods.
 * </p>
 * This is public so that it can be unit tested easily without HTTP.
 *
 * @param payload the UTF-8 request payload
 * @return a string which encodes either the method's return, a checked
 *         exception thrown by the method, or an
 *         {@link IncompatibleRemoteServiceException}
 * @throws SerializationException if we cannot serialize the response
 * @throws UnexpectedException if the invocation throws a checked exception
 *           that is not declared in the service method's signature
 * @throws RuntimeException if the service method throws an unchecked
 *           exception (the exception will be the one thrown by the service)
 */
private String processCall(String payload) throws SerializationException {
    // First, check for possible XSRF situation
    checkPermutationStrongName();

    try {
        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
        return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(),
                rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
        logError("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
        return RPC.encodeResponseForFailure(null, ex);
    } catch (RpcTokenException tokenException) {
        logError("An RpcTokenException was thrown while processing this call.", tokenException);
        return RPC.encodeResponseForFailure(null, tokenException);
    }
}

From source file:org.talend.mdm.webapp.general.gwt.ProxyGWTServiceImpl.java

License:Open Source License

@Override
protected String doProcessCall(String payload) throws SerializationException {
    try {/*  ww w .jav a  2  s.  c o m*/
        String serviceIntfName = getServiceIntfName(payload);
        Object action = getAction(serviceIntfName);
        if (action == null) {
            throw new IncompatibleRemoteServiceException(
                    serviceIntfName + " undefined in actions.properties\nPlease check"); //$NON-NLS-1$
        }

        RPCRequest rpcRequest = RPC.decodeRequest(payload, action.getClass(), this);
        onAfterRequestDeserialized(rpcRequest);
        return RPC.invokeAndEncodeResponse(action, rpcRequest.getMethod(), rpcRequest.getParameters(),
                rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
        log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); //$NON-NLS-1$
        return RPC.encodeResponseForFailure(null, ex);
    }
}