Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JAXB - Unexpected end of element {} - UnmarshalException Exception

843834Feb 18 2003 — edited Jan 26 2004
Hi

I am using Jaxb 1.0 Beta on AIX an I am getting javax.xml.bind.UnmarshalException exception when I try to unmarshall XML document. XML document and schema are valid ( I generated both using XML spy )

Interestingly, the code works fine on windows 2000 but when I put the jar ,XML schema and xml document on unix it throws Unmarshall exception.

Here's what I am trying to do.

Code :
--------------------------------------------------------------
JAXBContext jc =
JAXBContext.newInstance( context,
new com.xyz.retail.app.points.pgp.JAXBClassLoader());

if(jc != null)
System.out.println("Got the context");
else
System.out.println("Error in getting context");

System.out.println("");

// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();

System.out.println("Created the Unmarshaller");
System.out.println("");

// Unmarshal securities document into Java content tree

SecurityInfo securityInfo =
(SecurityInfo)u.unmarshal( new FileInputStream( secFile ) );

System.out.println("Unmarshaled the Document");
System.out.println("");
-----------------------------------------------------------

Schema :
-----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Yogesh
-->
<xs:schema targetNamespace="http://www.xyz.com/retail/app/points/pgp/util"
xmlns="http://www.xyz.com/retail/app/points/pgp/util" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="SecurityInfo" type="SecurityInfoType"/>
<xs:complexType name="SecurityInfoType">
<xs:sequence>
<xs:element ref="AirlinePartners"/>
</xs:sequence>
</xs:complexType>

<xs:element name="AirlinePartners">
<xs:complexType>
<xs:sequence>
<xs:element ref="AirlinePartner" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="AirlinePartner">
<xs:complexType>
<xs:sequence>
<xs:element name="CardType" type="xs:string"/>
<xs:element name="Description" type="xs:string" minOccurs="0"/>
<xs:element name="TPrivate" type="xs:string"/>
<xs:element name="TPassphrase" type="xs:string"/>
<xs:element name="APublic" type="xs:string"/>
<xs:element name="PlainText" type="xs:string"/>
<xs:element name="CypherText" type="xs:string"/>
<xs:element name="TKeyExpiry" type="xs:date" min
Occurs="0"/>
<xs:element name="AKeyExpiry" type="xs:date" min
Occurs="0"/>
</xs:sequence>
</xs:complexType>
/xs:element>
</xs:schema>
-----------------------------------------------------------

XML File :

-----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Yogesh
-->
<!--Sample XML file generated by XMLSPY v5 rel. 2 U (http://www.xmlspy.com)-->
<SecurityInfo xmlns="http://www.xyz.com/retail/app/points/pgp/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://www.xyz.com/retail/app/points/pgp/util /home/lcards/temp/APSecInfo.xsd">

<AirlinePartners>
<AirlinePartner>
<CardType>x</CardType>
<Description>some card</Description>
<TPrivate>/home/lcards/temp/sachin.asc</TPrivate>
<TPassphrase>worldcup2003</TPassphrase>
<APublic>/home/lcards/temp/sunil.asc</APublic>
<PlainText>/home/lcards/files/outbox/x</PlainText>
<CypherText>/home/lcards/files/outbox/x</CypherText>
<TKeyExpiry>2005-08-15</TKeyExpiry>
<AKeyExpiry>2005-08-15</AKeyExpiry>
</AirlinePartner>
<AirlinePartner>
<CardType>y</CardType>
<Description>Another card</Description>
<TPrivate>/home/lcards/temp/kapil.asc</TPrivate>
<TPassphrase>worldcup1983</TPassphrase>
<APublic>/home/lcards/temp/dilip.asc</APublic>
<PlainText>/home/lcards/files/outbox/y</PlainText>
<CypherText>/home/lcards/files/outbox/y</CypherText>
<TKeyExpiry>2005-08-15</TKeyExpiry>
<AKeyExpiry>2005-08-15</AKeyExpiry>
</AirlinePartner>
</AirlinePartners>

</SecurityInfo>

-----------------------------------------------------------

Output:
-----------------------------------------------------------


Got the context

Created the Unmarshaller

DefaultValidationEventHandler: [ERROR]: Unexpected end of element {}:CardType
javax.xml.bind.UnmarshalException: Unexpected end of element {}:CardType
at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalExce
ption(UnreportedException.java:59)
at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThr
ow(SAXUnmarshallerHandlerImpl.java:406)
at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.endElement(S
AXUnmarshallerHandlerImpl.java:108)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
n Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(Unmarshaller
Impl.java:139)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnm
arshallerImpl.java:129)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnm
arshallerImpl.java:166)
at com.xyz.retail.app.points.pgp.APSecurityInfoFactory.getAPSecInfo
(APSecurityInfoFactory.java:102)
at com.xyz.retail.app.points.pgp.EncryptAndSign.init(EncryptAndSign
.java:183)
at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
ign.java:581)
at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
tFiles.java:149)
Inside readKeys()

java.lang.NullPointerException
at com.xyz.retail.app.points.pgp.EncryptAndSign.readKeys(EncryptAnd
Sign.java:215)
at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
ign.java:583)
at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
tFiles.java:149)
Inside buildCypherTextFileName()

java.lang.NullPointerException
at com.xyz.retail.app.points.pgp.EncryptAndSign.buildCypherTextFile
Name(EncryptAndSign.java:311)
at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
ign.java:667)
at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
tFiles.java:149)
Exception in Main method

-----------------------------------------------------------

Thanks in advance for any help.

Yogesh.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2004
Added on Feb 18 2003
4 comments
1,134 views