2014-11-06 117 views
5

任何人都可以幫助我擺脫這種異常。JAXB卡住 - unmarshal XML異常

意外元件(URI: 「http://cpps.xxx.com/splm-service」, 本地: 「PartInquiryService」)。預期元件(無)

下面是代碼和xml我使用

File file = new File("PartInquiryService.xml"); 
JAXBContext jaxbContext = JAXBContext.newInstance(PartInquiryService.class); 
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 
PartInquiryService partInqService = 
     (PartInquiryService)jaxbUnmarshaller.unmarshal(file); 

這裏是XML正在使用它..我將會收到這個XML作爲從MQ

的響應
<PartInquiryService xmlns="http://cpps.xxx.com/splm-service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <control> 
    <type>inquiryWithServiceWindow</type> 
    <correlationId format="hex">A10488237F3B7734A10488237F3B7734A10488237F3B7734</correlationId> 
    <origin> 
     <system>CPPS-SPLM</system> 
     <id>MP2ZCP5</id> 
     <at timeZone="UTC"> 
     <date format="ISO">2008-12-12</date> 
     <time format="ISO">20:12:48</time> 
     </at> 
    </origin> 
    <destination> 
     <system>SPLM_GUI</system> 
     <id>SPLM_01</id> 
    </destination> 
    </control> 
    <partInquiry> 
    <customerSystemkey>123456789123456</customerSystemkey> 
    <countryCode type="IBM">788</countryCode> 
    <partnumber>0000039M5123</partnumber> 
    <machType>1722</machType> 
    <zipcode>1066 VH</zipcode> 
    </partInquiry> 
    <inquiryResult> 
    <errorMessage>Invalid part number XXXXXXXXXXXX received</errorMessage> 
    <zipcodeUsed>NL 1066</zipcodeUsed> 
    <timeZone>MSK</timeZone> 
    <currency>EUR</currency> 
    <partnumber> 
     <id>0000039M5123</id> 
     <subType>REQ</subType> 
     <description>POWER CORD</description> 
     <subRank>0</subRank> 
     <weigth>10</weigth> 
     <length>12</length> 
     <width>9</width> 
     <height>11</height> 
     <sellingPrice currency="EUR">12.030</sellingPrice> 
     <rohsInd>C</rohsInd> 
    </partnumber> 
    <partnumber> 
     <id>0000040K8888</id> 
     <subType>ALT</subType> 
     <description>POWER CORD</description> 
     <subRank>0</subRank> 
     <weigth>10</weigth> 
     <length>12</length> 
     <width>9</width> 
     <height>11</height> 
     <sellingPrice currency="EUR">12.030</sellingPrice> 
     <rohsInd>D</rohsInd> 
    </partnumber> 
    <partnumber> 
     <id>0000012J1234</id> 
     <subType>SUB</subType> 
     <description>POWER CORD</description> 
     <subRank>-1</subRank> 
     <weigth>10</weigth> 
     <length>12</length> 
     <width>9</width> 
     <height>11</height> 
     <sellingPrice currency="EUR">12.030</sellingPrice> 
     <rohsInd>N</rohsInd> 
    </partnumber> 
    <sourceLocation> 
     <locId>788-5000</locId> 
     <description>CENTRAL BUFFER VENLO</description> 
     <deliveryOption> 
     <serviceWindow>Sameday 2hr</serviceWindow> 
     <logisticCost>88.00</logisticCost> 
     <date format="ISO">2014-08-24</date> 
     <time format="ISO">10:56:00</time> 
     </deliveryOption> 
     <deliveryOption> 
     <serviceWindow>Next day 16:00</serviceWindow> 
     <logisticCost>10.00</logisticCost> 
     <date format="ISO">2014-08-25</date> 
     <time format="ISO">16:00:00</time> 
     </deliveryOption> 
     <partInventory> 
     <id>0000039M5123</id> 
     <availableStock>1</availableStock> 
     </partInventory> 
     <partInventory> 
     <id>0000040K8888</id> 
     <availableStock>5</availableStock> 
     </partInventory> 
    </sourceLocation> 
    <sourceLocation> 
     <locId>821-9200</locId> 
     <description>CRS ST PETERSBURG</description> 
     <deliveryOption> 
     <serviceWindow>Sameday 2hr</serviceWindow> 
     <logisticCost>88.00</logisticCost> 
     <date format="ISO">2014-08-24</date> 
     <time format="ISO">10:56:00</time> 
     </deliveryOption> 
     <deliveryOption> 
     <serviceWindow>Next day 16:00</serviceWindow> 
     <logisticCost>10.00</logisticCost> 
     <date format="ISO">2014-08-25</date> 
     <time format="ISO">16:00:00</time> 
     </deliveryOption> 
     <partInventory> 
     <id>0000039M5123</id> 
     <availableStock>1</availableStock> 
     </partInventory> 
     <partInventory> 
     <id>0000040K8888</id> 
     <availableStock>5</availableStock> 
     </partInventory> 
    </sourceLocation> 
    <sourceLocation> 
     <locId>821-1102</locId> 
     <description>LSH MOSCOW DUTY PAID</description> 
     <deliveryOption> 
     <serviceWindow>Sameday 2hr</serviceWindow> 
     <logisticCost>88.00</logisticCost> 
     <date format="ISO">2014-08-24</date> 
     <time format="ISO">10:56:00</time> 
     </deliveryOption> 
     <deliveryOption> 
     <serviceWindow>Next day 16:00</serviceWindow> 
     <logisticCost>10.00</logisticCost> 
     <date format="ISO">2014-08-25</date> 
     <time format="ISO">16:00:00</time> 
     </deliveryOption> 
     <partInventory> 
     <id>0000039M5123</id> 
     <availableStock>1</availableStock> 
     </partInventory> 
     <partInventory> 
     <id>0000040K8888</id> 
     <availableStock>5</availableStock> 
     </partInventory> 
    </sourceLocation> 
    </inquiryResult> 
</PartInquiryService> 

這裏是PartInquiryService.java

public class PartInquiryService { 
    private Control control; 
    private PartInquiry partInqury; 
    private InquiryResult inquiryResult; 
    public Control getControl() { 
     return control; 
    } 
    public void setControl(Control control) { 
     this.control = control; 
    } 
    public PartInquiry getPartInqury() { 
     return partInqury; 
    } 
    public void setPartInqury(PartInquiry partInqury) { 
     this.partInqury = partInqury; 
    } 
    public InquiryResult getInquiryResult() { 
     return inquiryResult; 
    } 
    public void setInquiryResult(InquiryResult inquiryResult) { 
     this.inquiryResult = inquiryResult; 
    } 


} 
+0

你能告訴我們PartInquiryService.class嗎? – Xstian 2014-11-06 08:08:08

+0

Hi Xstian,感謝您的回覆,我已經添加了PartInquiryService的代碼片段?我已經創建了其他的.java綁定文件,這些文件在xml unmarshalling中使用,例如Control.java,PartInquiry.java等。 – chandiprasad 2014-11-06 08:15:08

回答

5

增加您的類PartInquiryService.java

@XmlRootElement(name = "PartInquiryService" ,namespace="http://cpps.xxx.com/splm-service") 
public class PartInquiryService { 

在同一個包把這個類(package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "http://cpps.xxx.com/splm-service", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
package your.package; 

注:內@XmlRootElement命名空間是沒有必要的,這種情況下,但我用來加強這信息。

+0

很酷的工作!謝謝 。 – chandiprasad 2014-11-06 08:45:54

+0

很高興能幫到你:) – Xstian 2014-11-06 08:46:27

+0

Hi Xstian,希望我們甚至可以使用下面的命令通過運行這個命令來生成所有的JAXB類... $ xjc xx-xx-xx-xxx.xsd -p -d C:/ ? – chandiprasad 2014-11-06 11:23:04