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


Java InvocationContext类代码示例

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


InvocationContext类属于javax.interceptor包,在下文中一共展示了InvocationContext类的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: aroundInvoke

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
	String methodName = ic.getMethod().getName();
	logger.info("Executing " + ic.getTarget().getClass().getSimpleName() + "." + methodName + " method");
	Object[] parameters = (Object[]) ic.getParameters();
	logger.info("parameters are: " + parameters.length);
	if (parameters.length == 1) {
		Item item = (Item) parameters[0];
		logger.info("item: " + item.getName());
	}
	Map<String, Object> contextData = ic.getContextData();
	if (!contextData.isEmpty())
		getItemHistory().add(contextData.get("test_trace") + "");
	return ic.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:16,代码来源:IncludedInterceptor.java

示例3: aroundInvoke

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
	String methodName = ic.getMethod().getName();
	logger.info("Executing " + ic.getTarget().getClass().getSimpleName() + "." + methodName + " method");
	Object[] parameters = (Object[]) ic.getParameters();
	logger.info("parameters are: " + parameters.length);
	if (parameters.length == 1) {
		Item item = (Item) parameters[0];
		logger.info("item: " + item.getName());
	}
	Map<String, Object> contextData = ic.getContextData();
	if (contextData.isEmpty())
		contextData.put("test_trace", "test_trace");
	return ic.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:16,代码来源:ExcludedInterceptor.java

示例4: 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

示例5: guard

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object guard(InvocationContext context) throws Exception {
    Object target = context.getTarget();
    AtomicInteger counter = admin.getCounter(target);
    try {
        int failureCount = counter.get();
        if (failureCount >= this.maxExceptionsThreashold) {
            String methodName = context.getMethod().toString();
            this.unstableServiceEvent.fire(new SubsequentInvocationsFailure(methodName, failureCount));
            throw new UnstableExternalServiceException(methodName);
        }
        return context.proceed();
    } catch (Exception ex) {
        counter.incrementAndGet();
        throw ex;
    }
}
 
开发者ID:AdamBien,项目名称:javaee-calculator,代码行数:18,代码来源:CircuitBreaker.java

