.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 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); }
/** * 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()); }
/** * 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()); } }
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 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); }
/** * Invoked by {@link #processCall(String)} when RPC throws an * {@link IncompatibleRemoteServiceException}. This implementation * propagates the exception back to the client via RPC. * * @param e * Exception thrown * @return RPC encoded failure response * @throws SerializationException */ protected String handleIncompatibleRemoteServiceException(IncompatibleRemoteServiceException cause) throws SerializationException { logger.warn(cause.getMessage()); return RPC.encodeResponseForFailure(null, cause); }
/** * 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()); }
/** * 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()); }
/** * Exception handler. Doublle exception handling * @param phase * @param payload * @param e * @return */ private String processException(String phase, String payload, Throwable e) { String ret = "EX"; try { ret = RPC.encodeResponseForFailure(null, e); payloadLogger.error(">>> ("+phase+") User: "+getUser()+" Payload: "+payload+" Return: "+ret, e); } catch (Exception ex) { try { ret = RPC.encodeResponseForFailure(null, new SerializationException("Serialization error", ex)); } catch (SerializationException e2) { } payloadLogger.error(">>> ("+phase+") User: "+getUser()+" Payload: "+payload+" Return: "+ret, ex); } payloadLogger.info("<<< ("+phase+") User: "+getUser()+" Return: "+ret); return ret; }
/** * 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()); } }
/** * 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()); } }
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; }
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; }
/** * 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); }
@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 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); } }
static void writeResponse(AtmosphereResource resource, Object message) throws IOException { try { RPCRequest rpcRequest = (RPCRequest) resource.getRequest().getAttribute(AtmospherePollService.GWT_REQUEST); String response = encodeResponse(rpcRequest, message); writeResponse(resource.getRequest(), resource.getResponse(), resource.getAtmosphereConfig().getServletContext(), response); } catch (IncompatibleRemoteServiceException ex) { try { String error = RPC.encodeResponseForFailure(null, ex); writeResponse(resource.getRequest(), resource.getResponse(), resource.getAtmosphereConfig().getServletContext(), error); } catch (SerializationException ex2) { throw new IOException(ex2); } } catch (SerializationException ex) { throw new IOException(ex); } }