@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;
}
}
java类org.aopalliance.intercept.MethodInvocation的实例源码
InsertAroundMethod.java 文件源码
项目:SpringTutorial
阅读 19
收藏 0
点赞 0
评论 0
StandardBeanLifecycleDecorator.java 文件源码
项目:configx
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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();
}
AuthenticationAspect.java 文件源码
项目:act-platform
阅读 19
收藏 0
点赞 0
评论 0
@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();
}
}
DelegatePerTargetObjectIntroductionInterceptor.java 文件源码
项目:lams
阅读 17
收藏 0
点赞 0
评论 0
/**
* 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);
}
ValidationAspect.java 文件源码
项目:act-platform
阅读 22
收藏 0
点赞 0
评论 0
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;
}
}
BeanIdentifierImpl.java 文件源码
项目:alfresco-repository
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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;
}
FilenameFilteringInterceptor.java 文件源码
项目:alfresco-repository
阅读 16
收藏 0
点赞 0
评论 0
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;
}
SubsystemProxyFactory.java 文件源码
项目:alfresco-repository
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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();
}
}
}));
}
AlfrescoCmisStreamInterceptor.java 文件源码
项目:alfresco-repository
阅读 18
收藏 0
点赞 0
评论 0
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();
}
ConditionedInterceptor.java 文件源码
项目:NoraUi
阅读 18
收藏 0
点赞 0
评论 0
/**
* {@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();
}
NoneLoginAjaxExceptionHandler.java 文件源码
项目:bdf2
阅读 16
收藏 0
点赞 0
评论 0
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());
}
UserController.java 文件源码
项目:esup-ecandidat
阅读 24
收藏 0
点赞 0
评论 0
/**
* @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;
}
AmqpMessagingBeforeReceiveInterceptor.java 文件源码
项目:spring-cloud-sleuth-amqp
阅读 22
收藏 0
点赞 0
评论 0
@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();
}
PersistenceExceptionTranslationInterceptor.java 文件源码
项目:lams
阅读 20
收藏 0
点赞 0
评论 0
@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);
}
}
}
MBeanClientInterceptor.java 文件源码
项目:lams
阅读 31
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
OsgiServiceStaticInterceptorTest.java 文件源码
项目:gemini.blueprint
阅读 18
收藏 0
点赞 0
评论 0
public void testInvocationWhenServiceNA() throws Throwable {
// service n/a
ServiceReference reference = new MockServiceReference() {
public Bundle getBundle() {
return null;
}
};
interceptor = new ServiceStaticInterceptor(new MockBundleContext(), reference);
Object target = new Object();
Method m = target.getClass().getDeclaredMethod("hashCode", null);
MethodInvocation invocation = new MockMethodInvocation(m);
try {
interceptor.invoke(invocation);
fail("should have thrown exception");
}
catch (ServiceUnavailableException ex) {
// expected
}
}
MethodSecurityInteceptor.java 文件源码
项目:Equella
阅读 21
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
private Object filterResult(MethodInvocation invocation, final SecurityAttribute secAttr) throws Throwable // NOSONAR
{
Object returnedObject = invocation.proceed();
if( returnedObject == null )
{
return null;
}
if( returnedObject instanceof Collection )
{
return filterCollection(secAttr, (Collection<Object>) returnedObject);
}
else if( returnedObject instanceof Map )
{
return filterMap(secAttr, (Map<Object, Object>) returnedObject);
}
else
{
checkSingleObject(secAttr.getFilterPrivileges(), returnedObject);
return returnedObject;
}
}
MethodValidationInterceptor.java 文件源码
项目:lams
阅读 21
收藏 0
点赞 0
评论 0
@SuppressWarnings("deprecation")
public static Object invokeWithinValidation(MethodInvocation invocation, Validator validator, Class<?>[] groups)
throws Throwable {
org.hibernate.validator.method.MethodValidator methodValidator = validator.unwrap(org.hibernate.validator.method.MethodValidator.class);
Set<org.hibernate.validator.method.MethodConstraintViolation<Object>> result = methodValidator.validateAllParameters(
invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
if (!result.isEmpty()) {
throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
}
Object returnValue = invocation.proceed();
result = methodValidator.validateReturnValue(
invocation.getThis(), invocation.getMethod(), returnValue, groups);
if (!result.isEmpty()) {
throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
}
return returnValue;
}
DataSourceSpyInterceptor.java 文件源码
项目:dswork
阅读 17
收藏 0
点赞 0
评论 0
public Object invoke(MethodInvocation invocation) throws Throwable
{
Object result = invocation.proceed();
if(SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled())
{
if(result instanceof Connection)
{
Connection conn = (Connection) result;
return new ConnectionSpy(conn, getRdbmsSpecifics(conn));
}
}
return result;
}
SecurityDialectPostProcessor.java 文件源码
项目:Learning-Spring-Boot-2.0-Second-Edition
阅读 16
收藏 0
点赞 0
评论 0
@Override
public Object postProcessBeforeInitialization(
Object bean, String beanName) throws BeansException {
if (bean instanceof SpringTemplateEngine) {
SpringTemplateEngine engine =
(SpringTemplateEngine) bean;
SecurityExpressionHandler<MethodInvocation> handler =
applicationContext.getBean(
SecurityExpressionHandler.class);
SecurityDialect dialect = new SecurityDialect(handler);
engine.addDialect(dialect);
}
return bean;
}
AspectJAfterThrowingAdvice.java 文件源码
项目:lams
阅读 17
收藏 0
点赞 0
评论 0
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
try {
return mi.proceed();
}
catch (Throwable t) {
if (shouldInvokeOnThrowing(t)) {
invokeAdviceMethod(getJoinPointMatch(), null, t);
}
throw t;
}
}
UniTimeSecurityExpressionHandler.java 文件源码
项目:unitimes
阅读 17
收藏 0
点赞 0
评论 0
@Override
protected MethodSecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, MethodInvocation invocation) {
MyMethodSecurityExpressionRoot root = new MyMethodSecurityExpressionRoot(authentication);
root.setThis(invocation.getThis());
root.setPermissionEvaluator(getPermissionEvaluator());
return root;
}
OAuth2SsoCustomConfiguration.java 文件源码
项目:spring-security-oauth2-boot
阅读 22
收藏 0
点赞 0
评论 0
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
if (invocation.getMethod().getName().equals("init")) {
Method method = ReflectionUtils
.findMethod(WebSecurityConfigurerAdapter.class, "getHttp");
ReflectionUtils.makeAccessible(method);
HttpSecurity http = (HttpSecurity) ReflectionUtils.invokeMethod(method,
invocation.getThis());
this.configurer.configure(http);
}
return invocation.proceed();
}
MethodUnitOfWorkInterceptor.java 文件源码
项目:hiatus-spring-boot
阅读 18
收藏 0
点赞 0
评论 0
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
counter.increase();
try {
return invocation.proceed();
} finally {
counter.decrease();
}
}
JamonPerformanceMonitorInterceptor.java 文件源码
项目:lams
阅读 19
收藏 0
点赞 0
评论 0
/**
* Wraps the invocation with a JAMon Monitor and writes the current
* performance statistics to the log (if enabled).
* @see com.jamonapi.MonitorFactory#start
* @see com.jamonapi.Monitor#stop
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
Monitor monitor = MonitorFactory.start(name);
try {
return invocation.proceed();
}
finally {
monitor.stop();
if (!this.trackAllInvocations || isLogEnabled(logger)) {
logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
}
}
}
DataSourceSwitchMethodInterceptor.java 文件源码
项目:spring-boot-mybatisplus-multiple-datasource
阅读 19
收藏 0
点赞 0
评论 0
@Override
public Object invoke ( MethodInvocation invocation ) throws Throwable {
final String packageName = invocation.getThis().getClass().getPackage().getName();
if ( packageName.contains( "user" ) ) {
setDataSourceKey( invocation.getMethod() , GlobalConstant.USER_DATA_SOURCE_KEY );
}
if ( packageName.contains( "order" ) ) {
setDataSourceKey( invocation.getMethod() , GlobalConstant.ORDER_DATA_SOURCE_KEY );
}
return invocation.proceed();
}
AspectJAroundAdvice.java 文件源码
项目:lams
阅读 15
收藏 0
点赞 0
评论 0
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
if (!(mi instanceof ProxyMethodInvocation)) {
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
}
ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
JoinPointMatch jpm = getJoinPointMatch(pmi);
return invokeAdviceMethod(pjp, jpm, null, null);
}
AbstractAspectJAdvice.java 文件源码
项目:lams
阅读 26
收藏 0
点赞 0
评论 0
/**
* Lazily instantiate joinpoint for the current invocation.
* Requires MethodInvocation to be bound with ExposeInvocationInterceptor.
* <p>Do not use if access is available to the current ReflectiveMethodInvocation
* (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);
if (jp == null) {
jp = new MethodInvocationProceedingJoinPoint(pmi);
pmi.setUserAttribute(JOIN_POINT_KEY, jp);
}
return jp;
}
JooqTxnInterceptor.java 文件源码
项目:beadledom
阅读 15
收藏 0
点赞 0
评论 0
/**
* Invokes the method wrapped within a unit of work and a transaction.
*
* @param methodInvocation the method to be invoked within a transaction
* @return the result of the call to the invoked method
* @throws Throwable if an exception occurs during the method invocation, transaction, or unit of
* work
*/
private Object invokeInTransactionAndUnitOfWork(MethodInvocation methodInvocation)
throws Throwable {
boolean unitOfWorkAlreadyStarted = unitOfWork.isActive();
if (!unitOfWorkAlreadyStarted) {
unitOfWork.begin();
}
Throwable originalThrowable = null;
try {
return dslContextProvider.get().transactionResult(() -> {
try {
return methodInvocation.proceed();
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
}
});
} catch (Throwable t) {
originalThrowable = t;
throw t;
} finally {
if (!unitOfWorkAlreadyStarted) {
endUnitOfWork(originalThrowable);
}
}
}
ExposeBeanNameAdvisors.java 文件源码
项目:lams
阅读 18
收藏 0
点赞 0
评论 0
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
if (!(mi instanceof ProxyMethodInvocation)) {
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
}
ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
return mi.proceed();
}