Question

I have a Java EE project packaged on an ear. The ear contains one Jar where i package my @stateless EJBs and other not managed classes (my model, utils etc). For some of these EJBs i use Jax-Ws to expose their functionality as a web-service.

I try to create a logging mechanism using AOP, so i place the @Interceptors annotation in my Jax-Ws powered EJBs. The problem is that when i try to compile/build/package using maven i receive the following exception. It seems the problem is specific to wsgen cause when i put the @Interceptors annotation in the NON Jax-ws annotated EJBs it compiles and runs without any problem. I use JAva build 1.6.0_41-b02.

I also tried to find an older version of javax.interceptor-api (probably compiled in Java 1.6, as major.minor version 51.0 means that it has been compiled in JSE 7, if i get it right) but seems that 1.2 is the older one.

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsgen (MyWebService) on pro
ect my-ws-ejb: Failed to execute wsgen: javax/interceptor/Interceptors : Unsupported major.minor version 51.0 -> [Help
1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plu
in:2.2:wsgen (MyWebService) on project my-ws-ejb: Failed to execute wsgen
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute wsgen
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:148)
        at org.jvnet.jax_ws_commons.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:95)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: java.lang.UnsupportedClassVersionError: javax/interceptor/Interceptors : Unsupported major.minor version 51.

        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:249)
        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:181)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
        at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
        at java.lang.Class.getAnnotation(Class.java:3038)
        at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:240)
        at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:222)
        at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123)
        at com.sun.tools.ws.WsGen.doMain(WsGen.java:74)
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:142)
        ... 22 more

My pom (part):

    <build>
            <!-- The name of the jar file -->
            <finalName>my-ws-ejb</finalName>
            <plugins>
                <!-- Use EJB 3.0 -->
                <plugin>
                    <groupId>org.apache.maven.plugins
                    </groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <ejbVersion>3.0</ejbVersion>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jax-ws-commons</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                        <!-- The WSDLs to be generated are placed here -->
                        <execution>
                            <id>MyWebService</id>
                            <configuration>
                                <sei>MyWebServiceBean</sei>
                                <genWsdl>true</genWsdl>
                                <keep>true</keep>
                                <verbose>true</verbose>
                            </configuration>
                            <goals>
                                <goal>wsgen</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <!-- Build with Java 6 -->
                            <source>1.6</source>
                            <target>1.6</target>
                            <!-- Show deprecations and warnings -->
                            <showDeprecation>true</showDeprecation>
                            <showWarnings>true</showWarnings>
                        </configuration>
                    </plugin>
            </plugins>
        </build>

        <dependencies>
            <!-- EJB 3 -->
            <dependency>
                <groupId>javax.ejb</groupId>
                <artifactId>ejb</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <!-- EclipseLink -->
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Oracle JDBC driver -->
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.1.0.7.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- AOP -->
            <dependency>
                <groupId>javax.interceptor</groupId>
                <artifactId>javax.interceptor-api</artifactId>
                <version>1.2</version>
            </dependency>
.....
</dependencies>

My Bean (part)

@Interceptors(LoggingAopService.class)
@WebService(
        serviceName = "MyWebService", portName = "MyWebService",
        targetNamespace = "..."
)
@Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
public class MyWebServiceBean implements MyWebService
{....}

No correct solution

OTHER TIPS

Are you try web-beans.xml instead annotation? if didn't please check this is link. May be the maven plugin don't recognize this annotation.

The class level declaration should be look like this code:

<myapp:MyWebServiceBean>
   <myfwk:LoggingAopService/>
</myapp:MyWebServiceBean>

And this interceptor need to enabled:

<Interceptors>
    <myfwk:LoggingAopService/>
</Interceptors>

I didn't test these codes.

web-beans.xml declaration you sent is jboss specific ? I use web logic and found that an interceptor can be enabled by the following xml added in the META-INF/beans.xml.

<interceptors>
    <class>org.samples.LoggingInterceptor</class>
</interceptors>

I will try the xml declaration but because i was in a hurry i leveraged Handler capabilities provided natively by the Jax-Ws framework (using @HandlerChain annotation) to "intercept" web service requests and responses.

I also tried to create a new annotation using the @InterceptorBinding way:

@Inherited
    @InterceptorBinding
    @Retention(RUNTIME)
    @Target({ METHOD, TYPE })
    public @interface Logging {
    }



@Interceptor
    @Logging
    public class LoggingInterceptor {
        @AroundInvoke
        public Object intercept(InvocationContext context) throws Exception {...}



 @Logging
    @WebService(serviceName = "MyWebService", portName = "MyWebService",
    targetNamespace = "...")
    @Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
    public class MyWebServiceBean implements MyWebService
    {....}

but this does not compile too, i receive the same error:

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:w
sgen (EDocWebService) on project eDoc-ws-ejb: Failed to execute wsgen: javax/int
erceptor/InterceptorBinding : Unsupported major.minor version 51.0 -> [Help 1]

Probably this is a case where ejb-jar.xml should be used

    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
      <interceptors>
        <interceptor>
          <interceptor-class>com.mypackage.LoggingInterceptor </interceptor-class>
        </interceptor>
      </interceptors>

      <assembly-descriptor>
        <interceptor-binding>
          <ejb-name>MyWebServiceBean</ejb-name>
          <interceptor-class>com.package.Interceptor</interceptor-class>
        </interceptor-binding>
      </assembly-descriptor>
 </ejb-jar>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top