bjornvester / wsdl2java-gradle-plugin

A Gradle plugin for generating Java classes from WSDL files
MIT License
40 stars 14 forks source link

Difficulties with using multiple bindings file in different locations - and instructions how to do it - maybe worth adding to doco #16

Open boardbloke opened 3 years ago

boardbloke commented 3 years ago

Hiyah,

Thanks for this plugin - its proved very useful in my project. I did however have a problem using it with bindings files which I thought worth raising as it might be worthwhile adding to the doco

The problem I encountered was using it from the Groovy DSL. I have multiple WSDL each with their own binding file - I was trying to use the following config which was failing:

wsdl2java {
    cxfVersion = "${project.ext.cxfVersion}" // Referring to this via project.ext to avoid name clash
    markGenerated = "yes-jdk9"
    wsdlDir = file("$projectDir/src/main/resources/wsdl")
    addCompilationDependencies = true

    //  Map wsdls and cxf-parameters
    includesWithOptions = [
            "wsdl1.wsdl" : ['-b', 'binding1.ejb'],
            "wsdl2.wsdl" : ['-b', 'binding2.ejb'],
            "wsdl3.wsdl" : ['-b', 'binding3.ejb']
    ]
}

Doing the above - with the wsdl and bindings file in the same directory ("$projectDir/src/main/resources/wsdl") I was getting an error

Failed to generate sources from WSDL:
org.apache.cxf.tools.common.ToolException: java.lang.IllegalArgumentException: URI is not hierarchical
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:410)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
    at com.github.bjornvester.wsdl2java.Wsdl2JavaWorker.execute(Wsdl2JavaWorker.kt:18)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:49)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:43)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
    at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:43)
    at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
    at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
    at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:85)
    at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:55)
    at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:138)
    at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
    at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:135)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
    at java.base/java.io.File.<init>(File.java:420)
    at org.apache.cxf.resource.URIResolver.tryFileSystem(URIResolver.java:152)
    at org.apache.cxf.resource.URIResolver.<init>(URIResolver.java:93)
    at org.apache.cxf.resource.URIResolver.<init>(URIResolver.java:75)
    at org.apache.cxf.resource.URIResolver.<init>(URIResolver.java:71)
    at org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer.validate(JAXWSContainer.java:74)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:164)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:156)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:402)
    ... 31 more

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':wsdl2java'.
> A failure occurred while executing com.github.bjornvester.wsdl2java.Wsdl2JavaWorker
   > Failed to generate Java sources from WSDL. See the log for details.

I eventually found that the whole path to the binding file needs to specified - i.e.

wsdl2java {
    cxfVersion = "${project.ext.cxfVersion}" // Referring to this via project.ext to avoid name clash
    markGenerated = "yes-jdk9"
    wsdlDir = file("$projectDir/src/main/resources/wsdl")
    addCompilationDependencies = true

    //  Map wsdls and cxf-parameters
    includesWithOptions = [
            "wsdl1.wsdl" : ['-b', "$projectDir/src/main/resources/wsdl/binding1.ejb".toString()],
            "wsdl2.wsdl" : ['-b', "$projectDir/src/main/resources/wsdl/binding2.ejb".toString()],
            "wsdl3.wsdl" : ['-b', "$projectDir/src/main/resources/wsdl/binding3.ejb".toString()]
    ]
}

Note that it was not enough to just quote the path to the binding file relative to the project directory - e.g. 'src/main/resources/wsdl/binding1.ejb', so in Groovy I used a Groovy string "$projectDir/src/main/resources/wsdl/binding1.ejb".

Note also that the toString() is required because the Array needs to be a List of String and its not being converted automatically - without the toString() you get:

Failed to generate sources from WSDL:
java.lang.ArrayStoreException: arraycopy: element type mismatch: can not cast one of the elements of java.lang.Object[] to the type of the destination array, java.lang.String
    at java.base/java.util.Arrays.copyOf(Arrays.java:3722)
    at java.base/java.util.ArrayList.toArray(ArrayList.java:432)
    at com.github.bjornvester.wsdl2java.Wsdl2JavaWorker.execute(Wsdl2JavaWorker.kt:61)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:49)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:43)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
    at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:43)
    at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
    at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
    at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:85)
    at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:55)
    at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:138)
    at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
    at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:135)
    at jdk.internal.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
    at java.base/java.lang.Thread.run(Thread.java:829)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':wsdl2java'.
> A failure occurred while executing com.github.bjornvester.wsdl2java.Wsdl2JavaWorker
   > Failed to generate Java sources from WSDL. See the log for details.