在线WSDL生成Java类结构不一致:CXF插件未生成Header参数
问题:CXF Codegen插件生成的Java方法缺失WSDL定义的Header参数
之前使用org.codehaus.mojo:jaxws-maven-plugin-upd插件从在线WSDL生成Java类,但该插件无法兼容Java 17,因此更换为org.apache.cxf:cxf-codegen-plugin插件。更换后发现生成的Java类结构存在差异:原插件生成的checkService方法包含业务参数和Header参数Context,但新插件生成的同名方法仅包含业务参数,缺失了Header参数。
原插件配置
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin-upd</artifactId> <version>2.5</version> <dependencies> <dependency> <groupId>org.jvnet.jaxb2_commons</groupId> <artifactId>jaxb2-basics</artifactId> <version>0.11.1</version> </dependency> <dependency> <groupId>org.jvnet.jaxb2_commons</groupId> <artifactId>jaxb2-basics-annotate</artifactId> <version>1.1.0</version> </dependency> </dependencies> <executions> <execution> <id>wsimport</id> <goals> <goal>wsimport</goal> </goals> <configuration> <wsdlUrls> <wsdlUrl>http://url-for-file.wsdl</wsdlUrl> </wsdlUrls> <bindingDirectory>src/main/resources</bindingDirectory> <bindingFiles> <bindingFile>jaxb.xjb</bindingFile> </bindingFiles> <sourceDestDir>target/generated-sources/wsimport</sourceDestDir> </configuration> </execution> </executions> </plugin>
新插件配置
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>4.0.3</version> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>4.0.3</version> <scope>compile</scope> </dependency> </dependencies> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <goals> <goal>wsdl2java</goal> </goals> <configuration> <sourceRoot>target/generated-sources/wsimport</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://url-for-file.wsdl</wsdl> <bindingFiles> <bindingFile>src/main/resources/jaxb.xjb</bindingFile> </bindingFiles> </wsdlOption> </wsdlOptions> </configuration> </execution> </executions> </plugin>
WSDL相关片段
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WSDL-name" targetNamespace="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:binding name="AccountsSOAPBinding" type="wstns:AccountsPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Service"> <soap:operation soapAction="Service" style="document"/> <wsdl:input name="ServiceInput"> <soap:body use="literal"/> <soap:header message="wstns:ContextMessage" part="Context" use="literal"/> </wsdl:input> <wsdl:output name="ServiceOutput"> <soap:body use="literal"/> </wsdl:output> <wsdl:fault name="TechnicalFault"> <soap:fault use="literal" name="TechnicalFault"/> </wsdl:fault> <wsdl:fault name="FunctionalFault"> <soap:fault use="literal" name="FunctionalFault"/> </wsdl:fault> </wsdl:operation> </wsdl:binding>
生成代码差异
原插件生成的checkService方法
@WebMethod(operationName = "Service", action = "Service") @WebResult(name = "ResponseDataService", targetNamespace = "", partName = "ServiceResponseMessagePart") public ResponseDataServiceType checkService( @WebParam(name = "RequestDataService", targetNamespace = "", partName = "ServiceRequestMessagePart") RequestDataServiceType serviceRequestMessagePart, @WebParam(name = "Context", targetNamespace = "", header = true, partName = "Context") Context context) throws FunctionalFaultMessage, TechnicalFaultMessage
CXF插件生成的checkService方法
@WebMethod(operationName = "Service", action = "Service") @WebResult(name = "ResponseDataService", targetNamespace = "", partName = "ServiceResponseMessagePart") public ResponseDataServiceType checkService( @WebParam(name = "RequestDataService", targetNamespace = "", partName = "ServiceRequestMessagePart") RequestDataServiceType serviceRequestMessagePart) throws FunctionalFaultMessage, TechnicalFaultMessage
请问是否可以通过调整新插件的配置解决该问题,或者有其他兼容Java 17的插件可以使用?
内容的提问来源于stack exchange,提问作者Sagnik Chatterjee
相关产品推荐
相关产品推荐

