J88*_*888 5 java xml web-services jaxb unmarshalling
我从webservice收到以下响应,并使用以下代码来解组响应,但它返回以下错误.
SEVERE: java.lang.IllegalArgumentException: URI is not absolute
Run Code Online (Sandbox Code Playgroud)
响应
<?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>
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)
码
...
SOAPMessage sm = response;
ByteArrayOutputStream out = new ByteArrayOutputStream();
sm.writeTo(out);
this.results = (SearchFlightsResponse) JAXB.unmarshal(sm.toString(), SearchFlightsResponse.class);
Run Code Online (Sandbox Code Playgroud)
以下行是导致您出现问题的原因:
JAXB.unmarshal(sm.toString(), SearchFlightsResponse.class);
Run Code Online (Sandbox Code Playgroud)
结果sm.toString()将类似于以下内容,而不是StringXML 的表示形式。
com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl@693f23a2
Run Code Online (Sandbox Code Playgroud)
您现在所做的相当于执行以下操作:
import javax.xml.bind.JAXB;
public class Demo {
public static void main(String[] args) throws Exception {
JAXB.unmarshal("com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl@693f23a2", Foo.class);
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1095)
at javax.xml.bind.JAXB.toSource(JAXB.java:291)
at javax.xml.bind.JAXB.unmarshal(JAXB.java:205)
at forum23652823.Demo.main(Demo.java:8)
Run Code Online (Sandbox Code Playgroud)
笔记
String该方法中的参数是JAXB.unmarshal(String, Class)XML 的位置,而不是 XML 本身。这就是异常抱怨 URI 的原因。
| 归档时间: |
|
| 查看次数: |
2672 次 |
| 最近记录: |