| Author |
Issue with JAXB
|
Narayanan Ramachandran
Greenhorn
Joined: Dec 18, 2012
Posts: 2
|
|
Hi Team,
I have a Java class which uses JAXB to unmarshal a Java object to XML. Beloe is the code. It is using setSchema to set the reference of an external XSD file.
JAXBContext jaxbContext = JAXBContext.newInstance(MySimpleOrder.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(
new URL("http://soabook.com/example/oms/simpleorder.xsd"));
jaxbMarshaller.setSchema(schema);
ByteArrayOutputStream ba = new ByteArrayOutputStream();
jaxbMarshaller.marshal(myOrder, ba);
System.out.println(ba.toString());
This is failing when running through Eclipse in my Comany network because it is unable to locate the XSD file. I tried with proxy setting also. Still it failed. But in my client VPN, this is working fine. This is failing when executed with Command prompt also. But through my company network, I am able to access the XSD file through the browser.
Issue 1: Exception when executed in my company network (Not able to identify the XSD file)
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://soabook.com/example/oms/simpleorder.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2541)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:2528)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1825)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:519)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:485)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:210)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:626)
at com.jaxb.startfromjava.MySimpleOrderSerializer.main(MySimpleOrderSerializer.java:52)
Again, when I am trying to execute the code in the client VPN, I am getting an exception. Which happens during the marshalling process. Here I am getting another exception as below. But the XSD contains sn element simpleOrder and the corresponding class is also annotated appropriately.
javax.xml.bind.MarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'simpleOrder'.]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at com.jaxb.startfromjava.MySimpleOrderSerializer.main(MySimpleOrderSerializer.java:56)
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'simpleOrder'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:549)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.xml.internal.bind.v2.runtime.output.SAXOutput.endStartTag(SAXOutput.java:113)
at com.sun.xml.internal.bind.v2.runtime.output.ForkXmlOutput.endStartTag(ForkXmlOutput.java:91)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.endAttributes(XMLSerializer.java:274)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:560)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:290)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
... 3 more
Could you please tell me where I am wrong here?
|
 |
g tsuji
Ranch Hand
Joined: Jan 18, 2011
Posts: 375
|
|
@op
This is the explicative article on how to work through proxy server.
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
|
 |
 |
|
|
subject: Issue with JAXB
|
|
|