Ответ SOAP оборачивает объекты в <return>, а не в имя класса - PullRequest
0 голосов
/ 05 декабря 2018

Я создаю сервис SOAP, используя подход CODE FIRST.Весь XML автоматически генерируется IntelliJ, а затем разворачивается на GlassFish с созданным WAR.У меня есть базовая сущность Mesage , объявленная так:

@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.Я искал решение в течение нескольких часов, и я до сих пор не могу его найти.Еще раз хочу, чтобы IntelliJ генерировал его правильно, так как я хочу избежать внесения изменений в сам WSDL.Я действительно оценил бы любую помощь с этим.

...