【问题标题】:Spring Boot - maven-jaxb2-plugin not generaing all classes - requests and responses for WSDLSpring Boot - maven-jaxb2-plugin 不生成所有类 - WSDL 的请求和响应
【发布时间】:2023-02-06 04:53:04
【问题描述】:

我们有一个由 API 提供商提供的 WSDL 示例,我们希望与其集成。
我在 https://spring.io/guides/gs/consuming-web-service/ 和其他一些 .wsdl 文件中尝试了提供的示例,一切看起来都不错。
在我使用 wsdl 的情况下 - 当运行命令生成类时 - 只生成了其中的一些,而不是全部。
在 SoapUI 中情况并非如此 - 那里一切都很好。
任何信息为什么会这样?

我的 pom.xml 如下

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generatePackage>com.test.xxx.soapclient.generated</generatePackage>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

我所看到的是,只有 complex types 被创建为类——而其他的则没有。 在我的示例中,输入消息是下面的消息,并且没有为其生成任何类。
我怎样才能做到这一点? 另外这里有趣的是——soapAction 有空字符串作为参数——Java 的 API 需要 SoapAction Java代码

 public Object callWebService(String action, Object request){
        return getWebServiceTemplate().marshalSendAndReceive(request,new SoapActionCallback(action));
    }

实际的 WSDL 文件

<operation name="login" parameterOrder="user password">
  <input message="tns:CardManagementEP_login"> </input>
  <output message="tns:CardManagementEP_loginResponse"> </output>
</operation>

<message name="CardManagementEP_loginResponse">
<part name="result" type="xsd:string"> </part>
</message>

<message name="CardManagementEP_login">
<part name="user" type="xsd:string"> </part>
<part name="password" type="xsd:string"> </part>
</message>

<operation name="login">
  <soap:operation soapAction=""/>
  <input>
  <soap:body use="literal" namespace="http://com.tch.cards.service"/>
  </input>
  <output>
  <soap:body use="literal" namespace="http://com.tch.cards.service"/>
  </output>
</operation>

【问题讨论】:

    标签: spring-boot soap soap-client


    【解决方案1】:

    在 Spring Office Hours 节目中的 DaShaun Carter 的帮助下,我设法解决了这个问题。
    问题是上面提到的 WSDL 文件真的很旧,所以没有生成不复杂的请求/响应类。
    我们所做的是修改现有的 WSDL 并将这些东西创建为复杂类型——因此 Jaxb 将为它们生成类

    example-wsdl.wsdl

    <complexType name="login">
        <sequence>
            <element name="user" type="string"/>
            <element name="password" type="string"/>
        </sequence>
    </complexType>
    <complexType name="loginResponse">
        <sequence>
            <element name="result" type="string"/>
        </sequence>
    </complexType>
    

    在那之后,类正在生成,但它们对我不起作用,我不得不进行一些手动更改才能使它们工作
    LoginResponse.java

    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "loginResponse", namespace = "http://com.tch.cards.service")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class LoginResponse {
    
        @XmlElement(required = true)
        protected String result;
        public String getResult() {
            return result;
        }
        public void setResult(String value) {
            this.result = value;
        }
    }
    

    Login

    import javax.xml.bind.annotation.*;
    @XmlRootElement(name = "login", namespace = "http://com.tch.cards.service")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Login {
    
        @XmlElement(required = true)
        protected String user;
        @XmlElement(required = true)
        protected String password;
        public String getUser() {
            return user;
        }
        public void setUser(String value) {
            this.user = value;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String value) {
            this.password = value;
        }
    }
    

    另外,就我而言,Soap Action 并不重要,我传递的是空字符串。
    实际调用发生的代码如下:

    Login login = new Login();
    login.setUser("user");
    login.setPassword("password");
    LoginResponse response = (LoginResponse) soapConnector.callWebService("", login);
    System.out.println(response);
    

    重要说明:根据用例更改名称空间 - 这非常重要

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      相关资源
      最近更新 更多