本文整理汇总了Java中javax.interceptor.AroundInvoke类的典型用法代码示例。如果您正苦于以下问题:Java AroundInvoke类的具体用法?Java AroundInvoke怎么用?Java AroundInvoke使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AroundInvoke类属于javax.interceptor包,在下文中一共展示了AroundInvoke类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accessAllowed
import javax.interceptor.AroundInvoke; //导入依赖的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.AroundInvoke; //导入依赖的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.AroundInvoke; //导入依赖的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.AroundInvoke; //导入依赖的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();
}
}
示例5: guard
import javax.interceptor.AroundInvoke; //导入依赖的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;
}
}
示例6: invokeInterceptor
import javax.interceptor.AroundInvoke; //导入依赖的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;
}
}
}
示例7: isLoggingEnabled
import javax.interceptor.AroundInvoke; //导入依赖的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;
}
示例8: intercept
import javax.interceptor.AroundInvoke; //导入依赖的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();
}
示例9: ensureIsNotServiceProvider
import javax.interceptor.AroundInvoke; //导入依赖的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;
}
示例10: invokeWithReporting
import javax.interceptor.AroundInvoke; //导入依赖的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);
}
}
示例11: interceptMethodInvocation
import javax.interceptor.AroundInvoke; //导入依赖的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);
}
}
示例12: aroundInvoke
import javax.interceptor.AroundInvoke; //导入依赖的package包/类
@AroundInvoke
public Object aroundInvoke(InvocationContext context) {
// close circuit after recovery time
// if circuit is open
// return null;
try {
return context.proceed();
} catch (Exception e) {
// record exception
// increase failure counter
// open circuit if failure exceeds threshold
return null;
}
}
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:19,代码来源:CircuitBreaker.java
示例13: guard
import javax.interceptor.AroundInvoke; //导入依赖的package包/类
/**
* If there is an exception thrown in the underlying method call, the exception is converted into an empty
* Optional.
*
* @param invocationContext Interceptor's invocation context
* @return Value returned by the underlying method call. Empty optional in case of an exception.
*/
@AroundInvoke
public Object guard(InvocationContext invocationContext) {
try {
Object returnedObject = invocationContext.proceed();
if (returnedObject == null || !(returnedObject instanceof Optional)) {
return Optional.empty();
}
return returnedObject;
} catch (Throwable throwable) {
super.throwExecutionErrorEvent(invocationContext, throwable);
return Optional.empty();
}
}
示例14: filter
import javax.interceptor.AroundInvoke; //导入依赖的package包/类
/**
* If there is a {@link Throwable} thrown in the underlying method call, the exception is converted into an empty
* Optional, unless the {@link Error} or {@link Exception} is listed as ignorable in {@link Semisafe} annotation.
*
* @param invocationContext Interceptor's invocation context
* @return Value returned by the underlying method call. Empty optional in case of an exception.
*/
@AroundInvoke
public Object filter(InvocationContext invocationContext) throws Throwable {
try {
final Object returnedObject = invocationContext.proceed();
if (returnedObject == null || !(returnedObject instanceof Optional)) {
return Optional.empty();
}
return returnedObject;
} catch (Throwable throwable) {
if (isIgnoredThrowable(throwable, invocationContext.getMethod())) {
throw throwable;
}
super.throwExecutionErrorEvent(invocationContext, throwable);
return Optional.empty();
}
}
示例15: aroundInvoke
import javax.interceptor.AroundInvoke; //导入依赖的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();
}
}