List of usage examples for com.google.gwt.user.server.rpc RPC decodeRequest
public static RPCRequest decodeRequest(String encodedRequest)
From source file:com.google.gwt.examples.rpc.server.AdvancedExample.java
License:Apache License
/** * An example of how you could integrate GWTs RPC functionality without using * the {@link com.google.gwt.user.server.rpc.RemoteServiceServlet}. Note that * it also shows how mapping between and RPC interface and some other POJO * could be performed.// w w w .j a v a2 s . c o m */ @Override public void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { String payload = readPayloadAsUtf8(httpRequest); try { try { RPCRequest rpcRequest = RPC.decodeRequest(payload); Object targetInstance = getInstanceToHandleRequest(httpRequest, rpcRequest); Method targetMethod = maybeMapRequestedMethod(targetInstance, rpcRequest.getMethod()); Object[] targetParameters = maybeMapParameters(rpcRequest.getParameters()); try { Object result = targetMethod.invoke(targetInstance, targetParameters); result = maybeMapResult(rpcRequest.getMethod(), result); /* * Encode the object that will be given to the client code's * AsyncCallback::onSuccess(Object) method. */ String encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result); sendResponseForSuccess(httpResponse, encodedResult); } catch (IllegalArgumentException e) { SecurityException securityException = new SecurityException( "Blocked attempt to invoke method " + targetMethod); securityException.initCause(e); throw securityException; } catch (IllegalAccessException e) { SecurityException securityException = new SecurityException( "Blocked attempt to access inaccessible method " + targetMethod + (targetInstance != null ? " on target " + targetInstance : "")); securityException.initCause(e); throw securityException; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); Throwable mappedThrowable = maybeMapThrowable(cause, rpcRequest.getMethod()); /* * Encode the exception that will be passed back to the client's * client code's AsyncCallback::onFailure(Throwable) method. */ String failurePayload = RPC.encodeResponseForFailure(rpcRequest.getMethod(), mappedThrowable); sendResponseForFailure(httpResponse, failurePayload); } } catch (IncompatibleRemoteServiceException e) { sendResponseForFailure(httpResponse, RPC.encodeResponseForFailure(null, e)); } } catch (Throwable e) { /* * Return a generic error which will be passed to the client code's * AsyncCallback::onFailure(Throwable) method. */ sendResponseForGenericFailure(httpResponse); } }
From source file:com.openforevent.gwt.gwtrpc.util.GwtRpcPayloadUtil.java
License:Apache License
public static HashMap<String, String> getParameters(String requestPayload) { HashMap<String, String> parameters = null; RPCRequest rpcRequest = RPC.decodeRequest(requestPayload); Object[] obj = rpcRequest.getParameters(); parameters = (HashMap<String, String>) obj[0]; if (Debug.infoOn()) { Debug.logInfo("rpc request method : " + rpcRequest.getMethod(), module); Debug.logInfo("rpc request serialization policy : " + rpcRequest.getSerializationPolicy(), module); Debug.logInfo("rpc request flags : " + rpcRequest.getFlags(), module); Debug.logInfo("rpc request parameters : " + obj, module); Debug.logInfo("parameters map : " + parameters, module); }/*from ww w. j a v a2 s . c om*/ return parameters; }
From source file:jolie.net.HttpProtocol.java
License:Open Source License
private static String parseGWTRPC(HttpMessage message, Value value) throws IOException { RPCRequest request = RPC.decodeRequest(new String(message.content(), "UTF8")); String operationName = (String) request.getParameters()[0]; joliex.gwt.client.Value requestValue = (joliex.gwt.client.Value) request.getParameters()[1]; JolieGWTConverter.gwtToJolieValue(requestValue, value); return operationName; }
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.//from ww w. ja v a 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; }