@Override public String processCall(String payload) throws SerializationException { try { perThreadRequest.set(getThreadLocalRequest()); Object handler = getBean(getThreadLocalRequest()); RPCRequest rpcRequest = RPC.decodeRequest(payload, handler.getClass(), this); onAfterRequestDeserialized(rpcRequest); if (LOG.isDebugEnabled()) { LOG.debug("Invoking " + handler.getClass().getName() + "." + rpcRequest.getMethod().getName()); } return RpcHelper .invokeAndEncodeResponse( handler, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy() ); } catch (IncompatibleRemoteServiceException ex) { log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } catch (SerializationException ex) { LOG.error("An SerializationException was thrown while processing this call.", ex); throw ex; } finally { perThreadRequest.set(null); } }
try { onAfterRequestDeserialized(rpcRequest); return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
static String encodeResponse(RPCRequest rpcRequest, Object message) throws SerializationException { if (rpcRequest == null) { throw new NullPointerException("rpcRequest"); } if (rpcRequest.getSerializationPolicy() == null) { throw new NullPointerException("serializationPolicy"); } String responsePayload; responsePayload = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), message, rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); return responsePayload; }
@Override public String processCall(final String payload) throws SerializationException { try { 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); } }
/** * Wrapper around RPC utility invocation * @param rpcRequest RPCRequest * @param cause Exception to handle * @param targetMethod Method which threw the exception * @param targetParameters Method arguments * @return RPC payload * @throws Exception */ protected String encodeResponseForFailure(RPCRequest rpcRequest, Throwable cause, Method targetMethod, Object[] targetParameters) throws SerializationException{ SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForFailure(rpcRequest, service, targetMethod, targetParameters, cause); return RPC.encodeResponseForFailure(rpcRequest.getMethod(), cause, serializationPolicy, serializationFlags); }
/** * Wrapper around RPC utility invocation * @param rpcRequest RPCRequest * @param cause Exception to handle * @param targetMethod Method which threw the exception * @param targetParameters Method arguments * @return RPC payload * @throws Exception */ protected String encodeResponseForFailure(RPCRequest rpcRequest, Throwable cause, Method targetMethod, Object[] targetParameters) throws SerializationException{ SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForFailure(rpcRequest, service, targetMethod, targetParameters, cause); return RPC.encodeResponseForFailure(rpcRequest.getMethod(), cause, serializationPolicy, serializationFlags); }
/** * Handles method invocation on a service and is invoked by * {@link #processCall(String)}. * * @param service * Service to invoke method on * @param targetMethod * Method to invoke. * @param targetParameters * Parameters to pass to method. Can be null for no arguments. * @param rpcRequest * RPCRequest instance for this request * @return Return RPC encoded result. * @throws Exception */ protected String invokeMethodOnService(Object service, Method targetMethod, Object[] targetParameters, RPCRequest rpcRequest) throws Exception { Object result = targetMethod.invoke(service, targetParameters); SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForSuccess(rpcRequest, service, targetMethod, targetParameters, result); String encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, serializationPolicy, serializationFlags); return encodedResult; }
/** * Handles method invocation on a service and is invoked by * {@link #processCall(String)}. * * @param service * Service to invoke method on * @param targetMethod * Method to invoke. * @param targetParameters * Parameters to pass to method. Can be null for no arguments. * @param rpcRequest * RPCRequest instance for this request * @return Return RPC encoded result. * @throws Exception */ protected String invokeMethodOnService(Object service, Method targetMethod, Object[] targetParameters, RPCRequest rpcRequest) throws Exception { Object result = targetMethod.invoke(service, targetParameters); SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForSuccess(rpcRequest, service, targetMethod, targetParameters, result); String encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, serializationPolicy, serializationFlags); return encodedResult; }
@Override public String processCall(String payload) throws SerializationException { try { RPCRequest req = RPC.decodeRequest(payload, null, this); RemoteService service = getServiceInstance(req.getMethod().getDeclaringClass()); return RPC.invokeAndEncodeResponse(service, req.getMethod(), req.getParameters(), req.getSerializationPolicy(), req.getFlags()); } catch (IncompatibleRemoteServiceException ex) { log("IncompatibleRemoteServiceException in the processCall(String) method.", ex); return RPC.encodeResponseForFailure(null, ex); } }
@Override public Object doTask( TaskContext<GwtServiceTask, Dependencies, Indexed> context) throws Throwable { // Obtain the request ServerGwtRpcConnection<?> connection = (ServerGwtRpcConnection<?>) context .getObject(Dependencies.SERVER_GWT_RPC_CONNECTION); // Obtain the GWT request RPCRequest rpc = connection.getRpcRequest(); // Obtain the flow index String methodName = rpc.getMethod().getName(); Integer flowIndex = this.methodToFlow.get(methodName); if (flowIndex == null) { // Indicate unknown GWT service method connection.onFailure(new IncompatibleRemoteServiceException( "Unknown service method '" + methodName + "(...)'")); return null; // No further processing } // Obtain the parameter value Object[] parameters = rpc.getParameters(); Object parameter = (parameters.length == 0 ? null : parameters[0]); // Invoke flow to service request context.doFlow(flowIndex.intValue(), parameter); // Processing by flows return null; }
@Override protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { 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); } } }
@Override protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { 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); } } }
@RequestMapping(value = "/commandService", method = RequestMethod.POST) public void processPostRpc(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { 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); } }
@Override protected void onAfterRequestDeserialized(RPCRequest request) { final Principal principal = getThreadLocalRequest().getUserPrincipal(); if (principal == null || StringUtils.isNullOrEmpty(principal.getName())) { throw new DCSecurityException("No user principal - log in to use the system"); } if (!(principal instanceof Authentication)) { throw new IllegalStateException("Principal is not an instance of Authentication: " + principal); } final Authentication authentication = (Authentication) principal; final UserBean user = new UserBean(); user.updateUser(authentication, getTenantResolver()); final Method method = request.getMethod(); final RolesAllowed rolesAllowedAnnotation = ReflectionUtils.getAnnotation(method, RolesAllowed.class); if (rolesAllowedAnnotation != null) { String[] rolesAllowed = rolesAllowedAnnotation.value(); checkRoles(user, rolesAllowed, method); } final Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { final Class<?> cls = parameterTypes[i]; if (cls == TenantIdentifier.class) { TenantIdentifier tenantIdentifier = (TenantIdentifier) request.getParameters()[i]; checkTenant(user, tenantIdentifier); break; } } }
Method targetMethod = getMethodToInvoke(rpcRequest.getMethod()); Object[] targetParameters = rpcRequest.getParameters();