解析XM返回URI不是绝对的

时间:2014-04-08 11:43:01

标签: java soap parsexml

我正在尝试解析以下soap响应,但代码返回以下异常

SEVERE:   java.lang.IllegalArgumentException: URI is not absolute
    at java.net.URI.toURL(URI.java:1095)
    at javax.xml.bind.JAXB.toSource(JAXB.java:306)
    at javax.xml.bind.JAXB.unmarshal(JAXB.java:220)
    ......

响应

<?xml version="1.0" encoding="utf-8"?>
<SearchFlightsResponse xmlns="ElsyArres.API">
     <SoapMessage>
         <Username>Test</Username>
         <Password>Test</Password>
         <LanguageCode>EN</LanguageCode>
         <ErrorMessage />
         <ErrorCode>0</ErrorCode>
         <AppVersion>8.0.3</AppVersion>
         <Request>
             <Departure>BER</Departure>
             <Destination>LON</Destination>
             <DepartureDate>2014-10-18</DepartureDate>
             <ReturnDate />
             <NumADT>1</NumADT>
             <NumINF>0</NumINF>
             <NumCHD>0</NumCHD>
             <CurrencyCode>EUR</CurrencyCode>
             <CarrierList />
             <FareClasses />
             <Providers />
             <WaitForResult>true</WaitForResult>
             <NearbyDepartures>false</NearbyDepartures>
             <NearbyDestinations>false</NearbyDestinations>
             <RROnly>false</RROnly>
             <MetaSearch>false</MetaSearch>
        </Request>
        <Response>
             <SearchFlightId>140408111958-02-11428-310</SearchFlightId>
             <Roundtrip>false</Roundtrip>
             <CurrencyCode>EUR</CurrencyCode>
             <Flights>
                <Flight>
                <Outbound>
                    <CarName>Test Airline</CarName>
                    <CarCode>_2</CarCode>
                    <DepName>Berlin</DepName>
                    <DepCode>BER</DepCode>
                    <DestName>London</DestName>
                    <DestCode>LON</DestCode>
                    .....

代码

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


        this.results = (SearchFlightsResponse) JAXB.unmarshal(sm.toString(), SearchFlightsResponse.class);
        System.err.println(">" + results.getSoapMessage().getUsername());

响应类

@XmlRootElement(name="SearchFlightsResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class SearchFlightsResponse {
    @XmlElement(name = "SoapMessage")
    private SoapMessage soapMessage;
    .....

@XmlRootElement(name="SoapMessage")
@XmlAccessorType(XmlAccessType.FIELD)
public class SoapMessage {
    @XmlElement(name="Username")
    private String username;
    @XmlElement(name="Password")
    private String password;
    ....

package-info.java

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

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

1 个答案:

答案 0 :(得分:0)

XML命名空间 - xmlns属性应遵循URL约定,例如&#34; file:&#34;,&#34; classpath:&#34;,&#34; http://& #34;,&#34; ftp://&#34;,&#34; db:&#34;。

在你的情况下,它不是。

请参阅http://openrules.com/rulesrepository.htm