Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CXF-5052] Classpath references should be understood using wsdlRoot batch processing options in cxf-codegen #384

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maven-plugins/codegen-plugin/src/it/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ wsdl-artifact-resolution
------------------------

Verifies that a wsdlArtifact from local repository is properly resolved for codegen.

wsdl-classpath-resolution
------------------------

Verifies that using wsdlRoot with "classpath;<path-to-replace>" will generate Java classes with valid classpath
URLs instead of the local file URL.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
==============================================================================
===== Describe all service specific name spaces. =====
==============================================================================
--><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:org:apache:cxf:Cxf5052Service" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:Cxf5052msg="urn:org:apache:cxf:message:Cxf5052Message" targetNamespace="urn:org:apache:cxf:Cxf5052Service"><!--Content from Maven Artifact: "org.apache.cxf.Cxf5052:Cxf5052Service:wsdl:1.0.0" generated 2017-06-28T13:11:08CEST:-->
<!--
==============================================================================
===== Describe all data types transmitted between the client and server.=====
==============================================================================
-->
<wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:org:apache:cxf:Cxf5052:Domain-1" targetNamespace="urn:org:apache:cxf:Cxf5052:Domain-1" elementFormDefault="qualified"><!--Content from Maven Artifact: "org.apache.cxf.Cxf5052:Domain-1:xsd:1.0.0":-->
<xsd:complexType name="Cxf5052DomainType">
<xsd:sequence>
<xsd:element name="Id" type="xsd:string" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:org:apache:cxf:message:Cxf5052Message" xmlns:domain="urn:org:apache:cxf:Cxf5052:Domain-1" targetNamespace="urn:org:apache:cxf:message:Cxf5052Message" elementFormDefault="qualified"><!--Content from Maven Artifact: "org.apache.cxf.Cxf5052:Cxf5052Message:xsd:1.1.0":-->
<xsd:import namespace="urn:org:apache:cxf:Cxf5052:Domain-1" />
<xsd:element name="Cxf5052Request" type="tns:Cxf5052RequestType" />
<xsd:element name="Cxf5052Response" type="tns:Cxf5052ResponseType" />
<xsd:complexType name="Cxf5052RequestType">
<xsd:sequence>
<xsd:element name="domain" type="domain:Cxf5052DomainType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Cxf5052ResponseType">
<xsd:sequence>
<xsd:element name="domain" type="domain:Cxf5052DomainType" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema></wsdl:types>
<!--
==============================================================================
===== Describe all messages transmitted between the client and server. =====
==============================================================================
-->
<wsdl:message name="Cxf5052Request">
<wsdl:part name="Cxf5052req" element="Cxf5052msg:Cxf5052Request" />
</wsdl:message>
<wsdl:message name="Cxf5052Response">
<wsdl:part name="Cxf5052resp" element="Cxf5052msg:Cxf5052Response" />
</wsdl:message>
<!--
==============================================================================
===== Describe interface and all operations. =====
==============================================================================
-->
<wsdl:portType name="Cxf5052Port">
<wsdl:operation name="Cxf5052operation">
<wsdl:input message="tns:Cxf5052Request" />
<wsdl:output message="tns:Cxf5052Response" />
</wsdl:operation>
</wsdl:portType>
<!--
==============================================================================
===== Describe how the service will be implemented on the wire. =====
==============================================================================
-->
<wsdl:binding name="Cxf5052PortBinding" type="tns:Cxf5052Port">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Cxf5052operation">
<soap:operation soapAction="Cxf5052operation" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<!--
==============================================================================
===== Describe where the service can be invoked. =====
==============================================================================
-->
<wsdl:service name="Cxf5052Service">
<wsdl:port name="Cxf5052Port_pt" binding="tns:Cxf5052PortBinding">
<soap:address location="http://cxf.apache.cxf/ws/Cxf5052Service" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.cxf</groupId>
<artifactId>cxf5052-codegen</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cxf5052-codegen</name>

<properties>
<wsdl.groupid>org.apache.cxf.cxf5052</wsdl.groupid>
<wsdl.artifactid>Cxf5052Service</wsdl.artifactid>
<wsdl.version>1.0.0</wsdl.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>${wsdl.groupid}</groupId>
<artifactId>${wsdl.artifactid}</artifactId>
<version>${wsdl.version}</version>
<packaging>wsdl</packaging>
<file>Cxf5052Service-1.0.0.wsdl</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.3-SNAPSHOT</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlRoot>${basedir}</wsdlRoot>
<includes>
<include>**/*.wsdl</include>
</includes>
<defaultOptions>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-server</extraarg>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-validate</extraarg>
</extraargs>
<wsdlLocation>classpath;${basedir}</wsdlLocation>
</defaultOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,35 @@ public String getUri() {
public void setUri(String uri) {
wsdl = uri;
}

/**
* Calls {@link Option#merge(Option)} and checks afterwards, if a classpath
* replacement string has been set as default option.<br>
* <br>
* A classpath replacement string in the format
* "classpath;/path/to/replace/" will be processed to replace the local
* file-Url of the WSDL-files with the classpath URL.<br>
* <br>
* Example: "file:/path/to/package1/package2/myservice.wsdl" will be converted
* to "classpath:/package1/package2/myservice.wsdl", if "classpath;/path/to/"
* has been set<br>
*
* @see org.apache.cxf.maven_plugin.wsdl2java.Option#merge(org.apache.cxf.maven_plugin.wsdl2java.Option)
*/
@Override
public void merge(Option defaultOptions) {
super.merge(defaultOptions);
if (!isSetWsdlLocation() && defaultOptions.isSetWsdlLocation()) {
String defaultWsdlLocation = defaultOptions.getWsdlLocation();
if (defaultWsdlLocation != null && defaultWsdlLocation.startsWith("classpath;")) {
try {
String[] replacer = defaultWsdlLocation.split(";");
String filePath = new File(replacer[1]).toURI().toURL().toExternalForm();
this.wsdlLocation = this.getWsdl().replace(filePath, "classpath:/");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}