gpt4 book ai didi

java - JAXB 解码返回 'URI is not absolute' 错误

转载 作者:数据小太阳 更新时间:2023-10-29 01:56:30 26 4
gpt4 key购买 nike

我从网络服务收到以下响应,并使用以下代码解码响应,但它返回以下错误。

SEVERE:   java.lang.IllegalArgumentException: URI is not absolute

响应

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org
/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchFlightsResponse xmlns="ElsyArres.API">
<SoapMessage>
<Username>TEST</Username>
<Password>TESTs</Password>
<LanguageCode>EN</LanguageCode>
<ErrorMessage />
<ErrorCode>0</ErrorCode>
<AppVersion>8.0.3</AppVersion>
<Request>
<Departure>FDH</Departure>
<Destination>HAM</Destination>
<DepartureDate>2014-08-08</DepartureDate>
<ReturnDate />
<NumADT>1</NumADT>
<NumINF>0</NumINF>
<NumCHD>0</NumCHD>
<CurrencyCode>EUR</CurrencyCode>
<CarrierList />
<FareClasses />
<Providers />
<WaitForResult>true</WaitForResult>
<NearbyDepartures>true</NearbyDepartures>
<NearbyDestinations>true</NearbyDestinations>
<RROnly>false</RROnly>
<MetaSearch>true</MetaSearch>
</Request>
<Response>
<SearchFlightId>140514114543-02-43064-52</SearchFlightId>
<Roundtrip>false</Roundtrip>
<CurrencyCode>EUR</CurrencyCode>
<Flights>
<Flight>
<Outbound>
<CarName>Inter Sky</CarName>
<CarCode>3L</CarCode>
<DepName>Friedrichshafen</DepName>
<DepCode>FDH</DepCode>
<DestName>Hamburg</DestName>
<DestCode>HAM</DestCode>
<Duration>01:45</Duration>
<FlightNo>3L370</FlightNo>
<DepDateTime>2014-08-08T06:10:00</DepDateTime>
<ArrDateTime>2014-08-08T07:55:00</ArrDateTime>
<Legs>
<Leg>
<Sequence>0</Sequence>
<FlightNo>3L370</FlightNo>
<DepCode>FDH</DepCode>
<DepName>Friedrichshafen</DepName>
<DestCode>HAM</DestCode>
<DestName>Hamburg</DestName>
<DepTime>06:10</DepTime>
<ArrTime>07:55</ArrTime>
<CarCode>3L</CarCode>
<CarName>Inter Sky</CarName>
<FareClass>Economy</FareClass>
<ArrDateTime>2014-08-08T07:55:00</ArrDateTime>
<DepDateTime>2014-08-08T06:10:00</DepDateTime>
</Leg>
</Legs>
<Taxes>0</Taxes>
<FareADT>6500</FareADT>
<FareCHD>0</FareCHD>
<FareINF>0</FareINF>
<MiscFees>6400</MiscFees>
<Idx>307963</Idx>
<FareClass>Economy</FareClass>
<FareType>Web</FareType>
<FareId>3L0</FareId>
</Outbound>
<BagFee>0</BagFee>
<CcFee>600</CcFee>
<HandlingFee>500</HandlingFee>
<TotalFare>12900</TotalFare>
<FlightId>140514114543-02-21212-2</FlightId>
<Link2Book>http://sample.com</Link2Book>
<Provider>ElsyArres</Provider>
</Flight>
<Flight>
<Outbound>
<CarName>Inter Sky</CarName>
<CarCode>3L</CarCode>
<DepName>Friedrichshafen</DepName>
<DepCode>FDH</DepCode>
<DestName>Hamburg</DestName>
<DestCode>HAM</DestCode>
<Duration>01:45</Duration>
<FlightNo>3L376</FlightNo>
<DepDateTime>2014-08-08T18:00:00</DepDateTime>
<ArrDateTime>2014-08-08T19:45:00</ArrDateTime>
<Legs>
<Leg>
<Sequence>0</Sequence>
<FlightNo>3L376</FlightNo>
<DepCode>FDH</DepCode>
<DepName>Friedrichshafen</DepName>
<DestCode>HAM</DestCode>
<DestName>Hamburg</DestName>
<DepTime>18:00</DepTime>
<ArrTime>19:45</ArrTime>
<CarCode>3L</CarCode>
<CarName>Inter Sky</CarName>
<FareClass>Economy</FareClass>
<ArrDateTime>2014-08-08T19:45:00</ArrDateTime>
<DepDateTime>2014-08-08T18:00:00</DepDateTime>
</Leg>
</Legs>
<Taxes>0</Taxes>
<FareADT>10500</FareADT>
<FareCHD>0</FareCHD>
<FareINF>0</FareINF>
<MiscFees>6400</MiscFees>
<Idx>307964</Idx>
<FareClass>Economy</FareClass>
<FareType>Web</FareType>
<FareId>3L0</FareId>
</Outbound>
<BagFee>0</BagFee>
<CcFee>600</CcFee>
<HandlingFee>500</HandlingFee>
<TotalFare>16900</TotalFare>
<FlightId>140514114543-02-21212-3</FlightId>
<Link2Book>http://sample.com</Link2Book>
<Provider>ElsyArres</Provider>
</Flight>
</Flights>
</Response>
</SoapMessage>
</SearchFlightsResponse>
</soap:Body>
</soap:Envelope>

package-info.java

@XmlSchema( 
namespace = "http://testv80.elsyarres.net/service.asmx",
elementFormDefault = XmlNsForm.QUALIFIED)
package com.myProject.wegolo

import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

代码

        ...
SOAPMessage sm = response;
ByteArrayOutputStream out = new ByteArrayOutputStream();
sm.writeTo(out);

this.results = (SearchFlightsResponse) JAXB.unmarshal(sm.toString(), SearchFlightsResponse.class);

最佳答案

您从 SOAP 服务收到的 XML 响应不是有效的 XML。 xmlns 属性必须是绝对的 URI .

这意味着命名空间名称必须采用以下形式:<scheme>:<scheme-specific-part>

为了使 XML 有效,您调用的服务应该发回 urn:ElsyArres.API作为命名空间值。

<SearchFlightsResponse xmlns="urn:ElsyArres.API">

您的包信息文件将如下所示:

@XmlSchema( 
namespace = "urn:ElsyArres.API",
elementFormDefault = XmlNsForm.QUALIFIED)
package com.myProject.wegolo

import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

如果您无法获得修复 URI 问题的服务,您可以在通过使用 SAXFilter 解码时将其删除。这是一个很好的例子,它支持在解码期间添加和删除 namespace :https://stackoverflow.com/a/2148541/73446

关于java - JAXB 解码返回 'URI is not absolute' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23652823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com