Skip to content

Task API

TIP

The Worker API is the preferred approach for Java code generation

The Task API approach uses Gradle tasks to execute the wsdl2java tool. For each WSDL document to process, you must create a separate Gradle task of type Wsdl2Java.

The Wsdl2Java task is provided by this plugin and is a subclass of Gradle's JavaExec. As such, any and all configuration options available on JavaExec are also available on Wsdl2Java.

Configuration

For each WSDL document to process, create a task that holds the configuration. The task should be of type of Wsdl2Java. Create the task using your preferred method of task creation.

The following example shows a single task named example that processes the example.wsdl document:

kotlin
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java

// ...

tasks.register<Wsdl2Java>("example") {
    toolOptions {
        wsdl = file("path/to/example.wsdl").absolutePath
    }
}
groovy
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java

// ...

tasks.register("example", Wsdl2Java) {
    toolOptions {
        wsdl = file("path/to/example.wsdl").absolutePath
    }
}

By convention, the generated Java sources will be created in the$buildDir/$name-wsdl2java-generated-sources directory where $name is the task name.

Additionally, when defining a task:

  1. For each task, the generated Java sources (the task output) is added to the main source sets.
    • This can be disabled when creating the task by configuring addToMainSourceSet to false. This is a property on the task itself.
  2. All Wsdl2Java task types are aggregated to a single task named wsdl2java.

Tool Options

The Wsdl2Java task type provides type-safe properties that map to the underlying wsdl2java tool options. The properties are all lazy properties. Their values are realized when the task is executed.

The table below lists the available properties, descriptions, and type. These are a direct mapping to the wsdl2java tool options listed in the tool's documentation here.

These options should be configured within the toolOptions { } block as shown above in Configuration.

TypeNameDescription
Property<String>wsdlThe WSDL to process. The value can either be a direct path to a file on a local system or URL to a remote file.
DirectoryPropertyoutputDirectorySpecifies the directory the generated code files are written. If not set, the convention is build/$name-wsdl2java-generated-sources. The $name variable is the option name
ListProperty<String>packageNamesSpecifies zero, or more, package names to use for the generated code. Optionally specifies the WSDL namespace to package name mapping.
ListProperty<String>extraArgsSpecifies extra arguments to pass to the command-line code generator.
ListProperty<String>xjcArgsSpecifies arguments that are passed directly to the XJC processor when using the JAXB data binding.
ListProperty<String>asyncMethodsSpecifies subsequently generated Java class methods to allow for client-side asynchronous calls, similar to enableAsyncMapping in a JAX-WS binding file.
ListProperty<String>bareMethodsSpecifies subsequently generated Java class methods to have wrapper style, similar to enableWrapperStyle in JAX-WS binding file.
ListProperty<String>mimeMethodsSpecifies subsequently generated Java class methods to enable mime:content mapping, similar to enableMIMEContent in JAX-WS binding file.
ListProperty<String>namespaceExcludesIgnore the specified WSDL schema namespace when generating code. Optionally specifies the Java package name used by types described in the excluded namespace(s) using schema-namespace[=java-packagename].
Property<Boolean>defaultExcludesNamespaceEnables or disables the loading of the default excludes namespace mapping. If not set, wsdl2java defaults to true.
Property<Boolean>defaultNamespacePackageMappingEnables or disables the loading of the default namespace package name mapping. If not set, wsdl2java defaults to true and the http://www.w3.org/2005/08/addressing package mapping will be enabled.
SetProperty<String>bindingFilesSpecifies JAX-WS or JAXB binding files or XMLBeans context files. The values are evaluated as per Directory#file(String) from ProjectLayout#getProjectDirectory().
Property<String>wsdlLocationSpecifies the value of the @WebServiceClient annotation's wsdlLocation property. By default, the wsdl2java tool will use the value of wsdl.
Property<Boolean>wsdlListSpecifies that the wsdlurl contains a plain text, new line delimited, list of wsdlurls instead of the WSDL itself.
Property<String>frontendSpecifies the frontend. Currently only supports JAX-WS CXF frontends and a jaxws21 frontend to generate JAX-WS 2.1 compliant code. If not set, wsdl2java defaults to jaxws.
Property<String>databindingSpecifies the databinding. Currently, supports JAXB, XMLBeans, SDO (sdo-static and sdo-dynamic), and JiBX. If not set, wsdl2java defaults to jaxb.
Property<String>wsdlVersionSpecifies the WSDL version. If not set, wsdl2java defaults to WSDL1.1; currently supports only WSDL1.1 version.
Property<String>catalogSpecify catalog file to map the imported WSDL/schema.
Property<Boolean>extendedSoapHeadersEnables or disables processing of implicit SOAP headers (i.e. SOAP headers defined in the wsdl:binding, but not wsdl:portType section). If not set, wsdl2java defaults to false.
Property<String>validateWsdlEnables validating the WSDL before generating the code.
Property<Boolean>noTypesEnables or disables generation of the type classes. If not set, wsdl2java defaults to false.
Property<String>faultSerialVersionUidSpecifies how to generate serial version UID of fault exceptions. Use one of the following: NONE, TIMESTAMP, FQCN, or a specific number. If not set, wsdl2java defaults to NONE.
Property<String>exceptionSuperSpecifies the superclass for fault beans generated from wsdl:fault elements. If not set, wsdl2java defaults to Exception.
ListProperty<String>seiSuperSpecifies the superinterfaces to use for generated SEIs.
Property<Boolean>markGeneratedEnables or disables adding the @Generated annotation to classes generated.
Property<Boolean>suppressGeneratedDateEnables or disables writing the current timestamp in the generated file (since CXF version 3.2.2).
Property<String>serviceNameSpecifies the WSDL service name to use for the generated code.
Property<Boolean>autoNameResolutionEnables or disables automatically resolving naming conflicts without requiring the use of binding customizations.
Property<Boolean>noAddressBindingFor compatibility with CXF 2.0, this flag directs the code generator to generate the older CXF proprietary WS-Addressing types instead of the JAX-WS 2.1 compliant WS-Addressing types.
Property<Boolean>allowElementRefsEnables or disables disregarding the rule given in section 2.3.1.2(v) of the JAX-WS 2.2 specification disallowing element references when using wrapper-style mapping.
Property<String>encodingEncoding to use for generated sources (since CXF version 2.5.4).
Property<Boolean>verboseEnables or disables verbosity.

