return decodeRequest(encodedRequest, null);
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy, int flags) throws SerializationException { if (serviceMethod == null) { throw new NullPointerException("serviceMethod"); } if (serializationPolicy == null) { throw new NullPointerException("serializationPolicy"); } String responsePayload; try { Object result = serviceMethod.invoke(target, args); responsePayload = encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags); } catch (IllegalAccessException e) { SecurityException securityException = new SecurityException(formatIllegalAccessErrorMessage(target, serviceMethod)); securityException.initCause(e); throw securityException; } catch (IllegalArgumentException e) { SecurityException securityException = new SecurityException(formatIllegalArgumentErrorMessage(target, serviceMethod, args)); securityException.initCause(e); throw securityException; } catch (InvocationTargetException e) { // Try to encode the caught exception // Throwable cause = e.getCause(); responsePayload = encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags); } return responsePayload; }
/** * Returns a string that encodes the result of calling a service method, which * could be the value returned by the method or an exception thrown by it. * * <p> * This method does no security checking; security checking must be done on * the method prior to this invocation. * </p> * * @param target instance on which to invoke the serviceMethod * @param serviceMethod the method to invoke * @param args arguments used for the method invocation * @return a string which encodes either the method's return or a checked * exception thrown by the method * * @throws SecurityException if the method cannot be accessed or if the number * or type of actual and formal arguments differ * @throws SerializationException if an object could not be serialized by the * stream * @throws UnexpectedException if the serviceMethod throws a checked exception * that is not declared in its signature */ public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args) throws SerializationException { return invokeAndEncodeResponse(target, serviceMethod, args, getDefaultSerializationPolicy()); }
Object result = serviceMethod.invoke(target, args); responsePayload = RPC.encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags); .encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags);
@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 the object. It is an error to try to encode * an object that is not assignable to the service method's return type. * * @param serviceMethod the method whose result we are encoding * @param object the instance that we wish to encode * @return a string that encodes the object, if the object is compatible with * the service method's declared return type * * @throws IllegalArgumentException if the result is not assignable to the * service method's return type * @throws NullPointerException if the service method is <code>null</code> * @throws SerializationException if the result cannot be serialized */ public static String encodeResponseForSuccess(Method serviceMethod, Object object) throws SerializationException { return encodeResponseForSuccess(serviceMethod, object, getDefaultSerializationPolicy()); }
@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); } }
/** * Returns a string that encodes an exception. If method is not * <code>null</code>, it is an error if the exception is not in the method's * list of checked exceptions. * * @param serviceMethod the method that threw the exception, may be * <code>null</code> * @param cause the {@link Throwable} that was thrown * @return a string that encodes the exception * * @throws NullPointerException if the cause is <code>null</code> * @throws SerializationException if the result cannot be serialized * @throws UnexpectedException if the result was an unexpected exception (a * checked exception not declared in the serviceMethod's signature) */ public static String encodeResponseForFailure(Method serviceMethod, Throwable cause) throws SerializationException { return encodeResponseForFailure(serviceMethod, cause, getDefaultSerializationPolicy()); }
@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); } }
/** * Returns a string that encodes the object. It is an error to try to encode * an object that is not assignable to the service method's return type. * * <p> * If the serializationPolicy parameter is not <code>null</code>, it is used * to determine what types can be encoded as part of this response. If this * parameter is <code>null</code>, then only subtypes of * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or * types which have custom field serializers may be encoded. * </p> * * @param serviceMethod the method whose result we are encoding * @param object the instance that we wish to encode * @param serializationPolicy determines the serialization policy to be used * @return a string that encodes the object, if the object is compatible with * the service method's declared return type * * @throws IllegalArgumentException if the result is not assignable to the * service method's return type * @throws NullPointerException if the serviceMethod or the * serializationPolicy are <code>null</code> * @throws SerializationException if the result cannot be serialized */ public static String encodeResponseForSuccess(Method serviceMethod, Object object, SerializationPolicy serializationPolicy) throws SerializationException { return encodeResponseForSuccess(serviceMethod, object, serializationPolicy, AbstractSerializationStream.DEFAULT_FLAGS); }
@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); } } }
/** * Returns a string that encodes an exception. If method is not * <code>null</code>, it is an error if the exception is not in the method's * list of checked exceptions. * * <p> * If the serializationPolicy parameter is not <code>null</code>, it is used * to determine what types can be encoded as part of this response. If this * parameter is <code>null</code>, then only subtypes of * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or * types which have custom field serializers may be encoded. * </p> * * @param serviceMethod the method that threw the exception, may be * <code>null</code> * @param cause the {@link Throwable} that was thrown * @param serializationPolicy determines the serialization policy to be used * @return a string that encodes the exception * * @throws NullPointerException if the cause or the serializationPolicy * are <code>null</code> * @throws SerializationException if the result cannot be serialized * @throws UnexpectedException if the result was an unexpected exception (a * checked exception not declared in the serviceMethod's signature) */ public static String encodeResponseForFailure(Method serviceMethod, Throwable cause, SerializationPolicy serializationPolicy) throws SerializationException { return encodeResponseForFailure(serviceMethod, cause, serializationPolicy, AbstractSerializationStream.DEFAULT_FLAGS); }
rpcRequest = RPC.decodeRequest(payload, delegate.getClass(), this); } catch (IncompatibleRemoteServiceException ex) { log( "An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailedRequest(null, ex);
public static String encodeResponseForSuccess(Method serviceMethod, Object object, SerializationPolicy serializationPolicy, int flags) throws SerializationException { if (serviceMethod == null) { throw new NullPointerException("serviceMethod cannot be null"); } if (serializationPolicy == null) { throw new NullPointerException("serializationPolicy"); } Class<?> methodReturnType = serviceMethod.getReturnType(); if (methodReturnType != void.class && object != null) { Class<?> actualReturnType; if (methodReturnType.isPrimitive()) { actualReturnType = getPrimitiveClassFromWrapper(object.getClass()); } else { actualReturnType = object.getClass(); } if (actualReturnType == null || !methodReturnType.isAssignableFrom(actualReturnType)) { throw new IllegalArgumentException("Type '" + printTypeName(object.getClass()) + "' does not match the return type in the method's signature: '" + getSourceRepresentation(serviceMethod) + "'"); } } return encodeResponse(methodReturnType, object, false, flags, serializationPolicy); }
try { onAfterRequestDeserialized(rpcRequest); return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); "An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailedRequest(rpcRequest, ex); } catch (RpcTokenException tokenException) { log("An RpcTokenException was thrown while processing this call.", tokenException); return RPC.encodeResponseForFailedRequest(rpcRequest, tokenException);
return invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy, AbstractSerializationStream.DEFAULT_FLAGS);
+ moduleBaseURL + "'; a legacy, 1.3.3 compatible, serialization policy will be used. You may experience SerializationExceptions as a result."); serializationPolicy = RPC.getDefaultSerializationPolicy();
public static String encodeResponseForFailure(Method serviceMethod, Throwable cause, SerializationPolicy serializationPolicy, int flags) throws SerializationException { if (cause == null) { throw new NullPointerException("cause cannot be null"); } if (serializationPolicy == null) { throw new NullPointerException("serializationPolicy"); } if (serviceMethod != null && !RPCServletUtils.isExpectedException(serviceMethod, cause)) { throw new UnexpectedException("Service method '" + getSourceRepresentation(serviceMethod) + "' threw an unexpected exception: " + cause.toString(), cause); } return encodeResponse(cause.getClass(), cause, true, flags, serializationPolicy); }
RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); onAfterRequestDeserialized(rpcRequest); return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); "An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, 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()); } }