Ejemplo n.º 1
0
  private void call(String operation, Map<String, String> args)
      throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    final String requestClassName = packageName + ".model." + operation + "Request";
    final String operationMethodName =
        operation.substring(0, 1).toLowerCase() + operation.substring(1);
    Class<Object> requestClass = ReflectionUtils.loadClass(this.getClass(), requestClassName);
    Object requestObject = ReflectionUtils.newInstance(requestClass);

    if (args != null && !args.isEmpty()) {
      for (Map.Entry<String, String> entry : args.entrySet()) {

        String key = entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1);
        Object value =
            convertTo(
                ReflectionUtils.getParameterTypes(requestObject, Arrays.asList(key)),
                entry.getValue());

        ReflectionUtils.setByPath(requestObject, value, Arrays.asList(key));
      }
    }

    Method method = ReflectionUtils.findMethod(client, operationMethodName, requestClass);

    result = method.invoke(client, requestObject);
  }