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;
  }
  @Override
  public String processCall(String payload) throws SerializationException {
    try {
      String serviceName = extractServiceName(getThreadLocalRequest().getServletPath());
      Object service = applicationContext.getBean(serviceName);

      RPCRequest rpcRequest = RPC.decodeRequest(payload, service.getClass(), this);
      onAfterRequestDeserialized(rpcRequest);

      return RPC.invokeAndEncodeResponse(
          service,
          rpcRequest.getMethod(),
          rpcRequest.getParameters(),
          rpcRequest.getSerializationPolicy(),
          rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
      log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
      return RPC.encodeResponseForFailure(null, ex);
    }
  }
Beispiel #3
0
  @Override
  public String processCall(String content) throws SerializationException {
    try {
      // decode the request
      RPCRequest rpcRequest = RPC.decodeRequest(content, this.serviceClass);

      // if this is any service other than UserService we check session security here
      if (!(service instanceof UserService)) {
        validateSession(rpcRequest.getParameters());
      }
      // delegate work to the spring injected service
      return RPC.invokeAndEncodeResponse(
          service, rpcRequest.getMethod(), rpcRequest.getParameters());
    } catch (IncompatibleRemoteServiceException ex) {
      getServletContext()
          .log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
      return RPC.encodeResponseForFailure(null, ex);
    } catch (SessionTimedOutException ste) {
      return RPC.encodeResponseForFailure(null, ste);
    }
  }
Beispiel #4
0
  public String processCall(String payload) throws SerializationException {
    // First, check for possible XSRF situation
    checkPermutationStrongName();

    try {
      Object handler = getBean(getThreadLocalRequest());
      RPCRequest rpcRequest = RPC.decodeRequest(payload, handler.getClass(), this);
      onAfterRequestDeserialized(rpcRequest);
      return RPC.invokeAndEncodeResponse(
          handler,
          rpcRequest.getMethod(),
          rpcRequest.getParameters(),
          rpcRequest.getSerializationPolicy(),
          rpcRequest.getFlags());
    } catch (IncompatibleRemoteServiceException ex) {
      log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
      return RPC.encodeResponseForFailure(null, ex);
    } catch (RpcTokenException tokenException) {
      log("An RpcTokenException was thrown while processing this call.", tokenException);
      return RPC.encodeResponseForFailure(null, tokenException);
    }
  }
  private SerializationPolicy loadPolicy(String className) {
    File policyFile = serializationPolicyFiles.get(className);
    if (policyFile == null) {
      log.warn("No RPC serialization policy for service " + className);
      return RPC.getDefaultSerializationPolicy();
    }

    InputStream in = null;
    try {
      in = FileUtils.openInputStream(policyFile);
      SerializationPolicy result = SerializationPolicyLoader.loadFromStream(in, null);
      log.info(
          "Loaded serrialization policy for "
              + className
              + " from file "
              + policyFile.getAbsolutePath());
      return result;
    } catch (IOException e) {
      log.error(
          "IOException: Unable to load serialization policy for "
              + className
              + " from file "
              + policyFile.getAbsolutePath(),
          e);
      return RPC.getDefaultSerializationPolicy();
    } catch (ParseException e) {
      log.error(
          "ParseException: Unable to load serialization policy for "
              + className
              + " from file "
              + policyFile.getAbsolutePath(),
          e);
      return RPC.getDefaultSerializationPolicy();
    } finally {
      IOUtils.closeQuietly(in);
    }
  }
  /**
   * 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()));
  }