简体   繁体   中英

CDI Interceptor Glassfish after deploy NullPointer

I am playing with glassfish 3.1 for the first time.

After creating META-INF\\beans.xml file, deployment fails.

@WebServlet

@Override
@Audit
protected void service(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
    PrintWriter writer = res.getWriter();
    writer.write("Hello!");

}

Annotation @Audit

@Inherited  
@InterceptorBinding  
@Retention(RetentionPolicy.RUNTIME)  
@Target({ElementType.METHOD, ElementType.TYPE}) 

public @interface Audit {
}

Audit Implementation

@Interceptor
@Audit
public class AuditImpl {
     @AroundInvoke  
     public Object auditting(InvocationContext context) throws Exception {  
     System.out.println("Log before method call...");  
     Object returnObject = context.proceed();  
            // to do some logging  
     System.out.println("Log after method call...");  
     return returnObject;  
     } 
}

META-INF/beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
  http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
 <interceptors>
    <class>xyz.AuditImpl</class>
 </interceptors>
</beans>

I don't know where to look for error details in Glassfish. Please help.

Deployment error:

[#|2012-09-27T21:43:31.010+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=55;_ThreadName=Thread-1;|Exception while invoking class org.glassfish.weld.WeldDeployer load method
java.lang.NullPointerException
    at org.glassfish.weld.BeanDeploymentArchiveImpl.handleEntry(BeanDeploymentArchiveImpl.java:489)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.collectJarInfo(BeanDeploymentArchiveImpl.java:473)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.populate(BeanDeploymentArchiveImpl.java:413)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.<init>(BeanDeploymentArchiveImpl.java:148)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.<init>(BeanDeploymentArchiveImpl.java:128)
    at org.glassfish.weld.DeploymentImpl.<init>(DeploymentImpl.java:120)
    at org.glassfish.weld.WeldDeployer.load(WeldDeployer.java:334)
    at org.glassfish.weld.WeldDeployer.load(WeldDeployer.java:99)
    at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
    at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:249)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
    at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:145)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:577)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:463)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:395)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:380)
    at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:213)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
|#]

[#|2012-09-27T21:43:31.010+0200|SEVERE|glassfish3.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=55;_ThreadName=Thread-1;|Exception while loading the app|#]

[#|2012-09-27T21:43:31.016+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=55;_ThreadName=Thread-1;|Exception while loading the app|#]

I have cleared all occurrences of my application in glassfish server and after restart and new deployment, application works.

BTW: My @Audit interceptor is called when used with EJB methods, with @WebServlet methods is my interceptor not called. I will post new question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM