interceptor

Java CDI. Interceptor is only invoked in the first method call in a class [duplicate]

老子叫甜甜 提交于 2019-12-05 09:39:16
This question already has an answer here : Why is the interceptor not called in the same service class? (1 answer) Closed 3 years ago . I'm using CDI Interceptors and I've realized that only the first method call in a class annotated with @Interceptor is intercepted. In the example below methodB is never intercepted. @InterceptorBinding @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Transactional { } @Transactional @Interceptor public class TransactionsInterceptor { @AroundInvoke public Object transactionInterceptor(InvocationContext context) throws Exception {

Using EJB interceptors after a method call

假如想象 提交于 2019-12-05 02:31:23
I know one can use interceptors before a method call by using the @AroundInvoke annotation. What I would like to do is execute certain code after the method call, so that I can for example create a log entry before and after a method execution. Is this possible with EJB3, or do I need to use AOP? @AroundInvoke interceptor is passed InvocationContext, and proceed() must be called to advance the method. Thus: @AroundInvoke public Object log(InvocationContext ic) throws Exception { logEntry(); try { return ic.proceed(); } finally { logExit(); } } Depending on your needs, you could also log the

Autowired to hibernate Interceptor

拜拜、爱过 提交于 2019-12-05 02:12:33
问题 I'm extending hibernate.EmptyInterceptor and in my implementation I would like to have autowired to some services but they return null. I added a @Component annotation over the class. My code: <property name="jpaPropertyMap"> <map> <entry key="javax.persistence.transactionType" value="JTA" /> <entry key="hibernate.current_session_context_class" value="jta" /> <entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" /> <entry

catch moment when spring initialized all beans

試著忘記壹切 提交于 2019-12-05 00:42:28
I have spring application(I haven't lazy beans). I want to insert logic to place when all @Component(@Repositoey @Service @Controller) beans are initialized. How can I make it? trf As mentioned in the answer to this question , you could use ApplicationListener and look for the ContextRefreshedEvent : public class Loader implements ApplicationListener<ContextRefreshedEvent>{ public void onApplicationEvent(ContextRefreshedEvent event) { // whatever you want to do when app context is initialized or refreshed } } 来源: https://stackoverflow.com/questions/19541600/catch-moment-when-spring-initialized

How to exclude some services like login, register from interceptor Angular 5, HttpClient

被刻印的时光 ゝ 提交于 2019-12-05 00:30:17
i wanted to exclude some services using interceptor. app.module.js providers: [ UserService, RolesService, { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }, ], Login.service.ts return this.httpClient.post(this.appUrl + '/oauth/token', body.toString(), { headers, observe: 'response' }) .map((res: Response) => { const response = res.body; this.storeToken(response); return response; }) .catch((error: any) => { ErrorLogService.logError(error); return Observable.throw(new Error(error.status)); }); } To give this an answer not only in comments as requested ;-) To exclude some

spring aop不起作用

心已入冬 提交于 2019-12-04 23:17:45
接手了一个老项目,用的是spring 1.2.9的,配置aop怎么也不起作用,在网上搜了半天,只能啃官方文档。 https://docs.spring.io/spring/docs/1.2.9/reference/aop.html 不知道为什么,必须加上 DefaultAdvisorAutoProxyCreator 才起作用 <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean id="interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"/> <bean id="settersAndAbsquatulateAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="advice"> <ref local="interceptor"/> </property> <property name="patterns"> <list> <value>com.my.service.*</value> </list> <

Retrofit 2.0 headers authentication

北慕城南 提交于 2019-12-04 21:40:32
问题 private void setUpRestClient() { OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); Request request = original.newBuilder() .header("Accept", "application/pyur.v1") .header("Authorization", new SharedPreferencesUtil(getBaseContext()).getToken()) .header("Content-Type", "application/json") .method(original.method(),original.body()) .build(); return

Angular 4 - Callback for Observable.do() does not get called in interceptor

前提是你 提交于 2019-12-04 21:30:44
Trying to implement solution for displaying a loading indicator when requests are in progress. Looking from this solution I implemented the interceptor with the service. All works fine, except the counter is not deceasing becase the .do() callback never gets executed ( b is never printed in the console). Any thoughts on that? How to know if request has finished? import { Injectable } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/do'; import {

Intercept only interface methods with DynamicProxy

一笑奈何 提交于 2019-12-04 19:13:20
I got an interface like this public interface IService { void InterceptedMethod(); } A class that implements that interface and also has another method public class Service : IService { public virtual void InterceptedMethod() { Console.WriteLine("InterceptedMethod"); } public virtual void SomeMethod() { Console.WriteLine("SomeMethod"); } } And an Interceptor public class MyInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Intercepting"); invocation.Proceed(); } } I want to intercept only the methods on Service that exists on IService (i.e I want to

Help needed with Spring/Hibernate Lazy-loading

旧巷老猫 提交于 2019-12-04 15:17:06
I know that this has been discussed lot of times. I just can't understand how this work or where my mistake is. I think giving you a reduced example is the best way to show you what I'm trying to do and what assumptions I'm taking... I have a Product class with a name. The name is a String property that is lazy. My DAO: public abstract class HibernateProductDAO extends HibernateDaoSupport implements ProductDAO { public List getAll() { return this.getHibernateTemplate().find("from " + this.getDomainClass().getSimpleName()); } } My Service Interface: public interface ProductService { //This