示例#1
0
  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 =
          RPC.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();

      LOG.error(
          "Unexpected exception occured while invoking service method - "
              + (serviceMethod != null ? serviceMethod.getName() : "null"),
          cause);

      responsePayload =
          RPC.encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags);
    }

    return responsePayload;
  }
  /**
   * Serializes the result of the given method for RPC-prefetching.
   *
   * <p>
   *
   * @param method the method
   * @param data the result to serialize
   * @return the serialized data
   * @throws SerializationException if something goes wrong
   */
  protected String serialize(Method method, Object data) throws SerializationException {

    return escape(
        RPC.encodeResponseForSuccess(method, data, CmsPrefetchSerializationPolicy.instance()));
  }