当前位置: 首页>>代码示例>>Java>>正文


Java InvocationContext.getMethod方法代码示例

本文整理汇总了Java中javax.interceptor.InvocationContext.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationContext.getMethod方法的具体用法?Java InvocationContext.getMethod怎么用?Java InvocationContext.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.interceptor.InvocationContext的用法示例。


在下文中一共展示了InvocationContext.getMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: accessAllowed

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object accessAllowed(InvocationContext ctx) throws Exception {
	Method businessAction = ctx.getMethod();
	Object managedBean = ctx.getTarget();
	boolean isAccessAllowed = false;

	try {

		ActionContext securityContext = new ActionContext(getUser(userModule));
		securityContext.setBusinessAction(businessAction);
		securityContext.setManagedBean(managedBean);

		isAccessAllowed = forumsACLProvider.hasAccess(securityContext);
		if (!isAccessAllowed)
			return null;
	} catch (NoSuchMethodException nsme) {
		throw new FacesException("Error calling action method of component with id " + nsme, nsme);
	} catch (Exception e) {
		throw new FacesException("Error calling action method of component with id " + e, e);
	}
	return ctx.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:23,代码来源:AuthorizationListener.java

示例2: wrap

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object wrap(InvocationContext ctx) throws Exception {
    // first, let's find where this is annotated:
    Method method = ctx.getMethod();
    Class<?> resourceClass = method.getDeclaringClass();

    boolean trace = true;
    if (resourceClass.isAnnotationPresent(Traced.class)) {
        trace = resourceClass.getAnnotation(Traced.class).value();
    }

    if (method.isAnnotationPresent(Traced.class)) {
        trace = method.getAnnotation(Traced.class).value();
    }

    if (trace) {
        return super.wrap(ctx);
    } else {
        return ctx.proceed();
    }
}
 
开发者ID:opentracing-contrib,项目名称:java-cdi,代码行数:22,代码来源:CdiOpenTracingInterceptor.java

示例3: invokeWithReporting

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object invokeWithReporting(InvocationContext ctx) throws Exception {
  SpanBuilder span = tracer.createSpan();
  try {
    return ctx.proceed();
  } catch (Exception e) {
    span.exception(e);
    throw e;
  } finally {
    Method method = ctx.getMethod();
    span
      .resource(method.getDeclaringClass().getSimpleName())
      .operation(method.getName())
      .type(getType(method));
    tracer.closeSpan(span);
  }
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:18,代码来源:TraceInterceptor.java

示例4: interceptLogging

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object interceptLogging(InvocationContext ctx) throws Exception {
	StringBuilder params = new StringBuilder();
	for(Object param: ctx.getParameters()) {
		params.append(param.toString()).append(",");
	}
	String signature = ctx.getClass() + "." + ctx.getMethod() + "(" + params.substring(0, params.length() -1) + ")";
	Date now1 = new Date(System.currentTimeMillis());
	SimpleDateFormat sdf = new SimpleDateFormat("hh.mm.ss dd.MM.yyyy");
	LOG.info(sdf.format(now1) +" - " + signature);
	Object o = null; 
	try{
		o = ctx.getMethod().invoke(ctx.getTarget(), ctx.getParameters());
	} catch(Exception e) {
		LOG.error(signature, e);
		throw new BusinessException(signature, e);
	} finally {
		Date now2 = new Date(System.currentTimeMillis());
		LOG.info(sdf.format(now2) +" - " + signature);
	}
	return o;
}
 
开发者ID:Angular2Guy,项目名称:Angular2AndJavaEE,代码行数:23,代码来源:LoggingInterceptor.java

示例5: Log

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object Log(InvocationContext context) throws Exception {
    Method method = context.getMethod();
    String clazz = method.getDeclaringClass().getName();
    String mthd = clazz + ":" + method.getName();
    String parms = Arrays.toString(context.getParameters());

    try {
        Object result = context.proceed();
        System.out.println("Call to " + mthd + "(" + parms + ") returned " + result);
        return result;
    } catch (Exception e) {
        System.out.println("Call to " + mthd + "(" + parms + ") threw " + e.toString());
        throw e;
    }
}
 
开发者ID:eclipse,项目名称:microprofile-conference,代码行数:17,代码来源:Logger.java

示例6: logMyCall

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
	public Object logMyCall(InvocationContext context) throws Exception {
		
		// you can get the called method 
		Method method = context.getMethod();
		
		// and the class of that method, of course
		Class<?> clazz = method.getDeclaringClass();
		
		// you can get the parameters
		Object[] params = context.getParameters();
		//you can set (!) the parameters....
//		context.setParameters(...);
		
		// you can get the target class (the instance of clazz on which the method was called)
//		context.getTarget();

		
		// do what you need 
		System.out.println("called " + method.getName() + " on class " + clazz+ " params="+listParams(params));
		
		// invoke the method or let the next interceptor do its work
		return context.proceed();
	}
 
开发者ID:notsojug,项目名称:jug-material,代码行数:25,代码来源:LoggedInterceptor.java

示例7: logMethodCall

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object logMethodCall(InvocationContext invocationContext) throws Exception {
    Object interceptedObject = invocationContext.getTarget();
    Method interceptedMethod = invocationContext.getMethod();

    System.out.println("Entering "
            + interceptedObject.getClass().getName() + "."
            + interceptedMethod.getName() + "()");

    Object o = invocationContext.proceed();

    System.out.println("Leaving  "
            + interceptedObject.getClass().getName() + "."
            + interceptedMethod.getName() + "()");

    return o;
}
 
开发者ID:PacktPublishing,项目名称:Java-EE-7-Development-with-NetBeans-8,代码行数:18,代码来源:LoggingInterceptor.java

示例8: dbStoreInterceptor

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object dbStoreInterceptor(InvocationContext ctx) throws Exception {
    Object result = ctx.proceed();
    Method method = ctx.getMethod();
    final Object target = ctx.getTarget();
        
    try {
        final DBStore dbStoreAnnotation = method.getAnnotation(DBStore.class);
        
        DBStoreAdapter.dBStoreAdapter(dbStoreAnnotation, target, null, method, metricFields);
    } catch(Exception e) {
        e.printStackTrace();
    }
    
    return result;
}
 
开发者ID:panossot,项目名称:jam-metrics,代码行数:17,代码来源:DBStoreInterceptor.java

示例9: dbStoreSyncInterceptor

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object dbStoreSyncInterceptor(InvocationContext ctx) throws Exception {
    Object result = ctx.proceed();
    Method method = ctx.getMethod();
    final Object target = ctx.getTarget();
        
    try {
        DBStore dbStoreAnnotation = method.getAnnotation(DBStore.class);
        
        DBStoreSyncAdapter.dBStoreSyncAdapter(dbStoreAnnotation, target, null, method, metricFields);
        
    } catch(Exception e) {
        e.printStackTrace();
    }
    
    return result;
}
 
开发者ID:panossot,项目名称:jam-metrics,代码行数:18,代码来源:DBStoreSyncInterceptor.java

示例10: hawkularApmInterceptor

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object hawkularApmInterceptor(InvocationContext ctx) throws Exception {
    Method method = ctx.getMethod();

    try {
        final HawkularApm hawkularApmAnnotation = method.getAnnotation(HawkularApm.class);

        if (hawkularApmAnnotation != null) {
            HawkularApmAdapter.hawkularApmAdapter(hawkularApmAnnotation, method);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    Object result = ctx.proceed();

    return result;
}
 
开发者ID:panossot,项目名称:jam-metrics,代码行数:20,代码来源:HawkularApmInterceptor.java

示例11: metricFilterInterceptor

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object metricFilterInterceptor(InvocationContext ctx) throws Exception {
    Object result = ctx.proceed();
    Method method = ctx.getMethod();
    final Object target = ctx.getTarget();
        
    try {
        final MetricFilter metricFilterAnnotation = method.getAnnotation(MetricFilter.class);
        
        MetricFilterAdapter.metricFilterAdapter(metricFilterAnnotation, target, null, method, metricFields);

    } catch(Exception e) {
        e.printStackTrace();
    }
    
    return result;
}
 
开发者ID:panossot,项目名称:jam-metrics,代码行数:18,代码来源:MetricFilterInterceptor.java

示例12: intercept

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
    final Method method = ctx.getMethod();
    if ("onMessage".equals(method.getName())
            && method.getParameterCount() == 1
            && method.getParameterTypes()[0] == Message.class) {
        final ObjectMessage message = (ObjectMessage) ctx.getParameters()[0];
        final SecureObjectMessage secureMessage = (SecureObjectMessage) message.getObject();

        final Principal principal = secureMessage.getPrincipal();
        final Subject subject = secureMessage.getSubject();
        final Object credential = secureMessage.getCredential();

        if (principal != null && subject != null) {
            SecurityActions.setSubjectInfo(principal, subject, credential);
        }

        final ObjectMessage proxiedMessage = (ObjectMessage) Proxy.newProxyInstance(
                ObjectMessage.class.getClassLoader(),
                new Class[]{ObjectMessage.class},
                new ObjectMessageProxy(message));
        ctx.setParameters(new Object[]{proxiedMessage});
    }

    return ctx.proceed();
}
 
开发者ID:panga,项目名称:jboss-security-extended,代码行数:27,代码来源:JmsSecurityInterceptor.java

示例13: interceptRolesAllowed

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object interceptRolesAllowed(InvocationContext context) throws Exception {
    final Class<?> targetClass = context.getTarget().getClass();
    final Method method = context.getMethod();

    // Build roles allowed
    Set<String> rolesAllowed = new HashSet<>();

    addRolesAllowed(method, rolesAllowed);
    recursiveAddClassAndInterfaceRolesAllowed(targetClass, method, rolesAllowed, new HashSet<Class<?>>());

    // Now we have all allowed roles, we must check if we have at least one common role
    securityService.checkRolesAllowed(rolesAllowed);

    return context.proceed();
}
 
开发者ID:iorga-group,项目名称:ivif,代码行数:17,代码来源:RolesAllowedInterceptor.java

示例14: grant

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object grant(InvocationContext ctx) throws Exception { 
    Method method = ctx.getMethod();
    Class<?> type = method.getDeclaringClass();
    Grant resource = getResource(type);
    Grant action = getAction(resource, method);
    
    Boolean state = guardian.checkState(resource.name(), action.name());
    if (!Boolean.TRUE.equals(state)) return null;
    
    if (!action.check()) return ctx.proceed(); 
    authorise(session.getUsername(), resource.name(), action.name());
    
    filterMethodParameters(ctx, session.getUsername());
    
    Object result = relayUser(ctx, resource, action);
    if (action.filter() && result != null) result = filter(session.getUsername(), null, result);
    return result;
}
 
开发者ID:3venthorizon,项目名称:guardian,代码行数:20,代码来源:GuardInterceptor.java

示例15: filterMethodParameters

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
void filterMethodParameters(InvocationContext ctx, String username) {
    Object[] parameters = ctx.getParameters();
    if (parameters == null || parameters.length < 1) return;
    
    Method method = ctx.getMethod();
    boolean filtered = filterParameters(username, method, parameters);

    if (filtered) return;
    
    for (Class<?> iclass : method.getDeclaringClass().getInterfaces()) {
        try {
            Method imethod = iclass.getDeclaredMethod(method.getName(), method.getParameterTypes());
            filtered = filterParameters(username, imethod, parameters);
            if (filtered) return;
        } catch (NoSuchMethodException e) { }
    }
}
 
开发者ID:3venthorizon,项目名称:guardian,代码行数:18,代码来源:GuardInterceptor.java


注:本文中的javax.interceptor.InvocationContext.getMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。