0

Firstly idea was to generate java classes without internet connection, so I decided use jax-ws-catalog.xml file to rewrite uri on resource/local directory.

I defined location of xsd files by using jax-ws-catalog.xml with classpath.

But every compilation is wrong and catching error:

WARN org.apache.cxf.resource.URIResolver - Resource classpath:/local/xml.xsd was not found in the classloaders.
WSDLToJava Error: org.apache.ws.commons.schema.XmlSchemaException: Unable to locate imported document at 'http://www.w3.org/2001/xml.xsd', relative to ...{my file}...

build.gradle

plugins {
    id 'java'
    id 'java-library'
    id "io.mateo.cxf-codegen" version "1.0.2"
}
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java


ext {
    artifactId = 'soap-adapter'
}

jar {
    enabled = true
}

bootJar {
    enabled = false
}

dependencies {
    implementation "javax.xml.ws:jaxws-api:${jaxwsApiVersion}"
    implementation "javax.jws:javax.jws-api:${javaxJwsApiVersion}"

    implementation "com.sun.xml.messaging.saaj:saaj-impl:${sunSaajImplVersion}"

    implementation "org.apache.cxf:cxf-rt-frontend-jaxws:${apacheCxfVersion}"
    implementation "org.apache.cxf:cxf-rt-transports-http:${apacheCxfVersion}"
    implementation "org.apache.cxf:cxf-rt-ws-security:${apacheCxfVersion}"

    cxfCodegen "jakarta.xml.ws:jakarta.xml.ws-api"
    cxfCodegen "jakarta.annotation:jakarta.annotation-api"
    cxfCodegen "ch.qos.logback:logback-classic"

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

// Common properties of java generation from wsdl.
tasks.withType(Wsdl2Java).configureEach {
    toolOptions {
        markGenerated.set(true)
        outputDir.set(file("${buildDir}/generated"))
        addToMainSourceSet.set(true)

        wsdl.set(file("${projectDir}/src/main/resources/wsdl/myWsdl.wsdl"))
        catalog.set("${projectDir}/src/main/resources/META-INF/jax-ws-catalog.xml")
    }
}

compileJava.dependsOn wsdl2java

jax-ws-catalog.xml

<?xml version="1.0"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <rewriteURI uriStartString="http://www.w3.org/2001/xml.xsd" rewritePrefix="classpath:/local/xml.xsd"/>
</catalog>

I think that classpath is determined wrong.

NewSheriff
  • 105
  • 4
  • Author here, are you able to provide a [minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) using for example a publicly available Web Service and WSDL such as [Calculator Web Service](https://ecs.syr.edu/faculty/fawcett/Handouts/cse775/code/calcWebService/Calc.asmx) – Cisco Feb 15 '23 at 14:50
  • @Cisco sorry I don't have enough time for that. I found the answer myself. Look below – NewSheriff Feb 16 '23 at 14:54
  • @Cisco sorry I don't have enough time for that. I found the answer myself. Look below – NewSheriff Feb 16 '23 at 14:55

1 Answers1

0

I discovered the next:

  1. At the programm compilation jax-ws-catalog.xml using only relative paths from itself.
  2. At the runtime you can use classpath.
  3. And jax-ws library using resurce/META-INF/jax-ws-catalog.xml by default.

So I just duplicated this jax-ws-catalog.xml into next directories with different properties:

resource/jax-ws-catalog.xml

<?xml version="1.0"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
  <rewriteURI uriStartString="http://" rewritePrefix="local/"/>
  <rewriteURI uriStartString="https://" rewritePrefix="local/"/>
</catalog>

resource/META-INF/jax-ws-catalog.xml

<?xml version="1.0"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
  <rewriteSystem systemIdStartString="http://www.w3.org/2006/03/addressing" rewritePrefix="classpath:local/www.w3.org/2006/03/addressing"/>
  <rewriteSystem systemIdStartString="http://www.w3.org/2005/08/addressing" rewritePrefix="classpath:local/www.w3.org/2005/08/addressing"/>
</catalog>

In build.gradle I changed the next

tasks.withType(Wsdl2Java).configureEach {
    toolOptions {
        markGenerated.set(true)
        outputDir.set(file("${buildDir}/generated"))
        addToMainSourceSet.set(true)

        wsdl.set(file("${projectDir}/src/main/resources/wsdl/myWsdl.wsdl"))
        catalog.set("${projectDir}/src/main/resources/jax-ws-catalog.xml")
    }
}
NewSheriff
  • 105
  • 4