com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(18.4k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure方法的一些代码示例,展示了RPC.encodeResponseForFailure的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RPC.encodeResponseForFailure方法的具体详情如下:
包路径:com.google.gwt.user.server.rpc.RPC
类名称:RPC
方法名:encodeResponseForFailure

RPC.encodeResponseForFailure介绍

[英]Returns a string that encodes an exception. If method is not null, it is an error if the exception is not in the method's list of checked exceptions.
[中]返回对异常进行编码的字符串。如果方法不是null,则如果异常不在方法的已检查异常列表中,则为错误。

代码示例

代码示例来源:origin: kaaproject/kaa

.encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags);

代码示例来源:origin: kaaproject/kaa

@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);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * 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);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * 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());
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * 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());
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

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;
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * 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);
}

代码示例来源:origin: net.sf.gwt-widget/gwt-sl

/**
 * 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);
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * 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());
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * 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());
}

代码示例来源:origin: com.github.livesense/org.liveSense.service.gwt

/**
 * 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;
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * 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());
 }
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * 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());
 }
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

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;
}

代码示例来源:origin: net.wetheinter/gwt-user

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;
}

代码示例来源:origin: net.sf.gwt-widget/gwt-sl

/**
 * 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);
}

代码示例来源:origin: sk.seges.acris/acris-server-components

/**
 * 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);
}

代码示例来源:origin: sk.seges.acris/acris-security-openid-core

@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);
  }
}

代码示例来源:origin: org.appverse.web.framework.modules.backend.frontfacade.gwt/appverse-web-modules-backend-frontfacade-gwt

@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);
  }
}

代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-gwt-poll

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);
  }
}

相关文章