2016-01-16 4 views
12

के साथ एक्सएमएल संदेश का विश्लेषण नहीं कर सकता है। मैं साबुन प्रतिक्रिया को पार्स करने के लिए निम्नलिखित कोड का उपयोग कर रहा हूं लेकिन मुझे UnmarshallingFailureException प्राप्त हो रहा है, मैंने @XmlSeeAlso को @XMLRootElement में बदल दिया है लेकिन समस्या अभी भी बनी हुई है। डब्ल्यूएसडीएल here है।जेएक्सबी org.springframework.oxm.UnmarshallingFailureException

Caused by: javax.xml.bind.UnmarshalException: unexpected element 
     (uri:"ElsyArres.API", local:"SearchFlightsResponse"). Expected elements are 
     <{ElsyArres.API}Inbound>,<{ElsyArres.API}Leg>,<{ElsyArres.API}Legs>, 
     <{ElsyArres.API}Outbound>,<{ElsyArres.API}Request>,<{ElsyArres.API}Response>, 
     <{ElsyArres.API}SearchFlights>,<{ElsyArres.API}SoapMessage> 

कोड

@XmlRootElement(name = "SoapMessage") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class WegoloSoapMessageResponse { 
     @XmlElement(name = "Username") 
     private String username; 
     @XmlElement(name = "Password") 
     private String password; 
     @XmlElement(name = "LanguageCode") 
     private String languageCode; 
     @XmlElement(name = "ErrorMessage") 
     private String errorMessage; 
     @XmlElement(name = "ErrorCode") 
     private int errorCode; 
     @XmlElement(name = "AppVersion") 
     private String appVersion; 
     @XmlElement(name = "Request") 
     private Request request; 
     @XmlElement(name = "Response") 
     private Response response; 

     getters and setters 


    @XmlRootElement(name = "Request") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Request { 
     @XmlElement(name = "Departure") 
     private String departure; 
     @XmlElement(name = "Destination") 
     private String destination; 
     @XmlElement(name = "DepartureDate") 
     private String departureDate; 
     @XmlElement(name = "ReturnDate") 
     private String returnDate; 
     @XmlElement(name = "NumADT") 
     private int numADT; 
     @XmlElement(name = "NumINF") 
     private int numInf; 
     @XmlElement(name = "NumCHD") 
     private int numCHD; 
     @XmlElement(name = "CurrencyCode") 
     private String currencyCode; 
     @XmlElement(name = "WaitForResult") 
     private boolean waitForResult; 
     @XmlElement(name = "NearByDepartures") 
     private boolean nearByDepartures; 
     @XmlElement(name = "NearByDestinations") 
     private boolean nearByDestinations; 
     @XmlElement(name = "RROnly") 
     private boolean rronly; 
     @XmlElement(name = "MetaSearch") 
     private boolean metaSearch; 

     getters and setters 


    @XmlRootElement(name="Response") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Response { 
     @XmlElement(name="SearchFlightId") 
     private String searchFlightId; 
     @XmlElement(name="Roundtrip") 
     private boolean roundTrip; 
     @XmlElement(name="CurrencyCode") 
     private String currencyCode; 
     @XmlElement(name="Flights") 
     private Flights flights; 

     getters and setters 



    @XmlSeeAlso(Flight.class) 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Flights { 
     @XmlElement(name="Flight") 
     private List<Flight> flight; 

     getter and setter 



    @XmlSeeAlso(Outbound.class) 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Flight { 

     @XmlElement(name = "Outbound") 
     private Outbound outbound; 
     @XmlElement(name="Inbound") 
     private Inbound inbound; 
     @XmlElement(name = "BagFee") 
     private int bagFee; 
     @XmlElement(name = "CcFee") 
     private int ccFee; 
     @XmlElement(name = "HandlingFee") 
     private int handlingFee; 
     @XmlElement(name = "TotalFare") 
     private int totalFare; 
     @XmlElement(name = "FlightId") 
     private String flightId; 
     @XmlElement(name = "Link2Book") 
     private String link2Book; 
     @XmlElement(name = "Provider") 
     private String provider; 

     getters and setters 




    @XmlRootElement(name = "Outbound") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Outbound { 

     @XmlElement(name="CarName") 
     private String carName; 
     @XmlElement(name="CarCode") 
     private String carCode; 
     @XmlElement(name="DepName") 
     private String depName; 
     @XmlElement(name="DepCode") 
     private String depCode; 
     @XmlElement(name="DestName") 
     private String destName; 
     @XmlElement(name="DestCode") 
     private String destCode; 
     @XmlElement(name="Duration") 
     private String duration; 
     @XmlElement(name="FlightNo") 
     private String flightNo; 
     @XmlElement(name="DepDateTime") 
     private Date dapDateTime; 
     @XmlElement(name="ArrDateTime") 
     private Date arrDateTime; 
     @XmlElement(name="Legs") 
     private Legs legs; 
     @XmlElement(name="Taxes") 
     private int taxes; 
     @XmlElement(name="FareADT") 
     private int fareADT; 
     @XmlElement(name="FareCHD") 
     private int fareCHD; 
     @XmlElement(name="FareINF") 
     private int fareInf; 
     @XmlElement(name="MiscFees") 
     private int miscFees; 
     @XmlElement(name="Idx") 
     private int idx; 
     @XmlElement(name="FareClass") 
     private String fareClass; 
     @XmlElement(name="FareType") 
     private String fareType; 
     @XmlElement(name="FareId") 
     private String fareId; 

     getters and setters 



    @XmlRootElement(name="Legs") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Legs { 
     @XmlElement(name="Leg") 
     private Leg leg; 

     getter and setter 



    @XmlRootElement(name="Leg") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Leg { 
     @XmlElement(name="Sequence") 
     private int sequence; 
     @XmlElement(name="FlightNo") 
     private String flightNo; 
     @XmlElement(name="DepCode") 
     private String depCode; 
     @XmlElement(name="DepName") 
     private String depName; 
     @XmlElement(name="DestCode") 
     private String destCode; 
     @XmlElement(name="DestName") 
     private String destName; 
     @XmlElement(name="DepTime") 
     private String depTime; 
     @XmlElement(name="ArrTime") 
     private String arrTime; 
     @XmlElement(name="CarCode") 
     private String carCode; 
     @XmlElement(name="CarName") 
     private String carName; 
     @XmlElement(name="FareClass") 
     private String fareClass; 
     @XmlElement(name="ArrDateTime") 
     private Date arrDateTime; 
     @XmlElement(name="DepDateTime") 
     private Date depDateTime; 

     getters and setters 



    @XmlRootElement(name = "Inbound") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Inbound { 
     @XmlElement(name="CarName") 
     private String carName; 
     @XmlElement(name="CarCode") 
     private String carCode; 
     @XmlElement(name="DepName") 
     private String depName; 
     @XmlElement(name="DepCode") 
     private String depCode; 
     @XmlElement(name="DestName") 
     private String destName; 
     @XmlElement(name="DestCode") 
     private String destCode; 
     @XmlElement(name="Duration") 
     private String duration; 
     @XmlElement(name="FlightNo") 
     private String flightNo; 
     @XmlElement(name="DepDateTime") 
     private Date dapDateTime; 
     @XmlElement(name="ArrDateTime") 
     private Date arrDateTime; 
     @XmlElement(name="Legs") 
     private Legs legs; 
     @XmlElement(name="Taxes") 
     private int taxes; 
     @XmlElement(name="FareADT") 
     private int fareADT; 
     @XmlElement(name="FareCHD") 
     private int fareCHD; 
     @XmlElement(name="FareINF") 
     private int fareInf; 
     @XmlElement(name="MiscFees") 
     private int miscFees; 
     @XmlElement(name="Idx") 
     private int idx; 
     @XmlElement(name="FareClass") 
     private String fareClass; 
     @XmlElement(name="FareType") 
     private String fareType; 
     @XmlElement(name="FareId") 
     private String fareId; 

     gettes and setters 

jaxb.index

SearchFlights 
Flight 
Flights 
Leg 
Legs 
Outbound 
Request 
Response 
WegoloSoapMessage 

package-info.java

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

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

रिस्पांस

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

+0

इस लिंक पर एक नज़र डालें है: http://stackoverflow.com/questions/32181738/unmarshallingfailureexception-jaxb-unmarshalling -exception-nested-upgrade- – AbhishekAsh

उत्तर

1

यह आप मैन्युअल रूप से या कम से कम अपने सेम पैदा कर रहे उन्हें संपादित कर रहे हैं लगता है। दोनों मामलों से बचा जाना चाहिए। इसके बजाय आपको अपने लिए जैक्सबी कक्षाएं और साबुन क्लाइंट जेनरेट करने के लिए उपलब्ध टूल का उपयोग करने का प्रयास करना चाहिए। दो बहुत ही सामान्य विकल्प spring webservices या प्रसिद्ध Apache CXF framework हैं।

+0

आपके उत्तर के लिए धन्यवाद, मैं इसे मैवेन के माध्यम से उत्पन्न करने की कोशिश कर रहा हूं लेकिन मेरे पास एक और समस्या है जिसे आप यहां देख सकते हैं http://stackoverflow.com/questions/35108965/how-to-use- एक-वर्ग-अनुकूलन करने के लिए संकल्प-फ़ाइल-जनरेट संघर्ष –

3

त्रुटि संदेश राज्यों, आप स्थानीय नोड पार्स करने के लिए कोशिश कर रहे हैं कि searchflightsresponse जो आप अपनी कक्षाओं में एक एनोटेशन के रूप में मानचित्र नहीं बनाते हैं।

आपको इस नोड को घोषित करना होगा जैसा कि आपने इसे पहले किया है।

कृपया ध्यान दें कि साबुन प्रतिक्रिया को पार्स करने के लिए यहां जैक्सब का उपयोग करने की सलाह नहीं दी जाती है क्योंकि संरचना (जैसा कि आप देख सकते हैं) तुच्छ नहीं है। मैं wsdl डाउनलोड करने और webservice से मेल खाने के लिए क्लाइंट स्टब्स उत्पन्न करने का सुझाव देता हूं। तब आपको सैकड़ों सदस्यों और कक्षाओं को एनोटेट करने की आवश्यकता नहीं होगी।

भी यहाँ देखें: How to generate java classes from WSDL file

1

आपको प्रतिक्रिया xml उत्पन्न करने के लिए wsdl का उपयोग करने की आवश्यकता है। एक प्रतिक्रिया xml का निर्माण, यह भी इतना बड़ा है, तत्वों को गायब होने के लिए बाध्य है।

यहाँ एक ट्यूटोरियल आप अपने आरंभ करने के लिए उपयोग कर सकते हैं,

http://www.mkyong.com/webservices/jax-ws/jax-ws-wsgen-tool-example/ http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example-document-style/

संबंधित मुद्दे