Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInvocation


    }

    @Test
    public void declinesAccessUsingCreate() throws Exception {
        Object object = new TargetObject();
        final MethodInvocation mi = MethodInvocationUtils.create(object, "makeLowerCase", "foobar");
        MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
        mipe.setSecurityInterceptor(interceptor);
        when(mds.getAttributes(mi)).thenReturn(role);
        doThrow(new AccessDeniedException("rejected")).when(adm).decide(token, mi, role);
View Full Code Here


        assertFalse(mipe.isAllowed(mi, token));
    }

    @Test
    public void declinesAccessUsingCreateFromClass() throws Exception {
        final MethodInvocation mi = MethodInvocationUtils.createFromClass(new OtherTargetObject(), ITargetObject.class, "makeLowerCase",
                new Class[] {String.class}, new Object[] {"helloWorld"});

        MethodInvocationPrivilegeEvaluator mipe = new MethodInvocationPrivilegeEvaluator();
        mipe.setSecurityInterceptor(interceptor);
        when(mds.getAttributes(mi)).thenReturn(role);
View Full Code Here

        advisedTarget.makeUpperCase("hello");
    }

    @Test
    public void afterInvocationManagerIsNotInvokedIfExceptionIsRaised() throws Throwable {
        MethodInvocation mi = mock(MethodInvocation.class);
        token.setAuthenticated(true);
        SecurityContextHolder.getContext().setAuthentication(token);
        mdsReturnsUserRole();

        AfterInvocationManager aim = mock(AfterInvocationManager.class);
        interceptor.setAfterInvocationManager(aim);

        when(mi.proceed()).thenThrow(new Throwable());

        try {
            interceptor.invoke(mi);
            fail("Expected exception");
        } catch (Throwable expected) {
View Full Code Here

    }

    @Test
    public void expectedDomainObjectArgumentIsReturnedFromMethodInvocation() throws Exception {
        voter.setProcessDomainObjectClass(String.class);
        MethodInvocation mi = MethodInvocationUtils.create(new TestClass(), "methodTakingAString", "The Argument");
        assertEquals("The Argument", voter.getDomainObjectInstance(mi));
    }
View Full Code Here

    }

    @Test
    public void correctArgumentIsSelectedFromMultipleArgs() throws Exception {
        voter.setProcessDomainObjectClass(String.class);
        MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
                "methodTakingAListAndAString", new ArrayList<Object>(), "The Argument");
        assertEquals("The Argument", voter.getDomainObjectInstance(mi));
    }
View Full Code Here

   * Implementation of <code>InvocationHandler.invoke</code>.
   * <p>Callers will see exactly the exception thrown by the target,
   * unless a hook method throws an exception.
   */
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInvocation invocation = null;
    Object oldProxy = null;
    boolean setProxyContext = false;

    TargetSource targetSource = this.advised.targetSource;
    Class targetClass = null;
    Object target = null;

    try {
      if (!this.equalsDefined && AopUtils.isEqualsMethod(method)) {
        // The target does not implement the equals(Object) method itself.
        return (equals(args[0]) ? Boolean.TRUE : Boolean.FALSE);
      }
      if (!this.hashCodeDefined && AopUtils.isHashCodeMethod(method)) {
        // The target does not implement the hashCode() method itself.
        return new Integer(hashCode());
      }
      if (!this.advised.opaque && method.getDeclaringClass().isInterface() &&
          method.getDeclaringClass().isAssignableFrom(Advised.class)) {
        // Service invocations on ProxyConfig with the proxy config...
        return AopUtils.invokeJoinpointUsingReflection(this.advised, method, args);
      }

      Object retVal = null;

      if (this.advised.exposeProxy) {
        // Make invocation available if necessary.
        oldProxy = AopContext.setCurrentProxy(proxy);
        setProxyContext = true;
      }

      // May be <code>null</code>. Get as late as possible to minimize the time we "own" the target,
      // in case it comes from a pool.
      target = targetSource.getTarget();
      if (target != null) {
        targetClass = target.getClass();
      }

      // Get the interception chain for this method.
      List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);

      // Check whether we have any advice. If we don't, we can fallback on direct
      // reflective invocation of the target, and avoid creating a MethodInvocation.
      if (chain.isEmpty()) {
        // We can skip creating a MethodInvocation: just invoke the target directly
        // Note that the final invoker must be an InvokerInterceptor so we know it does
        // nothing but a reflective operation on the target, and no hot swapping or fancy proxying.
        retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args);
      }
      else {
        // We need to create a method invocation...
        invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
        // Proceed to the joinpoint through the interceptor chain.
        retVal = invocation.proceed();
      }

      // Massage return value if necessary.
      if (retVal != null && retVal == target && method.getReturnType().isInstance(proxy) &&
          !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
View Full Code Here

   * (in an around advice).
   * @return current AspectJ joinpoint, or through an exception if we're not in a
   * Spring AOP invocation.
   */
  public static JoinPoint currentJoinPoint() {
    MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
    if (!(mi instanceof ProxyMethodInvocation)) {
      throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
    }
    ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
    JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY);
View Full Code Here

    // consistent with return of MethodInvocationProceedingJoinPoint
    ProxyMethodInvocation pmi = null;
    Object targetObject = null;
    Object thisObject = null;
    try {
      MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
      targetObject = mi.getThis();
      if (!(mi instanceof ProxyMethodInvocation)) {
        throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
      }
      pmi = (ProxyMethodInvocation) mi;
      thisObject = pmi.getProxy();
View Full Code Here

  /**
   * Get the current join point match at the join point we are being dispatched on.
   */
  protected JoinPointMatch getJoinPointMatch() {
    MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
    if (!(mi instanceof ProxyMethodInvocation)) {
      throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
    }
    return getJoinPointMatch((ProxyMethodInvocation) mi);
  }
View Full Code Here

   * @return the invocation object associated with the current invocation
   * @throws IllegalStateException if there is no AOP invocation in progress,
   * or if the ExposeInvocationInterceptor was not added to this interceptor chain
   */
  public static MethodInvocation currentInvocation() throws IllegalStateException {
    MethodInvocation mi = (MethodInvocation) invocation.get();
    if (mi == null)
      throw new IllegalStateException(
          "No MethodInvocation found: Check that an AOP invocation is in progress, " +
          "and that the ExposeInvocationInterceptor is in the interceptor chain.");
    return mi;
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInvocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.