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