示例6: isServiceProvider_LdapPropertiesNull

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@Test
public void isServiceProvider_LdapPropertiesNull() throws Exception {
    // given
    InvocationContext context = mock(InvocationContext.class);
    Object[] parameters = { new VOOrganization(), new VOUserDetails(),
            null, "marketplaceId" };
    doReturn(parameters).when(context).getParameters();
    doReturn(Boolean.TRUE).when(ldapInterceptor.configService)
            .isServiceProvider();
    doReturn(new OperatorServiceBean()).when(context).getTarget();

    // when
    ldapInterceptor.ensureLdapDisabledForServiceProvider(context);

    // then
    verify(context, times(1)).proceed();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:LdapInterceptorTest.java

示例7: isServiceProvider_LdapPropertiesNotNull

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void isServiceProvider_LdapPropertiesNotNull() throws Exception {
    // Given a SAML_SP authentication mode and non-empty LdapProperties for
    // an organization
    InvocationContext context = mock(InvocationContext.class);
    Object[] parameters = { new VOOrganization(), new VOUserDetails(),
            new LdapProperties(), "marketplaceId" };
    doReturn(parameters).when(context).getParameters();

    doReturn(Boolean.TRUE).when(ldapInterceptor.configService)
            .isServiceProvider();
    doReturn(new OperatorServiceBean()).when(context).getTarget();

    // when
    ldapInterceptor.ensureLdapDisabledForServiceProvider(context);

    // then the creation of a customer for an LDAP-managed organization
    // should be unsupported
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:LdapInterceptorTest.java

示例8: isServiceProvider_PropertiesNotNull

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void isServiceProvider_PropertiesNotNull() throws Exception {
    // Given a SAML_SP authentication mode and non-empty Properties for
    // an organization
    InvocationContext context = mock(InvocationContext.class);
    Object[] parameters = { new Organization(), new ImageResource(),
            new VOUserDetails(), new Properties(), "domicileCountry",
            "marketplaceId", "description",
            OrganizationRoleType.PLATFORM_OPERATOR };
    doReturn(parameters).when(context).getParameters();

    doReturn(Boolean.TRUE).when(ldapInterceptor.configService)
            .isServiceProvider();
    doReturn(new OperatorServiceBean()).when(context).getTarget();

    // when
    ldapInterceptor.ensureLdapDisabledForServiceProvider(context);

    // then the creation of an LDAP-managed organization
    // should be unsupported
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:LdapInterceptorTest.java

示例9: isNotServiceProvider_PropertiesNotNull

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@Test
public void isNotServiceProvider_PropertiesNotNull() throws Exception {
    // Given an INTERNAL authentication mode and non-empty Properties for an
    // organization
    InvocationContext context = mock(InvocationContext.class);
    Object[] parameters = { new Organization(), new ImageResource(),
            new VOUserDetails(), new Properties(), "domicileCountry",
            "marketplaceId", "description",
            OrganizationRoleType.PLATFORM_OPERATOR };
    doReturn(parameters).when(context).getParameters();
    doReturn(Boolean.FALSE).when(ldapInterceptor.configService)
            .isServiceProvider();

    // when
    ldapInterceptor.ensureLdapDisabledForServiceProvider(context);

    // then
    verify(context, times(1)).proceed();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:LdapInterceptorTest.java

示例10: invokeInterceptor

import javax.interceptor.InvocationContext; //导入依赖的package包/类
private void invokeInterceptor(Method method, Class<?> clazz)
        throws InstantiationException, IllegalAccessException,
        InvocationTargetException {
    for (Method interceptorMethod : clazz.getMethods()) {
        if (interceptorMethod.getAnnotation(AroundInvoke.class) != null) {

            Object instance = clazz.newInstance();

            for (Field field : instance.getClass().getDeclaredFields()) {
                EJB ejb = field.getAnnotation(EJB.class);
                Inject inject = field.getAnnotation(Inject.class);
                if (ejb != null || inject != null) {
                    field.setAccessible(true);
                    field.set(instance, Mockito.mock(field.getType()));
                }
            }

            InvocationContext ic = createInvocationContext(method);
            interceptorMethod.invoke(instance, ic);
            break;
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:DeployedSessionBean.java

示例11: isLoggingEnabled

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object isLoggingEnabled(InvocationContext context) throws Exception {
    Object result = null;
    
    /**
     * Using DataService bean instead of ConfigurationServiceLocal bean due
     * to the problem with executing this with singleton
     * (ConfigurationServiceBean) on Jenkins for GF4
     */
    TypedQuery<ConfigurationSetting> query = dm.createNamedQuery(
            "ConfigurationSetting.findByInfoAndContext",
            ConfigurationSetting.class);
    query.setParameter("informationId", ConfigurationKey.AUDIT_LOG_ENABLED);
    query.setParameter("contextId", Configuration.GLOBAL_CONTEXT);

    ConfigurationSetting setting = query.getSingleResult();

    if (Boolean.parseBoolean(setting.getValue())) {
        result = context.proceed();
    }
    return result;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:AuditLoggingEnabled.java

示例12: intercept

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {

    if (configService.isServiceProvider()) {

        long userKey = identityService.getCurrentUserDetails().getKey();

        if (userKey != 1000L) {
            UnsupportedOperationException e = new UnsupportedOperationException(
                    "In SAML_SP mode the password can only be reset for the platform operator with key 1000.");

            Log4jLogger logger = LoggerFactory.getLogger(context
                    .getTarget().getClass());
            logger.logError(Log4jLogger.SYSTEM_LOG, e,
                    LogMessageIdentifier.ERROR_OPERATION_ONLY_FOR_1000);
            throw e;

        }
    }

    return context.proceed();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:PlatformOperatorServiceProviderInterceptor.java

示例13: ensureIsNotServiceProvider

import javax.interceptor.InvocationContext; //导入依赖的package包/类
/**
 * Checks if OSCM acts as a SAML service provider. If so, an
 * UnsupportedOperationException will be thrown.
 */
@AroundInvoke
public Object ensureIsNotServiceProvider(InvocationContext context)
        throws Exception {
    Object result = null;

    if (configService.isServiceProvider()) {
        UnsupportedOperationException e = new UnsupportedOperationException(
                "It is forbidden to perform this operation if a OSCM acts as a SAML service provider.");

        Log4jLogger logger = LoggerFactory.getLogger(context.getTarget()
                .getClass());
        logger.logError(Log4jLogger.SYSTEM_LOG, e,
                LogMessageIdentifier.ERROR_OPERATION_FORBIDDEN_FOR_SAML_SP);
        throw e;
    }

    result = context.proceed();

    return result;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:ServiceProviderInterceptor.java

示例14: 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

示例15: interceptMethodInvocation

import javax.interceptor.InvocationContext; //导入依赖的package包/类
@AroundInvoke
public Object interceptMethodInvocation(InvocationContext invocationContext) throws Exception {

    final String methodName = invocationContext.getMethod().getName();
    final String className = invocationContext.getTarget().getClass().getName();

    Logger logger = Logger.getLogger(className);

    final long timeBeforeMethodInvocation;
    final long timeAfterMethodInvocation;
    final long millis;
    logger.entering(className, methodName);
    timeBeforeMethodInvocation = System.currentTimeMillis();

    try {
        return invocationContext.proceed();
    } finally {
        timeAfterMethodInvocation = System.currentTimeMillis();
        millis = timeAfterMethodInvocation - timeBeforeMethodInvocation;
        logger.fine("Method took -> " + millis + " millis to be executed!");
        logger.exiting(className, methodName);
    }
}
 
开发者ID:harperkej,项目名称:store-app-ee,代码行数:24,代码来源:LoggingInterceptor.java


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