Skip to content

Instantly share code, notes, and snippets.

@Kotlin-Native
Created July 10, 2015 09:22
Show Gist options
  • Select an option

  • Save Kotlin-Native/e0c77e6756ef979b4339 to your computer and use it in GitHub Desktop.

Select an option

Save Kotlin-Native/e0c77e6756ef979b4339 to your computer and use it in GitHub Desktop.
// The Annotation
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER, TYPE})
@Qualifier
public @interface RunInRequestScope {
}
// The Interceptor for the annotation
@Interceptor
@RunInRequestScope
public class RunInRequestScopeInterceptor implements Serializable {
@Inject
private BoundRequestContext boundRequestContext;
@AroundInvoke
public Object wrapWithRequestScope(InvocationContext context) throws Exception {
Map<String, Object> requestDataStore = new HashMap<String, Object>();
boundRequestContext.associate(requestDataStore);
boundRequestContext.activate();
try {
return context.proceed();
} catch (Exception e) {
// to do further exception handlin (if needed)
throw e;
} finally {
try {
boundRequestContext.invalidate();
boundRequestContext.deactivate();
} finally {
boundRequestContext.dissociate(requestDataStore);
}
}
}
}
// Method declaration with interceptor @RunInRequestScope public void useRequestScopeInHere() { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment