private static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) { Object object = Proxy.newProxyInstance( interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler); return interfaceType.cast(object); }
private boolean isProxyForSameBshObject(Object other) { if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler ih = Proxy.getInvocationHandler(other); return (ih instanceof BshObjectInvocationHandler && this.xt.equals(((BshObjectInvocationHandler) ih).xt)); } }
/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @throws IllegalArgumentException if the specified interfaces expose * conflicting method signatures (or a similar constraint is violated) * @see java.lang.reflect.Proxy#getProxyClass */ @SuppressWarnings("deprecation") public static Class<?> createCompositeInterface(Class<?>[] interfaces, @Nullable ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); return Proxy.getProxyClass(classLoader, interfaces); }
/** * Check whether the given object is a JDK dynamic proxy. * <p>This method goes beyond the implementation of * {@link Proxy#isProxyClass(Class)} by additionally checking if the * given object is an instance of {@link SpringProxy}. * @param object the object to check * @see java.lang.reflect.Proxy#isProxyClass */ public static boolean isJdkDynamicProxy(@Nullable Object object) { return (object instanceof SpringProxy && Proxy.isProxyClass(object.getClass())); }
@Override public @Nullable String getSelectedProtocol(SSLSocket socket) { try { AlpnProvider provider = (AlpnProvider) Proxy.getInvocationHandler(getMethod.invoke(null, socket)); if (!provider.unsupported && provider.selected == null) { Platform.get().log(INFO, "ALPN callback dropped: HTTP/2 is disabled. " + "Is alpn-boot on the boot class path?", null); return null; } return provider.unsupported ? null : provider.selected; } catch (InvocationTargetException | IllegalAccessException e) { throw new AssertionError("failed to get ALPN selected protocol", e); } }
private static boolean isProxyOfSameInterfaces(Object arg, Class<?> proxyClass) { return proxyClass.isInstance(arg) // Equal proxy instances should mostly be instance of proxyClass // Under some edge cases (such as the proxy of JDK types serialized and then deserialized) // the proxy type may not be the same. // We first check isProxyClass() so that the common case of comparing with non-proxy objects // is efficient. || (Proxy.isProxyClass(arg.getClass()) && Arrays.equals(arg.getClass().getInterfaces(), proxyClass.getInterfaces())); } }
@Override public String getSelectedProtocol(SSLSocket socket) { try { JettyNegoProvider provider = (JettyNegoProvider) Proxy.getInvocationHandler(getMethod.invoke(null, socket)); if (!provider.unsupported && provider.selected == null) { Platform.get().log(INFO, "ALPN callback dropped: HTTP/2 is disabled. " + "Is alpn-boot on the boot class path?", null); return null; } return provider.unsupported ? null : provider.selected; } catch (InvocationTargetException | IllegalAccessException e) { throw assertionError("unable to get selected protocol", e); } }
public final <T> T wrap(Class<T> type, final T object) { return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return call(object,method,args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } })); } }
/** * Check whether the given object is a JDK dynamic proxy or a CGLIB proxy. * <p>This method additionally checks if the given object is an instance * of {@link SpringProxy}. * @param object the object to check * @see #isJdkDynamicProxy * @see #isCglibProxy */ public static boolean isAopProxy(@Nullable Object object) { return (object instanceof SpringProxy && (Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass()))); }
private boolean isProxyForSameBshObject(Object other) { if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler ih = Proxy.getInvocationHandler(other); return (ih instanceof BshObjectInvocationHandler && this.xt.equals(((BshObjectInvocationHandler) ih).xt)); } }
public void testToString() { List<String> proxy = newDelegatingList(LIST1); assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString()); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { List<Class<?>> loadedClasses = new ArrayList<Class<?>>(interfaces.length); for (String name : interfaces) { Class<?> clazz = Class.forName(name, false, classLoader); loadedClasses.add(clazz); } return Proxy.getProxyClass(classLoader, loadedClasses.toArray(new Class[loadedClasses.size()])); }
private static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) { Object object = Proxy.newProxyInstance( interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler); return interfaceType.cast(object); }
public boolean hasProxyTarget() { return (this.target != null && Proxy.isProxyClass(this.target.getType())); }
private boolean needsWrapping(Session session) { // try to make sure we don't wrap and already wrapped session if ( Proxy.isProxyClass( session.getClass() ) ) { final InvocationHandler invocationHandler = Proxy.getInvocationHandler( session ); if ( invocationHandler != null && TransactionProtectionWrapper.class.isInstance( invocationHandler ) ) { return false; } } return true; }
public static void stop( Object subprocess ) { ( (Handler) Proxy.getInvocationHandler( subprocess ) ).stop( null, 0 ); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { List<Class<?>> loadedClasses = new ArrayList<Class<?>>(interfaces.length); for (String name : interfaces) { Class<?> clazz = Class.forName(name, false, classLoader); loadedClasses.add(clazz); } return Proxy.getProxyClass(classLoader, loadedClasses.toArray(new Class[loadedClasses.size()])); }
/** * Returns a proxy instance that implements {@code interfaceType} by dispatching method * invocations to {@code handler}. The class loader of {@code interfaceType} will be used to * define the proxy class. To implement multiple interfaces or specify a class loader, use {@link * Proxy#newProxyInstance}. * * @throws IllegalArgumentException if {@code interfaceType} does not specify the type of a Java * interface */ public static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) { checkNotNull(handler); checkArgument(interfaceType.isInterface(), "%s is not an interface", interfaceType); Object object = Proxy.newProxyInstance( interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler); return interfaceType.cast(object); }
private static boolean isProxyOfSameInterfaces(Object arg, Class<?> proxyClass) { return proxyClass.isInstance(arg) // Equal proxy instances should mostly be instance of proxyClass // Under some edge cases (such as the proxy of JDK types serialized and then deserialized) // the proxy type may not be the same. // We first check isProxyClass() so that the common case of comparing with non-proxy objects // is efficient. || (Proxy.isProxyClass(arg.getClass()) && Arrays.equals(arg.getClass().getInterfaces(), proxyClass.getInterfaces())); } }
otherProxy = (JdkDynamicAopProxy) other; else if (Proxy.isProxyClass(other.getClass())) { InvocationHandler ih = Proxy.getInvocationHandler(other); if (!(ih instanceof JdkDynamicAopProxy)) { return false;