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)
        throws SerializationException 

Source Link

Document

Returns a string that encodes the result of calling a service method, which could be the value returned by the method or an exception thrown by it.

Usage

From source file:cc.kune.core.server.rack.filters.gwts.DelegatedRemoteServlet.java

License:GNU Affero Public License

@Override
public String processCall(final String payload) throws SerializationException, DefaultException {
    try {/*  www  .  j  av a  2 s.c om*/
        final RPCRequest rpcRequest = RPC.decodeRequest(payload, service.getClass());
        return RPC.invokeAndEncodeResponse(service, rpcRequest.getMethod(), rpcRequest.getParameters());
    } catch (final IncompatibleRemoteServiceException ex) {
        return RPC.encodeResponseForFailure(null, ex);
    }
}

From source file:com.google.gwt.examples.rpc.server.CanonicalExample.java

License:Apache License

/**
 * Process the RPC request encoded into the payload string and return a string
 * that encodes either the method return or an exception thrown by it.
 *//*from ww w  .  j a va2  s .c o  m*/
@Override
public String processCall(String payload) throws SerializationException {
    try {
        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass());
        return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters());
    } catch (IncompatibleRemoteServiceException ex) {
        return RPC.encodeResponseForFailure(null, ex);
    }
}

From source file:net.urlgrey.mythpodcaster.servlet.GWTController.java

License:Open Source License

public String processCall(String payload) throws SerializationException {
    try {/*from w ww .  j  av  a2s. c om*/

        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass);

        return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(),
                rpcRequest.getParameters());
    } catch (IncompatibleRemoteServiceException ex) {
        LOGGER.warn("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
        return RPC.encodeResponseForFailure(null, ex);
    }
}

From source file:org.ajax4jsf.gwt.jsf.GwtListenerMethodHelper.java

License:Open Source License

public String processRequest(RPCRequest request) {
    // Invoke the call on this helper itself!
    try {//from  w  w w.  j a  v a2s  .c  om
        return RPC.invokeAndEncodeResponse(this, request.getMethod(), request.getParameters());
    } catch (SerializationException e) {
        throw new RuntimeException("Could not deserialize request", e);
    }
}

From source file:org.ajax4jsf.gwt.jsf.GwtListenerServiceHelper.java

License:Open Source License

public String processRequest(RPCRequest request) {
    ELContext context = FacesContext.getCurrentInstance().getELContext();
    Object serviceBean = getServiceBean(context);
    try {/*from w ww .  ja  v  a 2s  . c  o  m*/
        return RPC.invokeAndEncodeResponse(serviceBean, request.getMethod(), request.getParameters());
    } catch (SerializationException e) {
        throw new RuntimeException("Couldn't serialize method response", e);
    }
}

From source file:org.ajax4jsf.gwt.server.GwtFacesServlet.java

License:Open Source License

/**
 * Handle the GWT RPC call by looking up the client ID specified in the request, and passing a callback
 * via JSF to the proper JSF component.//  w  ww  .ja  va  2  s.c  o m
 */
public String processCall(String requestPayload) throws SerializationException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    String clientId;
    String responsePayload = null;
    RPCRequest rpcRequest;
    rpcRequest = RPC.decodeRequest(requestPayload);

    if (null != facesContext) {
        clientId = (String) facesContext.getExternalContext().getRequestParameterMap().get("clientId");

        if (null != clientId) {

            // Invoke event on target component
            GwtFacesCallback callback = new GwtFacesCallback(rpcRequest);
            try {
                facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, callback);
            } catch (Exception e) {
                // Hmm, for now, let's make this be a server-only exception.
                throw new UnexpectedException("Error send event to component", e);
            }
            responsePayload = callback.getResponsePayload();
        } else if (null != lifecycle) {
            // Invoke event on registered listeners.
            PhaseListener[] listeners = lifecycle.getPhaseListeners();
            for (int i = 0; i < listeners.length; i++) {
                PhaseListener listener = listeners[i];
                if (listener instanceof GwtCallListener) {
                    GwtCallListener gwtListener = (GwtCallListener) listener;
                    responsePayload = gwtListener.processRequest(rpcRequest);
                }
            }
        }
    } else {
        // Non-faces environment, attempt to load stub class for hosted mode
        HttpServletRequest threadLocalRequest = getThreadLocalRequest();
        String moduleName = threadLocalRequest.getParameter(ComponentEntryPoint.GWT_MODULE_NAME_PARAMETER);
        if (null == moduleName) {
            // Hackish here, not sure this will work properly.....
            throw new SecurityException("Module name not set in request");
        }
        // Find latest package delimiter. GWT not allow to use default package - since
        // always present.
        int i = moduleName.lastIndexOf('.');
        // Module class name
        String className = "Mock" + moduleName.substring(i + 1);
        // Module package name
        String packageName = moduleName.substring(0, i) + ".server.";
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        className = packageName + className;
        Class clazz = null;
        try {
            clazz = classLoader.loadClass(className);

            // assume it's looking for GwtFacesService.
            // TODO: figure out how to tell what it's actually looking for!
            // (probably just trust the call!?!)
            GwtFacesService service = (GwtFacesService) clazz.newInstance();
            // OK so it warns about varargs redundancy here, but what does it want????
            responsePayload = RPC.invokeAndEncodeResponse(service, rpcRequest.getMethod(),
                    rpcRequest.getParameters());
        } catch (ClassNotFoundException e) {
            throw new SecurityException("Could not find requested mock class " + className);
        } catch (Exception e) {
            throw new SecurityException("Could not construct mock service class " + clazz);
        }
    }
    return responsePayload;
}

From source file:org.kuali.continuity.admin.project.server.GwtRpcController.java

License:Educational Community License

@Override
public String processCall(String payload) throws SerializationException {
    try {/*from ww  w  . j a v  a2 s.  c  o m*/
        System.out.println("GwtRpcController: received " + payload);

        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass);
        logger.info("GwtRpeController.processCall: " + remoteServiceClass.getName());
        // delegate work to the spring injected service
        return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(),
                rpcRequest.getParameters());
    } catch (IncompatibleRemoteServiceException ex) {
        getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.",
                ex);
        return RPC.encodeResponseForFailure(null, ex);
    }
}