Created
July 10, 2015 09:22
-
-
Save Kotlin-Native/e0c77e6756ef979b4339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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