SOAP响应将对象包装为<return>,而不是类名称

时间:2018-12-05 20:11:46

标签: java intellij-idea soap jaxb wsdl

我正在使用CODE FIRST方法创建SOAP服务。所有XML由IntelliJ自动生成,然后通过生成的WAR部署在GlassFish上。 我有这样声明的基本实体消息

@XmlRootElement
@XmlType(propOrder={"id", "content", "created", "author"})
public class Message {
    private long id;
    private String content;
    private Date created;
    private String author;

    public Message() {
        this.created = new Date();
    }
    public Message(long id, String content, String author) {
        this.id = id;
        this.content = content;
        this.created = new Date();
        this.author = author;
    }
    @XmlElement
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    @XmlElement
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @XmlElement
    public Date getCreated() {
        return created;
    }
    private void setCreated(Date created) {
        this.created = created;
    }
    @XmlElement
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}

在使用JAXB编组的应用程序中,返回如下对象:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message>
    <id>1</id>
    <content>Content</content>
    <created>2018-12-05T20:58:18.012+01:00</created>
    <author>Author</author>
</message>

但是当我通过服务检索一条消息时,它将消息包装在返回标记中,就像它不是类对象一样:

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <S:Body xmlns:ns2="http://service/">
        <ns2:getMessageResponse>
            <return>
                <id>1</id>
                <content>dada</content>
                <created>2018-12-05T20:45:23.043+01:00</created>
                <author>Kamil Kot</author>
            </return>
        </ns2:getMessageResponse>
    </S:Body>
</S:Envelope> 

生成的WSDL:

<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<!--
 Generated by JAX-WS RI (http://javaee.github.io/metro-jax-ws). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service/" name="MessageWSImplService">
<style type="text/css" id="night-mode-pro-style"/>
<link type="text/css" rel="stylesheet" id="night-mode-pro-link"/>
<types>
<xsd:schema>
<xsd:import namespace="http://service/" schemaLocation="http://507f3cda.ngrok.io:80/JAXWS_MessageServieArtifact/MessageWSImplService?xsd=1"/>
</xsd:schema>
</types>
<message name="getMessage">
<part name="parameters" element="tns:getMessage"/>
</message>
<message name="getMessageResponse">
<part name="parameters" element="tns:getMessageResponse"/>
</message>
<message name="deleteAllMessages">
<part name="parameters" element="tns:deleteAllMessages"/>
</message>
<message name="deleteAllMessagesResponse">
<part name="parameters" element="tns:deleteAllMessagesResponse"/>
</message>
<message name="createMessage">
<part name="parameters" element="tns:createMessage"/>
</message>
<message name="createMessageResponse">
<part name="parameters" element="tns:createMessageResponse"/>
</message>
<message name="updateMessage">
<part name="parameters" element="tns:updateMessage"/>
</message>
<message name="updateMessageResponse">
<part name="parameters" element="tns:updateMessageResponse"/>
</message>
<message name="deleteMessage">
<part name="parameters" element="tns:deleteMessage"/>
</message>
<message name="deleteMessageResponse">
<part name="parameters" element="tns:deleteMessageResponse"/>
</message>
<message name="getAllMessages">
<part name="parameters" element="tns:getAllMessages"/>
</message>
<message name="getAllMessagesResponse">
<part name="parameters" element="tns:getAllMessagesResponse"/>
</message>
<portType name="MessageWSImpl">
<operation name="getMessage">
<input wsam:Action="http://service/MessageWSImpl/getMessageRequest" message="tns:getMessage"/>
<output wsam:Action="http://service/MessageWSImpl/getMessageResponse" message="tns:getMessageResponse"/>
</operation>
<operation name="deleteAllMessages">
<input wsam:Action="http://service/MessageWSImpl/deleteAllMessagesRequest" message="tns:deleteAllMessages"/>
<output wsam:Action="http://service/MessageWSImpl/deleteAllMessagesResponse" message="tns:deleteAllMessagesResponse"/>
</operation>
<operation name="createMessage">
<input wsam:Action="http://service/MessageWSImpl/createMessageRequest" message="tns:createMessage"/>
<output wsam:Action="http://service/MessageWSImpl/createMessageResponse" message="tns:createMessageResponse"/>
</operation>
<operation name="updateMessage">
<input wsam:Action="http://service/MessageWSImpl/updateMessageRequest" message="tns:updateMessage"/>
<output wsam:Action="http://service/MessageWSImpl/updateMessageResponse" message="tns:updateMessageResponse"/>
</operation>
<operation name="deleteMessage">
<input wsam:Action="http://service/MessageWSImpl/deleteMessageRequest" message="tns:deleteMessage"/>
<output wsam:Action="http://service/MessageWSImpl/deleteMessageResponse" message="tns:deleteMessageResponse"/>
</operation>
<operation name="getAllMessages">
<input wsam:Action="http://service/MessageWSImpl/getAllMessagesRequest" message="tns:getAllMessages"/>
<output wsam:Action="http://service/MessageWSImpl/getAllMessagesResponse" message="tns:getAllMessagesResponse"/>
</operation>
</portType>
<binding name="MessageWSImplPortBinding" type="tns:MessageWSImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getMessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="deleteAllMessages">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="createMessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="updateMessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="deleteMessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getAllMessages">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MessageWSImplService">
<port name="MessageWSImplPort" binding="tns:MessageWSImplPortBinding">
<soap:address location="http://507f3cda.ngrok.io:80/JAXWS_MessageServieArtifact/MessageWSImplService"/>
</port>
</service>
</definitions>

我认为我缺少有关绑定的信息,而且我不知道如何使JAXB将我的类视为ComplexType。我已经搜索了数小时的解决方案,但仍然找不到。 id再次希望使IntelliJ生成正确的方式,因为我想避免对WSDL本身进行更改。 我真的会对此有所帮助。

0 个答案:

没有答案