Logging

Apache CXF uses SLF4J for logging and by default, all logs are suppressed by default. This is accomplished by the inclusion of theorg.slf4j:slf4j-nop dependency in the cxfCodegen configuration.

If logs were not suppressed by default, when executing any of the created tasks, the following lines will be printed to the console:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

The above logging provides no useful information in the build output and instead pollutes the build output. This is the reason why logging is suppressed by default.

Enable Logging

To enable logging for Apache CXF:

  1. Exclude the org.slf4j:slf4j-nop dependency
  2. Include a SLF4J provider (or binding)
  3. Include a logging library
    • The library should implement the SLF4J API

In the following example, Logback is used which provides an implementation of the SLF4J API.

kotlin
configurations.cxfCodegen {
    exclude(group = "org.slf4j", module = "slf4j-nop")
}

dependencies {
    cxfCodegen("ch.qos.logback:logback-classic:1.6.1")
}
groovy
configurations {
    cxfCodegen {
        exclude group: "org.slf4j", module: "slf4j-nop"
    }
}

dependencies {
    cxfCodegen "ch.qos.logback:logback-classic:1.6.1"
}

With the above configuration, you will see logs from Apache CXF:

11:00:38.266 [main] DEBUG org.apache.cxf.common.logging.LogUtils -- Using org.apache.cxf.common.logging.Slf4jLogger for logging.
11:00:38.319 [main] DEBUG org.apache.cxf.tools.wsdlto.core.PluginLoader -- Loading plugin jar:file:~/.gradle/caches/modules-2/files-2.1/org.apache.cxf/cxf-tools-wsdlto-databinding-jaxb/4.0.0/5876acee034617f4f6ed756105fe9a0dc50a750c/cxf-tools-wsdlto-databinding-jaxb-4.0.0.jar!/META-INF/tools-plugin.xml
11:00:38.349 [main] DEBUG org.apache.cxf.tools.wsdlto.core.PluginLoader -- Found 1 databindings in <jaxb> plugin.
11:00:38.349 [main] DEBUG org.apache.cxf.tools.wsdlto.core.PluginLoader -- Loading <jaxb> databinding from <jaxb> plugin.
11:00:38.349 [main] DEBUG org.apache.cxf.tools.wsdlto.core.PluginLoader -- Loading plugin jar:file:~/.gradle/caches/modules-2/files-2.1/org.apache.cxf/cxf-tools-wsdlto-frontend-jaxws/4.0.0/762d4f960e3e8778af050a271218785567bc29e1/cxf-tools-wsdlto-frontend-jaxws-4.0.0.jar!/META-INF/tools-plugin.xml

...and so on

Released under Apache 2.0 license