Error on line 1 premature end of file

User-1562626665 posted

User-1562626665 posted

Hi all, I am getting XML error premature end of file on Line1.

It does not come out very rarely and I can not find the reason why it occurs.

I would like to know the possibilities of the error source.

Here is my logic : I use the memory stream to write the XML with XMLTextWriter

and When I get the XMLTextWriter , I move the memory pointer to position zero  and read that with StreamReader .

I can not change the memory stream to string that’s why I use StreamReader to read and convert to string.

And then I create the stream writer using that string to send to the server.

 You will see step by step coding below.

I think I did it in very complicated way. If you guys know some way which is less complicated, share with me please.

1                         MemoryStream ms = new MemoryStream();
2 //Create XML Text writer with Memory stream
3 XmlTextWriter xmlwr = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
4 //Create CDLXMLWriter Object to create XML file to send
5                        CDLXMLWriter writer = new CDLXMLWriter(xmlwr);
6 //write the Request, this function will write the XML file with XML text writer
 7                        writer.WriteCompetitiveQuoteRequest(quote);
8 // Flush the writer down to the memory stream
9 xmlwr.Flush();
10 // Set the position of Memory Stream to Zero
11 ms.Position = 0;
12 //Create the Stream Reader to read the stream from Memory Stream
13 StreamReader rdr = new StreamReader(ms);
14 // Convert the stream to string
15 string str = rdr.ReadToEnd();
16 // Create the Stream Writer with Request Stream to Server
17 StreamWriter stmWR = new StreamWriter(requestCDL.GetRequestStream());
18 // Write the String to the Request Stream
19 stmWR.Write(str);
20 //Flush it down
21 stmWR.Flush();
22 //Close it
23 stmWR.Close();
24 //Create Response Object by requesting response stream
25 HttpWebResponse responseCDL = (HttpWebResponse)requestCDL.GetResponse();
26 //Get the result back from CDL and Read it with XMLText Reader
27 XmlTextReader tr = new XmlTextReader(responseCDL.GetResponseStream());

Problem

After a Bamboo Server restart, the application doesn’t start up and the following appears in <bamboo-home-directory>/logs/atlassian-bamboo.log:

2016-03-21 13:42:26,022 INFO [localhost-startStop-1] [lifecycle] Starting Bamboo 5.9.7 (build #5920 Wed Oct 14 07:27:00 BRT 2015) using Java 1.8.0_71 from Oracle Corporation
2016-03-21 13:42:26,022 INFO [localhost-startStop-1] [lifecycle] Real path of servlet context: /Users/bamboouser/Documents/Atlassian/bamboo/bamboo-5.9.7/install/atlassian-bamboo
2016-03-21 13:42:26,039 ERROR [localhost-startStop-1] [DefaultAtlassianBootstrapManager] Home is not configured properly: 
com.atlassian.config.ConfigurationException: Failed to parse config file: Error on line -1 of document  : Premature end of file. Nested exception: Premature end of file.
    at com.atlassian.config.xml.DefaultDom4jXmlConfigurationPersister.load(DefaultDom4jXmlConfigurationPersister.java:35)
    at com.atlassian.config.xml.DefaultDom4jXmlConfigurationPersister.load(DefaultDom4jXmlConfigurationPersister.java:65)
    at com.atlassian.config.ApplicationConfig.load(ApplicationConfig.java:365)
    at com.atlassian.config.bootstrap.DefaultAtlassianBootstrapManager.init(DefaultAtlassianBootstrapManager.java:68)
    at com.atlassian.bamboo.setup.BootstrapLoaderListener.contextInitialized(BootstrapLoaderListener.java:98)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5524)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.dom4j.DocumentException: Error on line -1 of document  : Premature end of file. Nested exception: Premature end of file.
    at org.dom4j.io.SAXReader.read(SAXReader.java:355)
    at org.dom4j.io.SAXReader.read(SAXReader.java:261)
    at com.atlassian.config.xml.AbstractDom4jXmlConfigurationPersister.loadDocument(AbstractDom4jXmlConfigurationPersister.java:68)
    at com.atlassian.config.xml.DefaultDom4jXmlConfigurationPersister.load(DefaultDom4jXmlConfigurationPersister.java:31)
    ... 13 more
