當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInvocation類代碼示例

本文整理匯總了Java中org.aopalliance.intercept.MethodInvocation的典型用法代碼示例。如果您正苦於以下問題:Java MethodInvocation類的具體用法?Java MethodInvocation怎麽用?Java MethodInvocation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MethodInvocation類屬於org.aopalliance.intercept包,在下文中一共展示了MethodInvocation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {

	System.out.println("Method name : "
			+ methodInvocation.getMethod().getName());

	// same with MethodBeforeAdvice
	System.out.println("InsertAroundMethod : Before method inserted!");

	try {
		// proceed to original method call
		Object result = methodInvocation.proceed();

		// same with AfterReturningAdvice
		System.out.println("InsertAroundMethod : after method inserted!");

		return result;

	} catch (IllegalArgumentException e) {
		// same with ThrowsAdvice
		System.out
				.println("InsertAroundMethod : Throw exception inserted!");
		throw e;
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:26,代碼來源:InsertAroundMethod.java

示例2: getDisposalLockProxy

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * Apply a lock (preferably a read lock allowing multiple concurrent access) to the bean. Callers should replace the
 * bean input with the output.
 *
 * @param bean the bean to lock
 * @param lock the lock to apply
 * @return a proxy that locks while its methods are executed
 */
private Object getDisposalLockProxy(Object bean, final Lock lock) {
    ProxyFactory factory = new ProxyFactory(bean);
    factory.setProxyTargetClass(proxyTargetClass);
    factory.addAdvice(new MethodInterceptor() {
        public Object invoke(MethodInvocation invocation) throws Throwable {
            lock.lock();
            try {
                return invocation.proceed();
            } finally {
                lock.unlock();
            }
        }
    });
    return factory.getProxy();
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:24,代碼來源:StandardBeanLifecycleDecorator.java

示例3: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  Service service = getService(invocation);
  RequestHeader requestHeader = getRequestHeader(invocation);

  try {
    // For each service method invocation verify that user is authenticated!
    //noinspection unchecked
    accessController.validate(requestHeader.getCredentials());
  } catch (InvalidCredentialsException ex) {
    throw new AuthenticationFailedException("Could not authenticate user: " + ex.getMessage());
  }

  if (SecurityContext.isSet()) {
    return invocation.proceed();
  }

  try (SecurityContext ignored = SecurityContext.set(service.createSecurityContext(requestHeader.getCredentials()))) {
    return invocation.proceed();
  }
}
 
開發者ID:mnemonic-no,項目名稱:act-platform,代碼行數:22,代碼來源:AuthenticationAspect.java

示例4: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * Subclasses may need to override this if they want to perform custom
 * behaviour in around advice. However, subclasses should invoke this
 * method, which handles introduced interfaces and forwarding to the target.
 */
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (isMethodOnIntroducedInterface(mi)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());

		// Using the following method rather than direct reflection,
		// we get correct handling of InvocationTargetException
		// if the introduced method throws an exception.
		Object retVal = AopUtils.invokeJoinpointUsingReflection(delegate, mi.getMethod(), mi.getArguments());

		// Massage return value if possible: if the delegate returned itself,
		// we really want to return the proxy.
		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:DelegatePerTargetObjectIntroductionInterceptor.java

示例5: validateMethodParameters

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
private void validateMethodParameters(MethodInvocation invocation) throws InvalidArgumentException {
  boolean isInvalid = false;
  InvalidArgumentException ex = new InvalidArgumentException();

  for (int i = 0; i < invocation.getMethod().getParameterCount(); i++) {
    Parameter parameter = invocation.getMethod().getParameters()[i];
    // Only validate arguments which implement ValidatingRequest.
    if (ValidatingRequest.class.isAssignableFrom(parameter.getType())) {
      ValidatingRequest request = (ValidatingRequest) invocation.getArguments()[i];
      if (request == null) {
        // Don't allow null request objects.
        ex.addValidationError(InvalidArgumentException.ErrorMessage.NULL, parameter.getName(), "NULL");
        isInvalid = true;
      } else {
        isInvalid |= validateRequest(request, ex);
      }
    }
  }

  if (isInvalid) {
    // If violations exist abort invoked service call.
    throw ex;
  }
}
 
開發者ID:mnemonic-no,項目名稱:act-platform,代碼行數:25,代碼來源:ValidationAspect.java

示例6: getBeanNameImpl

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * Do the look up by interface type.
 * 
 * @return              Returns the name of the service or <tt>null</tt> if not found
 */
private String getBeanNameImpl(MethodInvocation mi) throws BeansException
{
    if (mi instanceof ProxyMethodInvocation)
    {
        Object proxy = ((ProxyMethodInvocation) mi).getProxy();
        Map beans = beanFactory.getBeansOfType(proxy.getClass());
        Iterator iter = beans.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry entry = (Map.Entry) iter.next();
            String name = (String) entry.getKey();
            if (proxy == entry.getValue() && !name.equals("DescriptorService"))
            {
                return name;
            }
        }
    }
    return null;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:BeanIdentifierImpl.java

示例7: runAsSystem

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
private Object runAsSystem(MethodInvocation invocation) throws Throwable
{
    Object ret = null;

    // We're creating in enhanced mode and have a matching filename or path. Switch to
    // the system user to do the operation.

    AuthenticationUtil.pushAuthentication();
    try
    {
        AuthenticationUtil.setRunAsUserSystem();
        ret = invocation.proceed();
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
    
    return ret;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:21,代碼來源:FilenameFilteringInterceptor.java

示例8: SubsystemProxyFactory

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * Instantiates a new managed subsystem proxy factory.
 */
public SubsystemProxyFactory()
{
    addAdvisor(new DefaultPointcutAdvisor(new MethodInterceptor()
    {
        public Object invoke(MethodInvocation mi) throws Throwable
        {
            Method method = mi.getMethod();
            try
            {
                return method.invoke(locateBean(mi), mi.getArguments());
            }
            catch (InvocationTargetException e)
            {
                // Unwrap invocation target exceptions
                throw e.getTargetException();
            }
        }
    }));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:23,代碼來源:SubsystemProxyFactory.java

示例9: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
public Object invoke(MethodInvocation mi) throws Throwable
{
    Class<?>[] parameterTypes = mi.getMethod().getParameterTypes();
    Object[] arguments = mi.getArguments();
    for (int i = 0; i < parameterTypes.length; i++)
    {
        if (arguments[i] instanceof ContentStreamImpl)
        {
        	ContentStreamImpl contentStream = (ContentStreamImpl) arguments[i];
            if (contentStream != null)
            {
                // ALF-18006
                if (contentStream.getMimeType() == null)
                {
                	InputStream stream = contentStream.getStream();
                    String mimeType = mimetypeService.guessMimetype(contentStream.getFileName(), stream);
                    contentStream.setMimeType(mimeType);
                }
            }
        }
    }
    return mi.proceed();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:24,代碼來源:AlfrescoCmisStreamInterceptor.java

示例10: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    //
    Method m = invocation.getMethod();

    if (m.isAnnotationPresent(Conditioned.class)) {
        Object[] arg = invocation.getArguments();
        if (arg.length > 0 && arg[arg.length - 1] instanceof List && !((List) arg[arg.length - 1]).isEmpty() && ((List) arg[arg.length - 1]).get(0) instanceof GherkinStepCondition) {
            List<GherkinStepCondition> conditions = (List) arg[arg.length - 1];
            displayMessageAtTheBeginningOfMethod(m.getName(), conditions);
            if (!checkConditions(conditions)) {
                Context.getCurrentScenario().write(Messages.getMessage(SKIPPED_DUE_TO_CONDITIONS));
                return Void.TYPE;
            }
        }
    }

    logger.debug("NORAUI ConditionedInterceptor invoke method {}", invocation.getMethod());
    return invocation.proceed();
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:24,代碼來源:ConditionedInterceptor.java

示例11: handle

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
public void handle(Throwable exception, MethodInvocation invocation) {
	HttpServletRequest request=DoradoContext.getCurrent().getRequest();
	String contextPath=request.getContextPath();
	StringBuffer sb=new StringBuffer();
	NoneLoginException ex=(NoneLoginException)exception;
	if(ex.isSessionKickAway()){
		sb.append("dorado.MessageBox.alert(\""+Configure.getString("bdf2.ajaxSessionKickAwayMessage")+"\",function(){\n");
		sb.append("window.open(\""+contextPath+Configure.getString("bdf2.formLoginUrl")+"\",\"_top\");\n");
		sb.append("})");			
	}else{
		sb.append("dorado.MessageBox.alert(\""+Configure.getString("bdf2.ajaxSessionExpireMessage")+"\",function(){\n");
		sb.append("window.open(\""+contextPath+Configure.getString("bdf2.formLoginUrl")+"\",\"_top\");\n");
		sb.append("})");			
	}
       throw new ClientRunnableException(sb.toString());
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:17,代碼來源:NoneLoginAjaxExceptionHandler.java

示例12: canCurrentUserAccessView

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * @param viewClass
 * @return true si l'utilisateur peut accéder à la vue
 */
public boolean canCurrentUserAccessView(Class<? extends View> viewClass, Authentication auth) {
	if (auth == null) {
		return false;
	}
	MethodInvocation methodInvocation = MethodInvocationUtils.createFromClass(viewClass, "enter");
	Collection<ConfigAttribute> configAttributes = methodSecurityInterceptor.obtainSecurityMetadataSource()
			.getAttributes(methodInvocation);
	/* Renvoie true si la vue n'est pas sécurisée */
	if (configAttributes.isEmpty()) {
		return true;
	}
	/* Vérifie que l'utilisateur a les droits requis */
	try {
		methodSecurityInterceptor.getAccessDecisionManager().decide(auth, methodInvocation, configAttributes);
	} catch (InsufficientAuthenticationException | AccessDeniedException e) {
		return false;
	}
	return true;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:24,代碼來源:UserController.java

示例13: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  final Message message = getMessageArgument(invocation.getArguments());
  if (message == null) {
    throw new IllegalStateException("Message cannot be null");
  }
  before(message);
  return invocation.proceed();
}
 
開發者ID:netshoes,項目名稱:spring-cloud-sleuth-amqp,代碼行數:10,代碼來源:AmqpMessagingBeforeReceiveInterceptor.java

示例14: invoke

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	try {
		return mi.proceed();
	}
	catch (RuntimeException ex) {
		// Let it throw raw if the type of the exception is on the throws clause of the method.
		if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
			throw ex;
		}
		else {
			if (this.persistenceExceptionTranslator == null) {
				this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(this.beanFactory);
			}
			throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:PersistenceExceptionTranslationInterceptor.java

示例15: handleConnectFailure

import org.aopalliance.intercept.MethodInvocation; //導入依賴的package包/類
/**
 * Refresh the connection and retry the MBean invocation if possible.
 * <p>If not configured to refresh on connect failure, this method
 * simply rethrows the original exception.
 * @param invocation the invocation that failed
 * @param ex the exception raised on remote invocation
 * @return the result value of the new invocation, if succeeded
 * @throws Throwable an exception raised by the new invocation,
 * if it failed as well
 * @see #setRefreshOnConnectFailure
 * @see #doInvoke
 */
protected Object handleConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable {
	if (this.refreshOnConnectFailure) {
		String msg = "Could not connect to JMX server - retrying";
		if (logger.isDebugEnabled()) {
			logger.warn(msg, ex);
		}
		else if (logger.isWarnEnabled()) {
			logger.warn(msg);
		}
		prepare();
		return doInvoke(invocation);
	}
	else {
		throw ex;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:MBeanClientInterceptor.java


注:本文中的org.aopalliance.intercept.MethodInvocation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。