取消编组名称间隔 SOAP XML 参数的问题

我在处理 SOAP 请求时遇到问题。我可以从信封中读取所有内容,但无法解析名称空间修饰参数(cs:measurand)。


在这里,您可以找到 SOAP 信封:


<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cs/2012/06/" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soap:Header>

        <cs:identity>17083A00001101</cs:identity>

        <a:From>

            <a:Address>http://172.0.0.0:9080</a:Address>

        </a:From>

        <a:MessageID>urn:uuid:xxxxxxxxxxxx</a:MessageID>

        <a:ReplyTo>

            <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>

        </a:ReplyTo>

        <a:To>http://172.0.0.0:8080/ws/ocp</a:To>

        <a:Action>/MValues</a:Action>

    </soap:Header>

    <soap:Body>

        <cs:mValuesRequest>

            <cs:id>1</cs:id>

            <cs:transactionId>1881</cs:transactionId>

            <cs:values>

                <cs:timestamp>2019-03-07T13:41:52.405Z</cs:timestamp>

                <cs:value cs:measurand="e.a.i.r" cs:unit="Wh">300</cs:value>

                <cs:value cs:measurand="c.i" cs:unit="Amp">38.5</cs:value>

                <cs:value cs:measurand="v" cs:unit="Volt">399.5</cs:value>

                <cs:value cs:measurand="p.a.i" cs:unit="W">15380</cs:value>

                <cs:value cs:measurand="t" cs:unit="Celsius">35</cs:value>

            </cs:values>

        </cs:mValuesRequest>

    </soap:Body>

</soap:Envelope>


以下是接收请求的服务:


    @Action("/MValues")

    @ResponsePayload

    public JAXBElement<MValuesResponse> receive(@RequestPayload MValuesRequest request,

            MessageContext messageContext) {

....

    }




慕虎7371278
浏览 72回答 2
2回答

胡子哥哥

试试这个,MValuesRequest.java@XmlRootElement(name="cs:mValuesRequest")@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name ="ValuesRequest", propOrder = { "id", "transactionId", "values" })public class MValuesRequest {&nbsp; &nbsp; @XmlElement(name="cs:id")&nbsp; &nbsp; protected int id;&nbsp; &nbsp; @XmlElement(name="cs:transactionId")&nbsp; &nbsp; protected Integer transactionId;&nbsp; &nbsp; @XmlElement(name="cs:values")&nbsp; &nbsp; protected Values values;//&nbsp; getters and setters...}价值观.java@XmlRootElement(name="cs:values")public class Values{&nbsp; &nbsp; @XmlElement(name="cs:timestamp")&nbsp; &nbsp; protected String timestamp;&nbsp; &nbsp; @XmlElement(name="cs:value")&nbsp; &nbsp; protected List<Value> value;//&nbsp; getters and setters...}值.java@XmlRootElement(name="cs:value")public class value{&nbsp; &nbsp; @XmlAttribute(name="measurand" namespace="http://www.w3.org/XML/1998/namespace")&nbsp; &nbsp; protected String measurand;&nbsp; &nbsp; @XmlAttribute(name="unit" namespace="http://www.w3.org/XML/1998/namespace")&nbsp; &nbsp; protected String unit;&nbsp; &nbsp; @XmlValue&nbsp; &nbsp; protected String elementValue;//&nbsp; getters and setters...}

炎炎设计

我终于可以解决这个问题,非常感谢Rathnayake。我不必添加@XmlRootElement而只需将命名空间参数添加到@XmlAttribute。所以目前我的 XML 参数如下所示:&nbsp; &nbsp; @XmlAttribute(name = "context", namespace="urn://Ocpp/Cs/2012/06/")&nbsp; &nbsp; protected ReadingContext context;&nbsp; &nbsp; @XmlAttribute(name = "format", namespace="urn://Ocpp/Cs/2012/06/")&nbsp; &nbsp; protected ValueFormat format;&nbsp; &nbsp; @XmlAttribute(name = "measurand", namespace="urn://Ocpp/Cs/2012/06/")&nbsp; &nbsp; protected Measurand measurand;&nbsp; &nbsp; @XmlAttribute(name = "location", namespace="urn://Ocpp/Cs/2012/06/")&nbsp; &nbsp; protected Location location;&nbsp; &nbsp; @XmlAttribute(name = "unit", namespace="urn://Ocpp/Cs/2012/06/")&nbsp; &nbsp; protected UnitOfMeasure unit;请记住,这是我的 SOAP 标头:<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cs/2012/06/" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">我添加了命名空间=“...”值 xmlns:cs=“...”从标头。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java