本文整理汇总了Java中javax.interceptor.InvocationContext.proceed方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationContext.proceed方法的具体用法?Java InvocationContext.proceed怎么用?Java InvocationContext.proceed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.interceptor.InvocationContext
的用法示例。
在下文中一共展示了InvocationContext.proceed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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
示例3: 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;
}
示例4: 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();
}
}
示例5: aroundInvoke
import javax.interceptor.InvocationContext; //导入方法依赖的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
示例6: 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();
}
}
示例7: filter
import javax.interceptor.InvocationContext; //导入方法依赖的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();
}
}
示例8: aroundInvoke
import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
Object returnObject = null;
try {
// avant
((ConnectionSupport) ic.getTarget()).setConnection(connectionProvider.openConnection());
returnObject = ic.proceed();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
// apres
connectionProvider.closeJDBC(((ConnectionSupport) ic.getTarget()).getConnection(), null, null);
}
return returnObject;
}
示例9: logAroundInvoke
import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object logAroundInvoke(InvocationContext ic) throws Exception {
Class clazz = ic.getMethod().getDeclaringClass();
Log log = ic.getMethod().getAnnotation(Log.class);
if (DataHelper.hasBlank(log)) {
log = (Log) clazz.getAnnotation(Log.class);
}
boolean secure = (!DataHelper.hasBlank(log) && log.secure());
Object[] params = new Object[]{clazz.getName(), ic.getMethod().getName(),
Joiner.on(", ").useForNull("").join(ic.getParameters())};
L.debug("Entering - {}#{} : " + (secure ? "*****" : "{}"), ic.getMethod().getDeclaringClass().getSimpleName(),
ic.getMethod().getName(), params);
Object result = ic.proceed();
params[2] = result;
L.debug("Exiting - {}#{} : " + (secure ? "*****" : "{}"), ic.getMethod().getDeclaringClass().getSimpleName(),
ic.getMethod().getName(), result);
return result;
}
示例10: 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);
}
}
}
示例11: 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();
}
示例12: 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
示例13: logMethodCall
import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
@AroundInvoke
public Object logMethodCall(InvocationContext invocationContext)
throws Exception {
logger.log(Level.INFO, new StringBuilder("entering ").append(
invocationContext.getMethod().getName()).append(
" method").toString());
Object retVal = invocationContext.proceed();
logger.log(Level.INFO, new StringBuilder("leaving ").append(
invocationContext.getMethod().getName()).append(
" method").toString());
return retVal;
}
开发者ID:PacktPublishing,项目名称:Java-EE-7-Development-with-NetBeans-8,代码行数:17,代码来源:LoggingInterceptor.java
示例14: countedCallable
import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
private <E extends Member & AnnotatedElement> Object countedCallable(InvocationContext context, E element) throws Exception {
MetricResolver.Of<Counted> counted = resolver.counted(bean.getBeanClass(), element);
String name = counted.metricName();
Counter counter = (Counter) registry.getCounters().get(name);
if (counter == null) {
throw new IllegalStateException("No counter with name [" + name + "] found in registry [" + registry + "]");
}
LOGGER.debugf("Increment counter [metricName: %s]", name);
counter.inc();
try {
return context.proceed();
} finally {
if (!counted.metricAnnotation().monotonic()) {
LOGGER.debugf("Decrement counter [metricName: %s]", name);
counter.dec();
}
}
}
示例15: proceedAndSendMessage
import javax.interceptor.InvocationContext; //导入方法依赖的package包/类
/**
* Proceed the method and send MessageToClient to topic
* @param ctx
* @param topic
* @return
* @throws Exception
*/
Object proceedAndSendMessage(InvocationContext ctx, String topic, boolean jsonPayload) throws Exception {
MessageToClient messageToClient = new MessageToClient();
messageToClient.setId(topic);
Object result = ctx.proceed();
if(jsonPayload) {
if(!String.class.isInstance(result)) {
throw new UnsupportedOperationException("Method annotated JsTopic(jsonPayload=true) must return String type and correct Json.");
}
messageToClient.setJson((String) result);
} else {
messageToClient.setResponse(result);
}
wsEvent.fire(messageToClient);
return result;
}