List of usage examples for com.google.gwt.user.server.rpc RPC invokeAndEncodeResponse
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy) throws SerializationException
From source file:cc.alcina.framework.servlet.servlet.CommonRemoteServiceServlet.java
License:Apache License
protected String invokeAndEncodeResponse(RPCRequest rpcRequest) throws SerializationException { return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); }
From source file:com.dotspots.rpcplus.flexiblerpc.FlexibleRemoteServiceServlet.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. * <p>//from w ww . java 2 s . c om * 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()); } catch (IncompatibleRemoteServiceException ex) { log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } }
From source file:com.google.gwt.sample.stockwatcher_rpc.utils.SpringRPCDispatcherServlet.java
@Override public String processCall(String payload) throws SerializationException { try {// w w w . ja v a 2 s . c o m RemoteService handler = retrieveSpringBean(getThreadLocalRequest()); RPCRequest rpcRequest = RPC.decodeRequest(payload, handler.getClass(), this); onAfterRequestDeserialized(rpcRequest); if (logger.isDebugEnabled()) { logger.debug("Invoking " + handler.getClass().getName() + "." + rpcRequest.getMethod().getName()); } return RPC.invokeAndEncodeResponse(handler, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { logger.error("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } }
From source file:net.latin.server.GwtBaseAction.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 ww w. ja va 2 s. 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) */ public String processCall(String payload) throws SerializationException { try { RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } }
From source file:org.cruxframework.crux.core.server.dispatch.RemoteServiceServlet.java
License:Apache License
/** * @see com.google.gwt.user.server.rpc.RemoteServiceServlet#processCall(java.lang.String) *//*w w w .j av a 2 s . c o m*/ @Override public String processCall(String payload) throws SerializationException { boolean localeInitializedByServlet = false; try { localeInitializedByServlet = initUserLocaleResolver(); Object service = getServiceForRequest(payload); RPCRequest rpcRequest = RPC.decodeRequest(payload, service.getClass(), this); onAfterRequestDeserialized(rpcRequest); //TODO: criar um ponto de injecao de comportamento aki.... para permitir que plugins sejam criados (ex: seguranca, logs, etc) CruxSynchronizerTokenHandler handler = CruxSynchronizerTokenHandlerFactory .getCruxSynchronizerTokenHandler(getThreadLocalRequest()); boolean useToken = checkSynchonizerToken(rpcRequest, handler); try { return RPC.invokeAndEncodeResponse(service, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } finally { if (useToken) { String methodFullSignature = handler.getMethodDescription(rpcRequest.getMethod()); handler.endMethod(methodFullSignature); } } } catch (IncompatibleRemoteServiceException ex) { log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } finally { if (localeInitializedByServlet) { clearUserLocaleResolver(); } } }
From source file:org.exoplatform.wiki.webui.WikiRemoteServiceServlet.java
License:Open Source License
/** * {@inheritDoc}//from www . ja va2 s . co m * * @see RemoteServiceServlet#processCall(String) */ public String processCall(String payload) throws SerializationException { String result; PortalContainer portalContainer; SessionManager sessionManager; String sessionId = getThreadLocalRequest().getSession(false).getId(); try { sessionManager = (SessionManager) RootContainer.getComponent(SessionManager.class); portalContainer = RootContainer.getInstance() .getPortalContainer(sessionManager.getSessionContainer(sessionId)); } catch (Exception e) { return RPC.encodeResponseForFailure(null, e); } ExoContainer oldContainer = ExoContainerContext.getCurrentContainer(); ExoContainerContext.setCurrentContainer(portalContainer); RequestLifeCycle.begin(portalContainer); try { RPCRequest req = RPC.decodeRequest(payload, null, this); RenderingServiceImpl renderingService = (RenderingServiceImpl) portalContainer .getComponentInstanceOfType(RenderingService.class); WikiContext wikiContext = (WikiContext) sessionManager.getSessionContext(sessionId); Execution ec = ((RenderingServiceImpl) renderingService).getExecution(); if (ec.getContext() == null) { ec.setContext(new ExecutionContext()); ec.getContext().setProperty(WikiContext.WIKICONTEXT, wikiContext); } RemoteService service = (RemoteService) renderingService .getComponent(req.getMethod().getDeclaringClass()); result = RPC.invokeAndEncodeResponse(service, req.getMethod(), req.getParameters(), req.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { log("IncompatibleRemoteServiceException in the processCall(String) method.", ex); result = RPC.encodeResponseForFailure(null, ex); } catch (Exception e) { log("Exception in the processCall(String) method.", e); result = RPC.encodeResponseForFailure(null, e); } finally { ExoContainerContext.setCurrentContainer(oldContainer); RequestLifeCycle.end(); } return result; }
From source file:org.glimpse.spring.web.RemoteServiceDispatcher.java
License:Apache License
protected String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy) throws SerializationException { RemoteServiceUtil.setThreadLocals(getThreadLocalRequest(), getThreadLocalResponse(), getServletContext()); // Hook in case subclass needs to prepare onBeforeServiceCall(target);/*from www . j ava 2 s .c o m*/ String response = RPC.invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy); // Hook in case subclass needs to cleanup onAfterServiceCall(target); RemoteServiceUtil.clearThreadLocals(); return response; }
From source file:org.jahia.ajax.gwt.commons.server.GWTController.java
License:Open Source License
@Override public String processCall(String payload) throws SerializationException { RemoteService remoteService = null;/* w ww . j ava 2 s .c om*/ RPCRequest rpcRequest = null; try { remoteService = (RemoteService) applicationContext.getBean(remoteServiceName); setServiceData(remoteService, false); rpcRequest = RPC.decodeRequest(payload, remoteService.getClass(), this); if (logger.isDebugEnabled()) { logger.debug("Executing method " + rpcRequest.getMethod()); } return RPC.invokeAndEncodeResponse(remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (Exception e) { if (rpcRequest != null) { logger.error("An error occurred calling the GWT service method " + rpcRequest.getMethod() + ". Cause: " + e.getMessage(), e); } else { logger.error("An error occurred calling the GWT service " + (remoteService != null ? remoteService.getClass().getName() : remoteServiceName) + ". Cause: " + e.getMessage(), e); } return RPC.encodeResponseForFailure(null, e); } finally { if (remoteService != null) { setServiceData(remoteService, true); } } }
From source file:org.pentaho.mantle.server.DebugRemoteServiceServlet.java
License:Open Source 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 av a2 s.com * <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); return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", //$NON-NLS-1$ ex); return RPC.encodeResponseForFailure(null, ex); } }
From source file:org.pentaho.platform.web.servlet.AbstractGwtRpcProxyServlet.java
License:Open Source License
@Override public String processCall(String payload) throws SerializationException { Map<Class<?>, Boolean> whitelist = new HashMap<Class<?>, Boolean>(); whitelist.put(GwtRpcProxyException.class, Boolean.TRUE); Map<Class<?>, String> obfuscatedTypeIds = new HashMap<Class<?>, String>(); StandardSerializationPolicy policy = new StandardSerializationPolicy(whitelist, whitelist, obfuscatedTypeIds);/*from ww w . jav a 2 s . c o m*/ String servletContextPath = getServletContextPath(); Object target = null; try { target = resolveDispatchTarget(servletContextPath); } catch (GwtRpcProxyException ex) { logger.error(Messages.getInstance().getErrorString( "AbstractGwtRpcProxyServlet.ERROR_0001_FAILED_TO_RESOLVE_DISPATCH_TARGET", servletContextPath), //$NON-NLS-1$ ex); return RPC.encodeResponseForFailure(null, ex, policy); } final ClassLoader origLoader = Thread.currentThread().getContextClassLoader(); final ClassLoader altLoader = target.getClass().getClassLoader(); try { // temporarily swap out the context classloader to an alternate classloader if // the targetBean has been loaded by one other than the context classloader. // This is necessary, so the RPC class can do a Class.forName and find the service // class specified in the request if (altLoader != origLoader) { Thread.currentThread().setContextClassLoader(altLoader); } RPCRequest rpcRequest = RPC.decodeRequest(payload, null, this); onAfterRequestDeserialized(rpcRequest); // don't require the server side to implement the service interface Method method = rpcRequest.getMethod(); try { Method m = target.getClass().getMethod(method.getName(), method.getParameterTypes()); if (m != null) { method = m; } } catch (Exception e) { e.printStackTrace(); } return RPC.invokeAndEncodeResponse(target, method, rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { logger.error(Messages.getInstance().getErrorString( "AbstractGwtRpcProxyServlet.ERROR_0003_RPC_INVOCATION_FAILED", target.getClass().getName()), //$NON-NLS-1$ ex); return RPC.encodeResponseForFailure(null, ex); } finally { // reset the context classloader if necessary if ((altLoader != origLoader) && origLoader != null) { Thread.currentThread().setContextClassLoader(origLoader); } } }