public Object invoke(Object target, Method method, Object[] params) throws Throwable {
      if (EQUALS_METHOD.equals(method)) {
        Object param = params[0];
        if (param == null || !Proxy.isProxyClass(param.getClass())) {
          return false;
        }
        InvocationHandler other = Proxy.getInvocationHandler(param);
        return equals(other);
      } else if (HASHCODE_METHOD.equals(method)) {
        return hashCode();
      }

      MethodInvocation invocation =
          new MethodInvocation(
              method.getName(),
              method.getReturnType(),
              method.getGenericReturnType(),
              method.getParameterTypes(),
              delegate,
              params);
      invoker.invoke(invocation);
      if (!invocation.found()) {
        String methodName =
            method.getDeclaringClass().getSimpleName() + "." + method.getName() + "()";
        throw Exceptions.unsupportedMethod(methodName);
      }
      return invocation.getResult();
    }
 /** Unpacks the source object from a given view object. */
 public Object unpack(Object viewObject) {
   if (!Proxy.isProxyClass(viewObject.getClass())
       || !(Proxy.getInvocationHandler(viewObject) instanceof InvocationHandlerImpl)) {
     throw new IllegalArgumentException("The given object is not a view object");
   }
   InvocationHandlerImpl handler = (InvocationHandlerImpl) Proxy.getInvocationHandler(viewObject);
   return handler.delegate;
 }
Пример #3
0
  public void registerMockedClass(@Nonnull Class<?> mockedType) {
    if (!isMockedClass(mockedType)) {
      if (Proxy.isProxyClass(mockedType)) {
        mockedType = mockedType.getInterfaces()[0];
      }

      mockedClasses.add(mockedType);
    }
  }
Пример #4
0
 /**
  * Helper method used to weed out dynamic Proxy types; types that do not expose concrete method
  * API that we could use to figure out automatic Bean (property) based serialization.
  */
 public static boolean isProxyType(Class<?> type) {
   // Then: well-known proxy (etc) classes
   if (Proxy.isProxyClass(type)) {
     return true;
   }
   String name = type.getName();
   // Hibernate uses proxies heavily as well:
   if (name.startsWith("net.sf.cglib.proxy.") || name.startsWith("org.hibernate.proxy.")) {
     return true;
   }
   // Not one of known proxies, nope:
   return false;
 }
Пример #5
0
 public static final Connection getConnection() throws SQLException {
   Connection conn = conns.get();
   if (conn == null || conn.isClosed()) {
     conn = _getConnection();
     if (conn == null) throw new SQLException("Unabled to get connection.");
     conns.set(conn);
     // RequestContext ctx = RequestContext.get();
     // connectionContext.put(
     // Thread.currentThread().getId(),
     // new ConnectionContext(new Exception(), (ctx != null) ? ctx
     // .ip() : null, (ctx != null) ? ctx.uri() : null,
     // (ctx != null) ? ctx.request().getParameterMap()
     // : null));
   }
   return (show_sql && !Proxy.isProxyClass(conn.getClass()))
       ? new _DebugConnection(conn).getConnection()
       : conn;
 }
Пример #6
0
 private static void checkStub(Remote stub, Class<? extends Remote> stubClass) {
   // Check remote stub is from the expected class.
   //
   if (stub.getClass() != stubClass) {
     if (!Proxy.isProxyClass(stub.getClass())) {
       throw new SecurityException("Expecting a " + stubClass.getName() + " stub!");
     } else {
       InvocationHandler handler = Proxy.getInvocationHandler(stub);
       if (handler.getClass() != RemoteObjectInvocationHandler.class) {
         throw new SecurityException(
             "Expecting a dynamic proxy instance with a "
                 + RemoteObjectInvocationHandler.class.getName()
                 + " invocation handler!");
       } else {
         stub = (Remote) handler;
       }
     }
   }
   // Check RemoteRef in stub is from the expected class
   // "sun.rmi.server.UnicastRef2".
   //
   RemoteRef ref = ((RemoteObject) stub).getRef();
   if (ref.getClass() != UnicastRef2.class) {
     throw new SecurityException(
         "Expecting a " + UnicastRef2.class.getName() + " remote reference in stub!");
   }
   // Check RMIClientSocketFactory in stub is from the expected class
   // "javax.rmi.ssl.SslRMIClientSocketFactory".
   //
   LiveRef liveRef = ((UnicastRef2) ref).getLiveRef();
   RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
   if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
     throw new SecurityException(
         "Expecting a "
             + SslRMIClientSocketFactory.class.getName()
             + " RMI client socket factory in stub!");
   }
 }