try { onAfterRequestDeserialized(rpcRequest); return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); } catch (IncompatibleRemoteServiceException ex) { log(
@Override protected void onAfterRequestDeserialized(RPCRequest rpcRequest) { if (shouldValidateXsrfToken(rpcRequest.getMethod())) { validateXsrfToken(rpcRequest.getRpcToken(), rpcRequest.getMethod()); } }
@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); } }
/** * Returns a string that encodes an exception. If <code>rpcRequest</code> * is <code>null</code> a default serialization policy and default request * flags will be used. Otherwise these information are taken from * <code>rpcRequest</code>. * <p> * This method should be used if the RPC request could not be decoded or * could not be executed because of an exception thrown, e.g. * {@link IncompatibleRemoteServiceException}, {@link RpcTokenException} * </p> * @param rpcRequest the RPCRequest that failed to execute, may be null * @param cause the {@link Throwable} that was thrown * @return a String that encodes the exception * @throws SerializationException if the result cannot be serialized */ public static String encodeResponseForFailedRequest(RPCRequest rpcRequest, Throwable cause) throws SerializationException { if (rpcRequest == null) { return RPC.encodeResponseForFailure(null, cause, getDefaultSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS); } else { return RPC.encodeResponseForFailure(null, cause, rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); } }
@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; }
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; }
public SerializationPolicy getSerializationPolicyForSuccess( RPCRequest request, Object target, Method method, Object[] parameters, Object result) { return request.getSerializationPolicy(); }
/** * Handles the {@link CometPublicationService}. * * @param connection * {@link ServerGwtRpcConnection} to notify client that * published. * @param flow * {@link PublishFlow}. */ public void publish(ServerGwtRpcConnection<Long> connection, PublishFlow flow) { // Obtain the published event RPCRequest request = connection.getRpcRequest(); CometEvent event = (CometEvent) request.getParameters()[0]; // Publish the event flow.publish(event); }
return new RPCRequest(method, parameterValues, rpcToken, serializationPolicy, streamReader .getFlags()); } catch (NoSuchMethodException e) {
return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException e) { return RPC.encodeResponseForFailure(null, 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; } } }
payload = RPC.encodeResponseForSuccess(rpc.getMethod(), result, rpc.getSerializationPolicy(), rpc.getFlags()); } catch (Exception ex) {
/** * Returns a string that encodes an exception. If <code>rpcRequest</code> * is <code>null</code> a default serialization policy and default request * flags will be used. Otherwise these information are taken from * <code>rpcRequest</code>. * <p> * This method should be used if the RPC request could not be decoded or * could not be executed because of an exception thrown, e.g. * {@link IncompatibleRemoteServiceException}, {@link RpcTokenException} * </p> * @param rpcRequest the RPCRequest that failed to execute, may be null * @param cause the {@link Throwable} that was thrown * @return a String that encodes the exception * @throws SerializationException if the result cannot be serialized */ public static String encodeResponseForFailedRequest(RPCRequest rpcRequest, Throwable cause) throws SerializationException { if (rpcRequest == null) { return RPC.encodeResponseForFailure(null, cause, getDefaultSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS); } else { return RPC.encodeResponseForFailure(null, cause, rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); } }
/** * 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); }
public SerializationPolicy getSerializationPolicyForFailure( RPCRequest request, Object target, Method method, Object[] parameters, Throwable exception) { return request.getSerializationPolicy(); }
@Override public void service(ServerGwtRpcConnection<CometResponse> connection) { // Obtain the Comet Request RPCRequest rpcRequest = connection.getRpcRequest(); CometRequest cometRequest = (CometRequest) rpcRequest.getParameters()[0]; // Retrieve or wait on events for Comet Request this.source.receiveOrWaitOnEvents(cometRequest.getInterests(), connection, this.async, cometRequest.getLastSequenceNumber()); }
return new RPCRequest(method, parameterValues, rpcToken, serializationPolicy, streamReader .getFlags()); } catch (NoSuchMethodException e) {
@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); } }
Method targetMethod = getMethodToInvoke(rpcRequest.getMethod()); Object[] targetParameters = rpcRequest.getParameters();