List of usage examples for com.google.gwt.user.server.rpc RPCRequest getMethod
public Method getMethod()
From source file:cc.alcina.framework.servlet.servlet.CommonRemoteServiceServlet.java
License:Apache License
@Override public String processCall(String payload) throws SerializationException { RPCRequest rpcRequest = null; String threadName = Thread.currentThread().getName(); try {//from www . j av a 2 s . co m LooseContext.push(); initUserStateWithCookie(getThreadLocalRequest(), getThreadLocalResponse()); LooseContext.set(CONTEXT_THREAD_LOCAL_HTTP_REQUEST, getThreadLocalRequest()); LooseContext.set(CommonPersistenceBase.CONTEXT_CLIENT_IP_ADDRESS, ServletLayerUtils.robustGetRemoteAddr(getThreadLocalRequest())); LooseContext.set(CommonPersistenceBase.CONTEXT_CLIENT_INSTANCE_ID, SessionHelper.getAuthenticatedSessionClientInstanceId(getThreadLocalRequest())); rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); if (rpcRequest.getSerializationPolicy() instanceof LegacySerializationPolicy) { throw new IncompatibleRemoteServiceException(); } getThreadLocalRequest().setAttribute(THRD_LOCAL_RPC_RQ, rpcRequest); getThreadLocalRequest().setAttribute(THRD_LOCAL_RPC_PAYLOAD, payload); String name = rpcRequest.getMethod().getName(); RPCRequest f_rpcRequest = rpcRequest; Thread.currentThread().setName(Ax.format("gwt-rpc:%s", name)); onAfterAlcinaAuthentication(name); LooseContext.set(CONTEXT_RPC_USER_ID, PermissionsManager.get().getUserId()); InternalMetrics.get().startTracker(rpcRequest, () -> describeRpcRequest(f_rpcRequest, ""), InternalMetricTypeAlcina.client, Thread.currentThread().getName(), () -> true); Method method; try { method = this.getClass().getMethod(name, rpcRequest.getMethod().getParameterTypes()); if (method.isAnnotationPresent(WebMethod.class)) { WebMethod webMethod = method.getAnnotation(WebMethod.class); AnnotatedPermissible ap = new AnnotatedPermissible(webMethod.customPermission()); if (!PermissionsManager.get().isPermissible(ap)) { WebException wex = new WebException("Action not permitted: " + name); logRpcException(wex, LogMessageType.PERMISSIONS_EXCEPTION.toString()); return RPC.encodeResponseForFailure(null, wex); } if (!webMethod.readonlyPermitted()) { AppPersistenceBase.checkNotReadOnly(); } } } catch (SecurityException ex) { RPC.encodeResponseForFailure(null, ex); } catch (NoSuchMethodException ex) { RPC.encodeResponseForFailure(null, ex); } return invokeAndEncodeResponse(rpcRequest); } catch (IncompatibleRemoteServiceException ex) { getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } catch (UnexpectedException ex) { logRpcException(ex); throw ex; } catch (OutOfMemoryError e) { handleOom(payload, e); throw e; } catch (RuntimeException rex) { logRpcException(rex); throw rex; } finally { Thread.currentThread().setName(threadName); InternalMetrics.get().endTracker(rpcRequest); if (TransformManager.hasInstance()) { if (CommonUtils .bv((Boolean) getThreadLocalRequest().getAttribute(PUSH_TRANSFORMS_AT_END_OF_REUQEST))) { Sx.commit(); } ThreadlocalTransformManager.cast().resetTltm(null); LooseContext.pop(); } else { try { LooseContext.pop(); } catch (Exception e) {// squelch, probably webapp undeployed } } } }
From source file:cc.alcina.framework.servlet.servlet.CommonRemoteServiceServlet.java
License:Apache License
protected String describeRpcRequest(RPCRequest rpcRequest, String msg) { msg += "Method: " + rpcRequest.getMethod().getName() + "\n"; msg += "User: " + PermissionsManager.get().getUserString() + "\n"; msg += "Types: " + CommonUtils.joinWithNewlineTab(Arrays.asList(rpcRequest.getMethod().getParameters())); msg += "\nParameters: \n"; Object[] parameters = rpcRequest.getParameters(); if (rpcRequest.getMethod().getName().equals("transform")) { } else {// w w w . j a v a 2 s.co m try { msg += new JacksonJsonObjectSerializer().withIdRefs().withMaxLength(100000) .serializeNoThrow(parameters); } catch (Throwable e) { e.printStackTrace(); } } return msg; }
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: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 {//from w w w. j ava 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.apress.progwt.server.gwt.GWTController.java
License:Apache License
@Override public String processCall(String payload) throws SerializationException { try {//from w w w . ja va 2s . com RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); ServerSerializationStreamWriter_1_5_3 writer = getWriter(rpcRequest); return RPC1524.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), writer); } catch (IncompatibleRemoteServiceException ex) { log.error("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } catch (Exception e) { log.error("An Exception was thrown while processing this call.", e); return RPC.encodeResponseForFailure(null, e); } }
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 www . j av a 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 { // 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.cubusmail.gwtui.server.services.MailboxService.java
License:Open Source License
@Override public String processCall(String payload) throws SerializationException { if (this.applicationContext == null) { this.applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); }/*from w w w . ja va 2 s . c o m*/ if (SessionManager.isLoggedIn()) { try { return super.processCall(payload); } catch (SerializationException e) { log.error(e.getMessage(), e); throw e; } } else { RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new GWTInvalidSessionException()); } }
From source file:com.cubusmail.gwtui.server.services.UserAccountService.java
License:Open Source License
@Override public String processCall(String payload) throws SerializationException { if (SessionManager.isLoggedIn()) { try {//from w w w.java 2 s. c om return super.processCall(payload); } catch (SerializationException e) { log.error(e.getMessage(), e); throw e; } } else { RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new GWTInvalidSessionException()); } }
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. j a v a 2s .c o m*/ * 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.edgenius.wiki.gwt.server.handler.GWTSpringController.java
License:Open Source License
public String processCall(String payload) throws SerializationException { try {/*from w w w . ja v a 2s .c o m*/ // Copy & pasted & edited from the GWT 1.4.3 RPC documentation RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); Method targetMethod = rpcRequest.getMethod(); Object[] targetParameters = rpcRequest.getParameters(); SerializationPolicy policy = rpcRequest.getSerializationPolicy(); try { Object result = targetMethod.invoke(this, targetParameters); String encodedResult; String redir = getRedir(); if (redir != null) { Throwable ae; if (redir.endsWith(WikiConstants.URL_CAPTCHA_VERIFIED_ERROR)) { ae = new CaptchaVerifiedException(redir); } else if (redir.endsWith(WikiConstants.URL_ACCESS_DENIED)) { ae = new ClientAccessDeniedException(redir); } else { //OK, maybe accessDenied or authentication or other error, then let Gwt redirect it anyway. ae = new ClientAuthenticationException(redir); } log.info("Send redir value " + redir); encodedResult = RPC.encodeResponseForFailure(null, ae, policy); } else { if (result instanceof GeneralModel) { //set current user info,so that client can check if its session is expired for each request User user = WikiUtil.getUser(); ((GeneralModel) result).loginUserFullname = user.getFullname(); ((GeneralModel) result).loginUsername = user.getUsername(); ((GeneralModel) result).loginUserUid = user.getUid(); } //return correct result encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, policy); } return encodedResult; } catch (IllegalArgumentException e) { log.error("Handle ajax call for service " + this + " with exception.", e); SecurityException securityException = new SecurityException( "Blocked attempt to invoke method " + targetMethod); securityException.initCause(e); throw securityException; } catch (IllegalAccessException e) { log.error("Handle ajax call for service " + this + " with exception.", e); SecurityException securityException = new SecurityException( "Blocked attempt to access inaccessible method " + targetMethod + (this != null ? " on service " + this : "")); securityException.initCause(e); throw securityException; } catch (InvocationTargetException e) { log.error("Handle ajax call for service " + this + " with exception.", e); Throwable cause = e.getCause(); log.warn("Get RPC InvocationTargetException exception, the root cause is " + cause); //following handle are not exactly response if redir value is null: accessDenied is only for login user, here does not check this. //so MethodExceptionHandler.handleException() give more exactly response. //MethodSecurityInterceptor.invoke() may throw Authentication and AccessDenied Exception, if targetMethod does not //capture these exception, then they will go to here!! The example is PageControllerImpl.viewPage(), it handle the accessDenied //exception, if it does not, then here will handle it... if (cause instanceof AuthenticationException) { String redir = getRedir(); if (redir == null) //system default value redir = WikiConstants.URL_LOGIN; log.info("Send Authentication redirect URL " + redir); ClientAuthenticationException ae = new ClientAuthenticationException(redir); return RPC.encodeResponseForFailure(null, ae, policy); } else if (cause instanceof AccessDeniedException) { String redir = getRedir(); if (redir == null) //system default value redir = WikiConstants.URL_ACCESS_DENIED; log.info("Send AccessDenied redirect URL " + redir); ClientAccessDeniedException ae = new ClientAccessDeniedException(redir); return RPC.encodeResponseForFailure(null, ae, policy); } log.info("Return unexpected exception to client side " + cause); String failurePayload = RPC.encodeResponseForFailure(rpcRequest.getMethod(), cause, policy); return failurePayload; } } catch (IncompatibleRemoteServiceException e) { log.warn(e.getMessage()); return RPC.encodeResponseForFailure(null, e); } catch (Exception e) { log.error("Ajax call failed", e); throw new RuntimeException(e); } }