[java] Content is not allowed in Prolog SAXParserException

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

This question is related to java axis2 axis webservice-client saxparseexception

The answer is


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>

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.


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" />

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


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to axis2

ORA-12516, TNS:listener could not find available handler The endpoint reference (EPR) for the Operation not found is Content is not allowed in Prolog SAXParserException Java Webservice Client (Best way) How do you Change a Package's Log Level using Log4j? Difference between Apache CXF and Axis

Examples related to axis

R barplot Y-axis scale too short How can I change the font size of ticks of axes object in matplotlib Multiple contexts with the same path error running web service in Eclipse using Tomcat Please initialize the log4j system properly. While running web service Secondary axis with twinx(): how to add to legend? Content is not allowed in Prolog SAXParserException Python, Matplotlib, subplot: How to set the axis range? rotating axis labels in R Difference between Apache CXF and Axis How to add custom Http Header for C# Web Service Client consuming Axis 1.4 Web service

Examples related to webservice-client

WebService Client Generation Error with JDK8 javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake during web service communicaiton Client to send SOAP request and receive response Content is not allowed in Prolog SAXParserException Java Webservice Client (Best way)

Examples related to saxparseexception

Content is not allowed in Prolog SAXParserException