3

I want to add java annotations the service endpoint implementation interface class for an Apache CXF web service client, generated from a WSDL.

This is the binding file I am using that should leverage the Annotate plugin for JAXB from http://confluence.highsource.org/display/J2B/Annotate+Plugin:

<jaxws:bindings wsdlLocation="OptenetServices.wsdl"
     xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:annox="http://annox.dev.java.net"
     jaxws:extensionBindingPrefixes="annox">

   <jaxws:bindings node="wsdl:portType">
      <annox:annotate>
         <annox:annotate annox:class="org.jvnet.hk2.annotations.Contract" />
      </annox:annotate>
    </jaxws:bindings>
</jaxws:bindings>

There are no errors, but the annotation is just not created. I can confirm that the node is selected and the bindings are used because if I change the annox:annotate with:

    <jaxws:class name="Renamed">
        <jaxws:javadoc>Blah blah</jaxws:javadoc>
    </jaxws:class>

The interface is renamed and commented correctly.

It is unclear to me if annox can be used in this context and what is the relation between jaxb and jaxws bindings.

The code generation is handled by CFX, through Maven:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-codegen-plugin</artifactId>
      <version>${cxf.version}</version>
      <executions>
        <execution>
          <id>generate-sources</id>
          <phase>generate-sources</phase>
          <configuration>
            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
            <wsdlOptions>
              <wsdlOption>
                <wsdl>${basedir}/src/main/wsdl/service.wsdl</wsdl>
                <extraargs>
                  <extraarg>-client</extraarg>
                  <extraarg>-p</extraarg>
                  <extraarg>com.example.pkg</extraarg>
                  <extraarg>-b</extraarg>
                  <extraarg>${basedir}/src/main/wsdl/bindings.xml</extraarg>
                  <extraarg>-xjc-Xannotate</extraarg>
                  <extraarg>-verbose</extraarg>
                </extraargs>
              </wsdlOption>
            </wsdlOptions>
          </configuration>
          <goals>
            <goal>wsdl2java</goal>
          </goals>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics-annotate</artifactId>
          <version>0.6.5</version>
        </dependency>
        <dependency>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics-annotate</artifactId>
          <version>0.6.5</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

Thanks.

lexicore
  • 42,748
  • 17
  • 132
  • 221
Andrea Ratto
  • 815
  • 1
  • 11
  • 23

2 Answers2

1

Have you tried it with <annox:annotateClass> instead of <annox:annotate annox:class="org.jvnet.hk2.annotations.Contract" />

Example given:

This will annotate the generated class FindApplicationForApplicationSession with @SuppressWarnings("all")

<jaxws:bindings node="xs:complexType[@name='findApplicationForApplicationSession']"> <annox:annotateClass>@java.lang.SuppressWarnings(name="all")</annox:annotateClass> </jaxws:bindings>

Fachher
  • 28
  • 4
1

It is not possible to annotate SEI classes using binding file. Apache CXF's cxf-codegen-plugin uses velocity templates to generate SEI classes.Therefore you should create a plugin which provide different velocity template.

Example: https://github.com/valmol/samples-cxf-codegen-plugin/

The generator just add comments to generated SEI.Adding annotation which does not depends on generated context is also straightforward task, just add annotation into custom template as is.

Valeriy
  • 126
  • 4