2016-03-21 13:42:26,041 INFO [localhost-startStop-1] [lifecycle] Bamboo home directory: /Users/bamboouser/Documents/Atlassian/bamboo/bamboo-5.9.7/home
2016-03-21 13:42:26,042 INFO [localhost-startStop-1] [lifecycle] Default charset: UTF-8

Diagnosis

The <bamboo-home-directory>/bamboo.cfg.xml is empty. This file cannot be empty. It contains important information such as the database connection, license, path to important directories, etc.

Workaround

Force Bamboo to regenerate the bamboo.cfg.xml file. To do that we need to reinstall Bamboo and copy the file to our existing Bamboo Home directory. Please read all the steps carefully before going through the process.

  1. Create a new empty directory to use as the Bamboo Home directory. This temporary.
  2. Create a new empty database. This temporary.
  3. Edit the <bamboo-installation-directory>/atlassian-bamboo/WEB-INF/classes/bamboo-init.properties file.
  4. Point bamboo.home to the new directory created in Step 1.

    ## You can specify your bamboo.home property here or in your system environment variables.
    
    #bamboo.home=/old/path/to/home/directory
    bamboo.home=/new/path/to/temporary/home/directory
  5. Go to <bamboo-installation-directory>/bin and start Bamboo.

    If you access Bamboo through the web browser, you should be prompted to set up a new Bamboo instance. This is what we want.

  6. Go through the setup wizard process but point Bamboo to the new database (created in Step 2) and not to the existing one.
  7. After finishing the setup process, stop Bamboo.
  8. Go to the to the new Bamboo Home directory and copy the bamboo.cfg.xml file.
  9. Put the bamboo.cfg.xml file inside the old Bamboo Home directory.

    IMPORTANT: don’t start Bamboo yet. Instead open up the bamboo.cfg.xml file.

  10. Edit the database connection properties to point to your existing Bamboo database.
  11. Go back to the <bamboo-installation-directory>/atlassian-bamboo/WEB-INF/classes/bamboo-init.properties file.
  12. Point bamboo.home back to the old directory

    ## You can specify your bamboo.home property here or in your system environment variables.
    
    bamboo.home=/old/path/to/home/directory
  13. Start Bamboo again.

I’m trying to fetch the content of the RSS feeds with ROME tools 1.5.1 from http://emm.newsbrief.eu news aggregation system.

I pad attention that ROME returns exception «com.rometools.rome.io.ParsingFeedException: Invalid XML: Error on line 1: Premature end of file» on some of the links.

The problematic part of the code, which leads the exception:

// fetch data from URL
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
try {
    feed = input.build(new XmlReader(feedSource));
} catch (FeedException | IOException | NullPointerException e) {
    isOK = false;
    e.printStackTrace();
    System.out.println(dataSource);
    System.out.println(e.getMessage());
}

Try to re-run the code multiple times, you’ll see that this issue appears for the different links, and from the time to time all the links return error but sometimes there is no even one error.

From my observations, if you re-run the code multiple times in a row, the probability that the bug will arise is less than if you re-run the code with a long break/pause.

The full error text:

com.rometools.rome.io.ParsingFeedException: Invalid XML: Error on line 1: Premature end of file.
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:237)
at com.rometools.rome.io.SyndFeedInput.build(SyndFeedInput.java:154)
at Rome.getRSSData(Rome.java:29)
at Main.main(Main.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.jdom2.input.JDOMParseException: Error on line 1: Premature end of file.
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:232)
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:303)
at org.jdom2.input.SAXBuilder.build(SAXBuilder.java:1196)
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:234)
… 8 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
at

com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1437)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1019)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:217)

Понравилась статья? Поделить с друзьями:
  • Error on line 1 at column 39 unsupported encoding unicode
  • Error on ingesting samples that are too old or are too far into the future
  • Error on ingesting out of order samples
  • Error on gpu3 device not responding check overclocking settings
  • Error on gpu1 an illegal memory access was encountered