Question

I am trying to implement Apache Qpid into our architecture and I am having trouble reading in a properties file.

Properties props = new Properties(); props.loadFromXML(this.getClass().getResourceAsStream("hello.properties"));

loadfromxml is throwing me an error, here is the stack trace:

> java.util.InvalidPropertiesFormatException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog.  at
> java.util.XMLUtils.load(XMLUtils.java:56)     at
> java.util.Properties.loadFromXML(Properties.java:852)     at
> com.irad.message.system.HelloTest.runTest(HelloTest.java:29)  at
> com.irad.message.system.HelloTest.main(HelloTest.java:23) Caused by:
> org.xml.sax.SAXParseException: Content is not allowed in prolog.  at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
>   at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
>   at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
>   at
> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
>   at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1036)
>   at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
>   at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
>   at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
>   at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
>   at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
>   at
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232)
>   at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
>   at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:82)   at
> java.util.XMLUtils.load(XMLUtils.java:54)     ... 3 more

Here is the hello.properties file:

java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionfactory= amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
destination.topicExchange = amq.topic

What am I doing wrong? I copied the code snippet from the documentation page of Qpid.

Was it helpful?

Solution

You are using Properties.loadFromXML to load a TEXT file as XML, and it's telling you the XML file you've given it is malformed.

Next time when you get errors like this, do a google search for 'java loadfromxml'. It will take you to the javadocs manual on how to use it and you will see that the parameters you are feeding it is incorrect:

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#loadFromXML%28java.io.InputStream%29

The above link says:

The XML document must have the following DOCTYPE declaration:

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

Change your properties file to be of correct format, and then you'll be on your way to figuring out the next error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top