Content is not allowed in Prolog SAXParserException
Asked Answered
M

5

45

I am trying to call a web service but facing a strange behavior. we have a web-service running on my server but the code is not open to us so can not see what going on behind the wall The owner of the service have exposed web based test client UI which take input in a text box and will show the response to testing purpose.This input box is taking the input in the below mentioned format

<CONTENT>
 <CONTENTID></CONTENTID>
 <DOCUMENTID>DRI2</DOCUMENTID>
 <LOCALECODE>en_US</LOCALECODE>
 <LATEST_VERSION>false</LATEST_VERSION>
 <INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT>
 <ACTIVITY_TYPE></ACTIVITY_TYPE>
</CONTENT>

its working fine on this UI but when i am trying to call this web service through my java code its getting connected as well getting authorized by the service but when i trying to call the above method it giving me the below error message

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog.
 faultActor: 
 faultNode: 
 faultDetail: 
 {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: Content is not allowed in prolog.
 at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
 at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
 at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
 at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
 at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
 at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
 at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
 at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
 at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
 at org.apache.axis.client.Call.invoke(Call.java:2767)
 at org.apache.axis.client.Call.invoke(Call.java:2443)
 at org.apache.axis.client.Call.invoke(Call.java:2366)
 at org.apache.axis.client.Call.invoke(Call.java:1812)
 at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
 at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
 at com.inquira.prep.TestWs.main(TestWs.java:13)

 {http://xml.apache.org/axis/}hostname:umeshawasthi

org.xml.sax.SAXParseException: Content is not allowed in prolog.
 at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
 at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
 at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
 at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
 at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
 at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
 at org.apache.axis.client.Call.invoke(Call.java:2767)
 at org.apache.axis.client.Call.invoke(Call.java:2443)
 at org.apache.axis.client.Call.invoke(Call.java:2366)
 at org.apache.axis.client.Call.invoke(Call.java:1812)
 at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
 at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
 at com.inquira.prep.TestWs.main(TestWs.java:13)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
 at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
 at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
 at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
 at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
 at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
 ... 11 more

below is the code for generating the required XML

inputXml.append("<CONTENT>");
   inputXml.append("<CONTENTID>").append("</CONTENTID>");
   inputXml.append("<DOCUMENTID>").append("DRI2").append("</DOCUMENTID>");
   inputXml.append("<LOCALECODE>").append("en_US").append("</LOCALECODE>");
   inputXml.append("<LATEST_VERSION>").append("false").append("</LATEST_VERSION>");
   inputXml.append("<INCREASEVIEWCOUNT>").append("false").append("</INCREASEVIEWCOUNT>");
   inputXml.append("<ACTIVITY_TYPE>").append("</ACTIVITY_TYPE>");
   inputXml.append("</CONTENT>");

and the generated XML is as below

<CONTENT><CONTENTID></CONTENTID><DOCUMENTID>DRI2</DOCUMENTID><LOCALECODE>en_US</LOCALECODE><LATEST_VERSION>false</LATEST_VERSION><INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT><ACTIVITY_TYPE></ACTIVITY_TYPE></CONTENT>

i even did timing of the generated string something as below

inputXml.toString().trim().replaceFirst("^([\\W]+)<","<");

but unable to find out whats going wrong,one thing i am sure there is some problem in the input XML as its working find on the test Page UI for the same XML

any help in this regard is much appricated

Menis answered 31/12, 2010 at 9:0 Comment(5)
I get this kind of error message when saving XML files as UTF-8 with BOM. Where and how do you initialize the inputXML object?Nates
Try adding this at the top <?xml version="1.0" encoding="UTF-8"?>Ti
@Org.life.java: I also tried this thing nothing worked :(Menis
@Welteraumpirat:_content.getContentRecord(_token,test); this is the service method provided by them which takes 2 parameters both as string typeMenis
possible duplicate of org.xml.sax.SAXParseException: Content is not allowed in prologWorkout
N
62

This error is probably related to a byte order mark (BOM) prior to the actual XML content. You need to parse the returned String and discard the BOM, so SAXParser can process the document correctly.

You will find a possible solution here.

Nates answered 31/12, 2010 at 12:10 Comment(2)
I checked whether this "BOM" existed by viewing my file in a Hex Editor. ef bb bf marked the first 3 bytesHackathorn
ok but isnT there a way to do this with SAX parser? Do we have to remove the BOM ourselves, before feeding the SAX (handler) ?Esmeraldaesmerelda
L
3

to simply remove it, paste your xml file into notepad, you'll see the extra character before the first tag. Remove it & paste back into your file - bof

Loggia answered 26/2, 2013 at 9:59 Comment(0)
A
2

This error can come if there is validation error either in your wsdl or xsd file. For instance I too got the same issue while running wsdl2java to convert my wsdl file to generate the client. In one of my xsd it was defined as below

<xs:import schemaLocation="" namespace="http://MultiChoice.PaymentService/DataContracts" />

Where the schemaLocation was empty. By providing the proper data in schemaLocation resolved my problem.

<xs:import schemaLocation="multichoice.paymentservice.DataContracts.xsd" namespace="http://MultiChoice.PaymentService/DataContracts" />
Acosmism answered 22/5, 2014 at 7:46 Comment(0)
P
2

Check the XML. It is not a valid xml.

Prolog is the first line with xml version info. It ok not to include it in your xml.

This error is thrown when the parser reads an invalid tag at the start of the document. Normally where the prolog resides.

e.g.

  1. Root/><document>
  2. Root<document>
Pacorro answered 6/5, 2015 at 9:44 Comment(1)
Isn't Prolog a programming language??? OK, I just so totally misunderstood that "Content is not allowed in Prolog" message!Broaden
S
0

I faced the same issue. Our application running on four application servers and due to invalid schema location mentioned on one of the web service WSDL, hung threads are generated on the servers . The appliucations got down frequently. After corrected the schema Location , the issue got resolved.

Sylph answered 22/8, 2014 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.