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


Java InvocationContext.getContextData方法代码示例

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


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

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

示例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())
		contextData.put("test_trace", "test_trace");
	return ic.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:16,代码来源:ExcludedInterceptor.java

示例3: aroundInvoke

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
    KeycloakToken keycloakToken = null;

    Map<String, Object> contextData = invocationContext.getContextData();
    if (contextData.containsKey(KeycloakToken.TOKEN_KEY)) {
        keycloakToken = (KeycloakToken) contextData.get(KeycloakToken.TOKEN_KEY);
        logger.info("Successfully found KeycloakToken passed from client");

        ContextStateCache stateCache = null;
        try {
            try {
                // We have been requested to use an authentication token so now we attempt the switch.
                // This userPrincipal and credential will be found by JAAS login modules
                SimplePrincipal userPrincipal = new SimplePrincipal(keycloakToken.getUsername());
                String accessToken = keycloakToken.getToken();
                stateCache = SecurityActions.pushIdentity(userPrincipal, accessToken);
                logger.infof("Successfully pushed userPrincipal %s and his credential", userPrincipal.getName());

            } catch (Exception e) {
                logger.error("Failed to switch security context for user", e);
                // Don't propagate the exception stacktrace back to the client for security reasons
                throw new EJBAccessException("Unable to attempt switching of user.");
            }

            return invocationContext.proceed();
        } finally {
            // switch back to original context
            if (stateCache != null) {
                SecurityActions.popIdentity(stateCache);
                ;
            }
        }

    } else {
        logger.warn("No Keycloak token found");
        return invocationContext.proceed();
    }
}
 
开发者ID:mposolda,项目名称:keycloak-remote-ejb,代码行数:40,代码来源:ServerSecurityInterceptor.java

示例4: controlInvoke

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object controlInvoke(InvocationContext ctx) throws Exception {
   log.debug("execute CibetContextInterceptor with " + ctx);
   boolean isNewlyManaged = false;
   AuthenticationProvider auth = new InvocationContextAuthenticationProvider(ctx.getContextData());
   AuthenticationProvider anonymousAuth = new AnonymousAuthenticationProvider();
   try {
      isNewlyManaged = Context.start(null, auth, anonymousAuth);
      return ctx.proceed();
   } finally {
      if (isNewlyManaged) {
         Context.end();
      } else {
         Context.internalRequestScope().getAuthenticationProvider().getProviderChain().remove(auth);
         Context.internalRequestScope().getAuthenticationProvider().getProviderChain().remove(anonymousAuth);
      }
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:19,代码来源:CibetContextInterceptor.java

示例5: aroundConstruct

import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundConstruct
public Object aroundConstruct(InvocationContext ic) throws Exception {
	logger.info("Executing " + ic.getConstructor());
	Map<String, Object> data = ic.getContextData();
	data.forEach((k, v) -> logger.info("data key: " + k + " - value: " + v));
	return ic.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:8,代码来源:LoggingInterceptor.java


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