是否可以拦截没有AroundTimeout注释的超时方法?

时间:2018-11-19 10:46:58

标签: java java-ee jar interceptor

我的公司当前正在使用旧的Javaee jar(5.2.0),其中不包含AroundTimeOut类。无法更改此jar,因为它将发生一些重大影响。我的经理要求我拦截超时方法。.您知道是否有解决此问题的方法吗?

这是我使用的方法:

@Timeout
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Interceptors(CorrelationIdInterceptor.class)
    public void handleTimeout(Timer timer) {

拦截器:

public class CorrelationIdInterceptor {


    private static final String CORRELATION_ID = "CORRELATION_ID";
    private static final String GET_CORRELATION_ID = "getCorrelationId";

    private static final Logger LOGGER = 
    Logger.getLogger(CorrelationIdInterceptor.class);


    @AroundInvoke
    public Object log(final InvocationContext ic) throws Exception {

        String webServiceMethodName = ic.getMethod().getName();


        if(webServiceMethodName.equalsIgnoreCase("handleTimeout")){
            webServiceMethodName="SIBOI"+":"+ webServiceMethodName;
        }

1 个答案:

答案 0 :(得分:0)

尝试添加您的ejb-jar.xml

    <assembly-descriptor>
      <interceptor-binding>
         <ejb-name>full.path.to.your.ejb</ejb-name>
         <interceptor-class>full.path.to.your.interceptor</interceptor-class>
         <method-name>method.in.your.ejb</method-name>
      </interceptor-binding>
   </assembly-descriptor>