title: How to get the invoker name in EJB interceptor's lifecycle event method
body: <p>I use Java EE 5. I wrote an interceptor for all EJBs with three methods for logging:</p>
  
  <pre><code>public class DefaultInterceptor {
      public static final String PREFIX = "!!!!!!!!!Interceptor:";
  
      @PostConstruct
      public void postConstruct(InvocationContext ctx) {
          try {
              System.out.println(PREFIX + " postConstruct");
          } catch (Exception ex) {
              throw new RuntimeException(ex);
          }
      }
  
      @PreDestroy
      public void preDestroy(InvocationContext ctx) {
          try {
              System.out.println(PREFIX + " predestroy");
              System.out.println(PREFIX + "ctx.preceed=" + ctx.proceed());
          } catch (Exception ex) {
              throw new RuntimeException(ex);
          }
      }
  
      @AroundInvoke
      public Object intercept(InvocationContext ctx) throws Exception {
          System.out.println(PREFIX + "method invocation '" + ctx.getMethod().getName() + "'");
          System.out.println(PREFIX + "parameters ='" + Arrays.deepToString(ctx.getParameters()) + "'");
          System.out.println(Arrays.deepToString(ctx.getContextData().keySet().toArray()));
          Object result = null;
          try {
              result = ctx.proceed();
              System.out.println(PREFIX + "Method result='" + result + "'");
              return result;
          } catch (Exception ex) {
              System.out.println(PREFIX + "Method exception ='" + ex.getMessage() + "'");
              throw ex;
          } finally {
              System.out.println(PREFIX + "Method finished");
          }
      }
  } 
  </code></pre>
  
  <p>I want to get the name of EJB which called this interceptor. How can I do it?</p>
  
  <p>I tried <code>ctx.getMethod().getDeclaringClass().getSimpleName()</code> but <code>ctx.getMethod()</code> returns <code>null</code> in <code>postConstruct(-)</code> and <code>predestroy(-)</code> methods. </p>