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:
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java
// ...
tasks.register<Wsdl2Java>("example") {
toolOptions {
wsdl = file("path/to/example.wsdl").absolutePath
}
}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:
- For each task, the generated Java sources (the task output) is added to the
mainsource sets.- This can be disabled when creating the task by configuring
addToMainSourceSettofalse. This is a property on the task itself.
- This can be disabled when creating the task by configuring
- All
Wsdl2Javatask types are aggregated to a single task namedwsdl2java.
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.
| Type | Name | Description |
|---|---|---|
Property<String> | wsdl | The WSDL to process. The value can either be a direct path to a file on a local system or URL to a remote file. |
DirectoryProperty | outputDirectory | Specifies 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> | packageNames | Specifies zero, or more, package names to use for the generated code. Optionally specifies the WSDL namespace to package name mapping. |
ListProperty<String> | extraArgs | Specifies extra arguments to pass to the command-line code generator. |
ListProperty<String> | xjcArgs | Specifies arguments that are passed directly to the XJC processor when using the JAXB data binding. |
ListProperty<String> | asyncMethods | Specifies subsequently generated Java class methods to allow for client-side asynchronous calls, similar to enableAsyncMapping in a JAX-WS binding file. |
ListProperty<String> | bareMethods | Specifies subsequently generated Java class methods to have wrapper style, similar to enableWrapperStyle in JAX-WS binding file. |
ListProperty<String> | mimeMethods | Specifies subsequently generated Java class methods to enable mime:content mapping, similar to enableMIMEContent in JAX-WS binding file. |
ListProperty<String> | namespaceExcludes | Ignore 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> | defaultExcludesNamespace | Enables or disables the loading of the default excludes namespace mapping. If not set, wsdl2java defaults to true. |
Property<Boolean> | defaultNamespacePackageMapping | Enables 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> | bindingFiles | Specifies JAX-WS or JAXB binding files or XMLBeans context files. The values are evaluated as per Directory#file(String) from ProjectLayout#getProjectDirectory(). |
Property<String> | wsdlLocation | Specifies the value of the @WebServiceClient annotation's wsdlLocation property. By default, the wsdl2java tool will use the value of wsdl. |
Property<Boolean> | wsdlList | Specifies that the wsdlurl contains a plain text, new line delimited, list of wsdlurls instead of the WSDL itself. |
Property<String> | frontend | Specifies 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> | databinding | Specifies the databinding. Currently, supports JAXB, XMLBeans, SDO (sdo-static and sdo-dynamic), and JiBX. If not set, wsdl2java defaults to jaxb. |
Property<String> | wsdlVersion | Specifies the WSDL version. If not set, wsdl2java defaults to WSDL1.1; currently supports only WSDL1.1 version. |
Property<String> | catalog | Specify catalog file to map the imported WSDL/schema. |
Property<Boolean> | extendedSoapHeaders | Enables 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> | validateWsdl | Enables validating the WSDL before generating the code. |
Property<Boolean> | noTypes | Enables or disables generation of the type classes. If not set, wsdl2java defaults to false. |
Property<String> | faultSerialVersionUid | Specifies 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> | exceptionSuper | Specifies the superclass for fault beans generated from wsdl:fault elements. If not set, wsdl2java defaults to Exception. |
ListProperty<String> | seiSuper | Specifies the superinterfaces to use for generated SEIs. |
Property<Boolean> | markGenerated | Enables or disables adding the @Generated annotation to classes generated. |
Property<Boolean> | suppressGeneratedDate | Enables or disables writing the current timestamp in the generated file (since CXF version 3.2.2). |
Property<String> | serviceName | Specifies the WSDL service name to use for the generated code. |
Property<Boolean> | autoNameResolution | Enables or disables automatically resolving naming conflicts without requiring the use of binding customizations. |
Property<Boolean> | noAddressBinding | For 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> | allowElementRefs | Enables 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> | encoding | Encoding to use for generated sources (since CXF version 2.5.4). |
Property<Boolean> | verbose | Enables 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:
- Exclude the
org.slf4j:slf4j-nopdependency - Include a SLF4J provider (or binding)
- 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.
configurations.cxfCodegen {
exclude(group = "org.slf4j", module = "slf4j-nop")
}
dependencies {
cxfCodegen("ch.qos.logback:logback-classic:1.6.1")
}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