简体   繁体   中英

issue with SAX parser in java

When web service is called by using SOAP request it will give following parse error. I have check about the prolog of request its right there is no whitespace or dash. Even though it will cause following error

org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
  known 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.dispat
ch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known 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 Sour
ce)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
    at requestModel.SimpleCheckMail.checkMail(SimpleCheckMail.java:162)
    at model.InboxDataBean.prepareList(InboxDataBean.java:97)
    at model.InboxDataBean.getemailList(InboxDataBean.java:207)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELR
esolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELRe
solver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:1
89)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpress
ion.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.
 java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.
java:182)
    at javax.faces.component.UIData.getValue(UIData.java:731)
    at javax.faces.component.UIData.getDataModel(UIData.java:1798)
    at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIDa
ta.java:484)
    at javax.faces.component.UIData.setRowIndex(UIData.java:473)
    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRen
 derer.java:81)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.jav
 a:820)
    at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1754)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.
java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView
(FaceletViewHandlingStrategy.java:401)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewH
andler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePha
se.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
 ava:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
 927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
 11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:1805)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:907)
    at java.lang.Thread.run(Thread.java:619)

Please let me know whats the problem......of this error....thanx in advance


Ya....all of you are right ....But what i am getting is that it is an SOAP request and i have already see the request carefully there is no bad character.....But the problem is that when i am invoking the web service through soap request it gives null as a respone so i am getting the error..... As soon as Webservice work properly ......this works fine now....thanks all of you

It means that there is something in xml before <?xml ... look carefully in it. Also check that there is no invisible character (you can do it in any HEX editor). Sometimes windows notepad adds his marker in the file beginning.

The parser sees character data before the actual XML itself is started. Either make sure your XML does not contain any stuff before the XML starts, or let your SAX parser ignore this...

Try to display the data you're actually parsing. Maybe some bad characters are inserted before the beginning of your xml, or maybe you're not reading the right file.

This may be a because of a BOM , if your XML file is stored as UTF-8 (which it probably is).

Here , you have an example of an InputStream, that gets rid of the BOM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM