當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。