简体   繁体   English

无法更改生成的类的SOAP客户端请求参数

[英]Can't change SOAP-Client Request parameters of generated classes

i have implemented a SOAP Webservice and have tested it successfully with SOAP UI. 我已经实现了SOAP Web服务,并已通过SOAP UI成功对其进行了测试。 Now i want to generate the client classes with netbeans wsimport by URL (glassfish with webservice is on of course). 现在,我想使用URL通过netbeans wsimport生成客户端类(当然,带有webservice的glassfish)。 The generation runs successfully, but i can't change parameters of the RecommendationRequest -complextype. 生成成功运行,但是我无法更改RecommendationRequest -complextype的参数。 This is my client-code: 这是我的客户代码:

RecommendationService service = new RecommendationService();
ShitstormRec recommenderPort = service.getRecommenderPort();

ObjectFactory factory = new ObjectFactory();
Goal g1 = factory.createGoal(); // runs
        g1.setGoal("cost"); // runs perfectly, can set the value
        g1.setPrio(1); // runs perfectly, can set the value

RecommendationRequest request = factory.createRecommendationRequest();
        request.setVariables // no setter was generated, can't use any setters!!!
recommenderPort.getRecommendation(request); // so i can't send a meaningful request with adjusted parameters, because of missing generated setter-Methods from request.

How can this be? 怎么会这样? Every Object works fine, but only the most important argument is not able to change. 每个对象都可以正常工作,但是只有最重要的参数无法更改。 These are my serverside classes: 这些是我的服务器端类:

This is my WebService-Interface: 这是我的WebService-Interface:

@WebService(name = "ShitstormRec",
        targetNamespace = "http://shitstormrec.org")
public interface IRecommendationService {

    @WebMethod
    @WebResult(name = "recommendations")
    public List<Recommendation> getRecommendation(
            @WebParam(name = "recommendationRequest") RecommendationRequest request);

    @WebMethod
    @WebResult(name = "say")
    public String sayCiao();
}

Implementation of the web service: Web服务的实现:

@WebService(serviceName = "RecommendationService",
        portName = "RecommenderPort",
        endpointInterface = "org.andy.services.IRecommendationService")
public class RecommendationService implements IRecommendationService {

    private Recommender recommender = new Recommender();

    @Override
    public List<Recommendation> getRecommendation(RecommendationRequest request) {
        return recommender.recommend(request);
    }

    @Override
    public String sayCiao() {
        return "ciao";
    }

}

The server-side Goal object: 服务器端目标对象:

@XmlRootElement(name = "goal")
public class Goal implements Serializable {

    private int prio;
    private String goal;

    public Goal() {
    }

    public int getPrio() {
        return prio;
    }

    public void setPrio(int prio) {
        this.prio = prio;
    }

    public String getGoal() {
        return goal;
    }

    public void setGoal(String goal) {
        this.goal = goal;
    }

}

The server-side-object, where no setter is available for generated client classes: 服务器端对象,其中没有可用于生成的客户端类的设置器:

@XmlRootElement(name = "recommendationRequest")
public class RecommendationRequest implements Serializable {

    private List<ProcessVariable> variables;
    private List<Goal> goals;

    public RecommendationRequest() {
    }

    public RecommendationRequest(List<ProcessVariable> variables, List<Goal> goals) {
        this.variables = variables;
        this.goals = goals;
    }

    public List<ProcessVariable> getVariables() {
        return variables;
    }

    public void setVariables(List<ProcessVariable> variables) {
        this.variables = variables;
    }

    public List<Goal> getGoals() {
        return goals;
    }

    public void setGoals(List<Goal> goals) {
        this.goals = goals;
    }

}

The wsdl: wsdl:

<definitions targetNamespace="http://services.andy.org/" name="RecommendationService">
    <import namespace="http://shitstormrec.org" location="http://localhost:9090/ShitstormRec/RecommendationService?wsdl=1"/>
    <binding name="RecommenderPortBinding" type="ns1:ShitstormRec">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="getRecommendation">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <operation name="sayCiao">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="RecommendationService">
        <port name="RecommenderPort" binding="tns:RecommenderPortBinding">
            <soap:address location="http://localhost:9090/ShitstormRec/RecommendationService"/>
        </port>
    </service>
</definitions>

The referenced wsdl from above: 上面引用的wsdl:

