[
https://issues.apache.org/jira/browse/CXF-9154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18012414#comment-18012414
]
Freeman Yue Fang commented on CXF-9154:
---------------------------------------
Hi [~spineau]
It's not the same Adapter1.java is generated for both runs, it's the second
run's Adapter1.java override the first run.
And since in globalBindings of two binding.xml, you have the same <javaType
name="java.util.Calendar" xmlType="xs:dateTime", so two
org/w3/_2001/xmlschema/Adapter1.java will be generated, but the second one
overrides the first one. No way to specify the Adapter class with
jaxb:javaType, and this behaviour is from jaxb xjc tools, not from CXF itself.
A workaround I can come up with is that to use xjc:javaType instead of
jaxb:javaType from which you can specify the Adapter class name. So do some
change in src/main/resources/service2/binding.xml like
{code}
--- a/src/main/resources/service2/binding.xml
+++ b/src/main/resources/service2/binding.xml
@@ -1,8 +1,9 @@
<bindings xmlns="https://jakarta.ee/xml/ns/jaxb" version="3.0"
- xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
+ xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
+ jaxb:extensionBindingPrefixes="xjc">
<globalBindings>
- <javaType name="java.util.Calendar" xmlType="xs:dateTime"
- parseMethod="com.example.demo.ConverterCustom.parseDateTime"
-
printMethod="com.example.demo.ConverterCustom.printDateTime"/>
+ <xjc:javaType adapter="com.example.demo.Adapter1"
name="java.util.Calendar" xmlType="xs:dateTime"/>
</globalBindings>
</bindings>
{code}
And also add a src/main/java/com/example/demo/Adapter1.java like or whatever
you need here
{code}
package com.example.demo;
import java.util.Calendar;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
public class Adapter1
extends XmlAdapter<String, Calendar>
{
public Calendar unmarshal(String value) {
return (com.example.demo.ConverterCustom.parseDateTime(value));
}
public String marshal(Calendar value) {
return (com.example.demo.ConverterCustom.printDateTime(value));
}
}
{code}
Best Regards
Freeman
> [cxf-codegen-plugin][WSDL2Java] Incorrect Adapter Usage with Multiple
> executions
> --------------------------------------------------------------------------------
>
> Key: CXF-9154
> URL: https://issues.apache.org/jira/browse/CXF-9154
> Project: CXF
> Issue Type: Wish
> Affects Versions: 4.1.2
> Reporter: Sullivan Pineau
> Assignee: Freeman Yue Fang
> Priority: Major
>
> Hello,
> We are experiencing a problem with the cxf-codegen-plugin when running
> multiple executions under the goal wsdl2java. Specifically, we have
> configured two executions where each references a different WSDL and binding
> file. Although the plugin successfully generates code for both WSDLs, the
> Adapter being generated and used for both seems to derive from the binding of
> the last execution.
> For example :
> Binding 1 (/src/main/resources/service1/binding.xml) :
> {code:xml}
> <bindings xmlns="https://jakarta.ee/xml/ns/jaxb" version="3.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <globalBindings>
> <javaType name="java.util.Calendar" xmlType="xs:dateTime"
>
> parseMethod="jakarta.xml.bind.DatatypeConverter.parseDateTime"
>
> printMethod="jakarta.xml.bind.DatatypeConverter.printDateTime"/>
> </globalBindings>
> </bindings>
> {code}
> Binding 2 (/src/main/resources/service2/binding.xml) :
> {code:xml}
> <bindings xmlns="https://jakarta.ee/xml/ns/jaxb" version="3.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <globalBindings>
> <javaType name="java.util.Calendar" xmlType="xs:dateTime"
> parseMethod="com.example.demo.ConverterCustom.parseDateTime"
>
> printMethod="com.example.demo.ConverterCustom.printDateTime"/>
> </globalBindings>
> </bindings>
> {code}
> pom.xml
> {code:xml}
> ...
> <plugin>
> <groupId>org.apache.cxf</groupId>
> <artifactId>cxf-codegen-plugin</artifactId>
> <version>${cxf.version}</version>
> <executions>
> <execution>
> <id>generate-sources-service-1</id>
> <phase>generate-sources</phase>
> <configuration>
> <defaultOptions>
>
> <bindingFiles><bindingFile>${project.basedir}/src/main/resources/service1/binding.xml
> </bindingFile>
> </bindingFiles>
> </defaultOptions>
> <wsdlOptions>
>
> <wsdlOption><wsdl>${project.basedir}/src/main/resources/service1/service1.wsdl</wsdl>
> </wsdlOption>
> </wsdlOptions>
> </configuration>
> <goals>
> <goal>wsdl2java</goal>
> </goals>
> </execution>
> <execution>
> <id>generate-sources-service-2</id>
> <phase>generate-sources</phase>
> <configuration>
> <defaultOptions>
>
> <bindingFiles><bindingFile>${project.basedir}/src/main/resources/service2/binding.xml
> </bindingFile>
> </bindingFiles>
> </defaultOptions>
> <wsdlOptions>
>
> <wsdlOption><wsdl>${project.basedir}/src/main/resources/service2/service2.wsdl</wsdl>
> </wsdlOption>
> </wsdlOptions>
> </configuration>
> <goals>
> <goal>wsdl2java</goal>
> </goals>
> </execution>
> </executions>
> </plugin>
> ...
> {code}
> We have noticed that the same adapter (Adapter1.class) is used for both
> generated classes that possess attributes requiring the annotation
> XmlJavaTypeAdapter. The adapter utilized is
> org/w3/_2001/xmlschema/Adapter1.java, which corresponds to the last execution.
>
> Refer to the example project here: [Example
> Project|https://github.com/PineauSullivan/issue_cfx].
>
> Please let us know if you need more details or any configuration snippets. We
> look forward to your guidance on resolving this issue.
> Thank you!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)