<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.2-b608 (trunk-7979; 2015-01-21T12:50:19+0000) JAXWS-RI/2.2.11-b150120.1832 JAXWS-API/2.2.12 JAXB-RI/2.2.12-b141219.1637 JAXB-API/2.2.13-b141020.1521 svn-revision#unknown. 
--><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.2-b608 (trunk-7979; 2015-01-21T12:50:19+0000) JAXWS-RI/2.2.11-b150120.1832 JAXWS-API/2.2.12 JAXB-RI/2.2.12-b141219.1637 JAXB-API/2.2.13-b141020.1521 svn-revision#unknown. 
--><definitions targetNamespace="http://shitstormrec.org">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://shitstormrec.org" schemaLocation="http://localhost:9090/ShitstormRec/RecommendationService?xsd=1"/>
        </xsd:schema>
    </types>
    <message name="getRecommendation">
        <part name="parameters" element="tns:getRecommendation"/>
    </message>
    <message name="getRecommendationResponse">
        <part name="parameters" element="tns:getRecommendationResponse"/>
    </message>
    <message name="sayCiao">
        <part name="parameters" element="tns:sayCiao"/>
    </message>
    <message name="sayCiaoResponse">
        <part name="parameters" element="tns:sayCiaoResponse"/>
    </message>
    <portType name="ShitstormRec">
        <operation name="getRecommendation">
            <input ns1:Action="http://shitstormrec.org/ShitstormRec/getRecommendationRequest" message="tns:getRecommendation"/>
            <output ns2:Action="http://shitstormrec.org/ShitstormRec/getRecommendationResponse" message="tns:getRecommendationResponse"/>
        </operation>
        <operation name="sayCiao">
            <input ns3:Action="http://shitstormrec.org/ShitstormRec/sayCiaoRequest" message="tns:sayCiao"/>
            <output ns4:Action="http://shitstormrec.org/ShitstormRec/sayCiaoResponse" message="tns:sayCiaoResponse"/>
        </operation>
    </portType>
</definitions>

The XSD-Schema: XSD模式:

<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.2-b608 (trunk-7979; 2015-01-21T12:50:19+0000) JAXWS-RI/2.2.11-b150120.1832 JAXWS-API/2.2.12 JAXB-RI/2.2.12-b141219.1637 JAXB-API/2.2.13-b141020.1521 svn-revision#unknown. 
--><xs:schema version="1.0" targetNamespace="http://shitstormrec.org">
    <xs:element name="getRecommendation" type="tns:getRecommendation"/>
    <xs:element name="getRecommendationResponse" type="tns:getRecommendationResponse"/>
    <xs:element name="goal" type="tns:goal"/>
    <xs:element name="processVariable" type="tns:processVariable"/>
    <xs:element name="recommendation" type="tns:recommendation"/>
    <xs:element name="recommendationRequest" type="tns:recommendationRequest"/>
    <xs:element name="sayCiao" type="tns:sayCiao"/>
    <xs:element name="sayCiaoResponse" type="tns:sayCiaoResponse"/>
    <xs:complexType name="sayCiao">
        <xs:sequence/>
    </xs:complexType>
    <xs:complexType name="sayCiaoResponse">
        <xs:sequence>
            <xs:element name="say" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="getRecommendation">
        <xs:sequence>
            <xs:element name="recommendationRequest" type="tns:recommendationRequest" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="recommendationRequest">
        <xs:sequence>
            <xs:element name="goals" type="tns:goal" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="variables" type="tns:processVariable" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="goal">
        <xs:sequence>
            <xs:element name="goal" type="xs:string" minOccurs="0"/>
            <xs:element name="prio" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="processVariable">
        <xs:sequence>
            <xs:element name="name" type="xs:string" minOccurs="0"/>
            <xs:element name="type" type="tns:variableType" minOccurs="0"/>
            <xs:element name="value" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="getRecommendationResponse">
        <xs:sequence>
            <xs:element name="recommendations" type="tns:recommendation" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="recommendation">
        <xs:sequence>
            <xs:element name="benefit" type="xs:int"/>
            <xs:element name="information" type="xs:string" minOccurs="0"/>
            <xs:element name="taskName" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:simpleType name="variableType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="STRING"/>
            <xs:enumeration value="INTEGER"/>
            <xs:enumeration value="DOUBLE"/>
            <xs:enumeration value="OBJECT"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

Have i done a mistake? 我做错了吗?

Thanks a lot for your help =) 非常感谢您的帮助=)

I have found the solution. 我找到了解决方案。 Everything ist correct, was just an error in reasoning. 一切正确,只是推理上的错误。 I just need to get the Variables List and add something. 我只需要获取变量列表并添加一些内容即可。 I was confused about the missing setters. 我对失踪的二传手感到困惑。

RecommendationRequest request = factory.createRecommendationRequest();
        request.setVariables // setter was not available 

// Instead i used:
request.getVariables().add(object_to_add)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM