Why am I getting this error:
ERROR: 'Namespace for prefix 'xsi' has not been declared.'
Here is my Java code:
package com.emp.ma.jbl.nsnhlrspmlpl.nsnhlrspmlpl.internal.action;
import com.emp.ma.util.xml.XMLDocument;
import com.emp.ma.util.xml.XMLDocumentBuilder;
public class yay {
public static void main(String[] args) {
XMLDocument xmldoc = XMLDocumentBuilder.newDocument().addRoot("spml:modifyRequest");
xmldoc.gotoRoot().addTag("modification").addText("");
xmldoc.gotoChild("modification").addTag("valueObject").addText("");
xmldoc.gotoChild("valueObject").addAttribute("xsi:type","halo");
System.out.println(xmldoc);
}
}
This code was functioning properly until I tried throwing transformer exception whilst converting XML file to HTML for experimenting only.
I need to create an xml file with the format:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<spml:modifyRequest>
<modification>
<valueObject xsi:type="halo">
</valueObject>
</modification>
</spml:modifyRequest>
I removed the transformer part from the code already and yet I'm getting this error in eclipse:
ERROR: 'Namespace for prefix 'xsi' has not been declared.'
Exception in thread "main" com.emp.ma.util.xml.XMLDocumentException: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
at com.emp.ma.util.xml.XMLDocumentImpl.toResult(XMLDocumentImpl.java:1244)
at com.emp.ma.util.xml.XMLDocumentImpl.toStream(XMLDocumentImpl.java:1314)
at com.emp.ma.util.xml.XMLDocumentImpl.toString(XMLDocumentImpl.java:1336)
at com.emp.ma.util.xml.XMLDocumentImpl.toString(XMLDocumentImpl.java:1325)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.emp.ma.util.xml.XMLDocumentBuilder$XMLDocumentHandler.invoke(XMLDocumentBuilder.java:55)
at $Proxy1.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at com.emp.ma.jbl.nsnhlrspmlpl.nsnhlrspmlpl.internal.action.yay.main(yay.java:13)
Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.emp.ma.util.xml.XMLDocumentImpl.toResult(XMLDocumentImpl.java:1242)
... 12 more
Caused by: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
at com.sun.org.apache.xml.internal.serializer.SerializerBase.getNamespaceURI(Unknown Source)
at com.sun.org.apache.xml.internal.serializer.SerializerBase.addAttribute(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
... 15 more
I'm stuck because of this one exception and I don't know how to undo this. Please do help. Like i said, it was functioning properly before trying this experiment of mine, if possible how do I remove this transformer integration. I've tried changing workspace as well -- still not working.
For an XML document to be well-formed, all used namespace prefixes must be declared.
Simply declare the xsi namespace prefix on the root element of your XML,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<spml:modifyRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modification>
<valueObject xsi:type="halo">
</valueObject>
</modification>
</spml:modifyRequest>
and your error will go away.
Note that you'll similarly have to define the spml namespace prefix.
I got the same error "AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server faultSubcode: faultString: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared." while calling the soap web service from coldfusion 9 server, as the error does not resolve quickly as I had to spent more time, finnaly found that due to the incorrect date value supplying to the webservice parameters, it throws different issue. Whenever we got this issue please check input values that are supplying to the webservcie parameters. In my case due to the datetime format 2015-03-04T00:00:00.000Z(It's a part of ISO-8601 date representation), issue happened, 2015-03-04 00:00 resolves the issue. For example for datetime If I provide string(xxxx), coldfusion axis webservice shows te irrelevant error --Namespace for prefix 'xsi' has not been declared....
Related
I am using Flink v1.11.2 and Avro v1.10.1.
I am trying to deserialize an Avro record as a Specific record from a Kafka topic, but for some reason keep getting this error:
I was able to output it as a generic record using this:
FlinkKafkaConsumer<GenericRecord> eventsConsumer = new FlinkKafkaConsumer(
fsiProcessorProps.getKafkaEventsInput(),
AvroDeserializationSchema.forGeneric(Sde.getClassSchema()),
properties);
And am now trying:
FlinkKafkaConsumer<Sde> eventsConsumer = new FlinkKafkaConsumer(
fsiProcessorProps.getKafkaEventsInput(),
AvroDeserializationSchema.forSpecific(Sde.class),
properties);
but get the following error when trying to start the job:
"org.apache.flink.runtime.rest.handler.RestHandlerException: Could not execute application.
at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$handleRequest$1(JarRunHandler.java:103)
at java.base/java.util.concurrent.CompletableFuture.uniHandle(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.CompletionException: org.apache.flink.util.FlinkRuntimeException: Could not execute application.
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
... 7 more
Caused by: org.apache.flink.util.FlinkRuntimeException: Could not execute application.
at org.apache.flink.client.deployment.application.DetachedApplicationRunner.tryExecuteJobs(DetachedApplicationRunner.java:81)
at org.apache.flink.client.deployment.application.DetachedApplicationRunner.run(DetachedApplicationRunner.java:67)
at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$handleRequest$0(JarRunHandler.java:100)
... 7 more
Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Expecting type to be a PojoTypeInfo
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:302)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:198)
at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:149)
at org.apache.flink.client.deployment.application.DetachedApplicationRunner.tryExecuteJobs(DetachedApplicationRunner.java:78)
... 9 more
Caused by: java.lang.IllegalStateException: Expecting type to be a PojoTypeInfo
at org.apache.flink.formats.avro.typeutils.AvroTypeInfo.generateFieldsFromAvroSchema(AvroTypeInfo.java:74)
at org.apache.flink.formats.avro.typeutils.AvroTypeInfo.<init>(AvroTypeInfo.java:56)
at org.apache.flink.formats.avro.AvroDeserializationSchema.getProducedType(AvroDeserializationSchema.java:168)
at org.apache.flink.streaming.connectors.kafka.internals.KafkaDeserializationSchemaWrapper.getProducedType(KafkaDeserializationSchemaWrapper.java:66)
at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase.getProducedType(FlinkKafkaConsumerBase.java:1066)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.getTypeInfo(StreamExecutionEnvironment.java:2172)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1608)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1569)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1551)
at FsiProcessor.main(FsiProcessor.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:288)
... 12 more
"
The Sde class is a typical generated avro class so I am not sure what I am missing. Also the data does not have the schema embedded (tried with schema embedded as well and got same issue).
So I wasn't able to find the answer to that because things switched to using a schema registry, but wanted to post how it was done with a schema registry at least.
So instead of doing:
FlinkKafkaConsumer<Sde> eventsConsumer = new FlinkKafkaConsumer(
fsiProcessorProps.getKafkaEventsInput(),
AvroDeserializationSchema.forSpecific(Sde.class),
properties);
It was changed to:
private static <T extends SpecificRecordBase> FlinkKafkaConsumerBase<T> getFlinkKafkaConsumer(
Properties properties, String topic, Class<? extends SpecificRecordBase> type, String schemaRegistryUrl, Map<String, String> sslConfiguration) {
ConfluentRegistryAvroDeserializationSchema<?> schema =
ConfluentRegistryAvroDeserializationSchema.forSpecific(
type, schemaRegistryUrl, sslConfiguration);
return new FlinkKafkaConsumer<T>(topic, (DeserializationSchema<T>) schema, properties);
}
I won't mark this as an answer, but wanted to give it as at least another way involving schema registry which is a good thing to use with Avro anyway.
Make it sure Avro generated POJO has both get/set method implemented by adding this:
<createSetters>true</createSetters>
I would like to get the state machine from .uml file created by papyrus. I am parsing the model.uml file using the code below.
ResourceSet set = new ResourceSetImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource res = set.getResource(URI.createFileURI("resources/model.uml"), true);
EcoreUtil.resolveAll(res);
System.out.println(res.getContents().get(0));
This code works fine and prints the content. But when I try to cast it to Model class using the code below
Model model = (Model) EcoreUtil.getObjectByType(res.getContents(),UMLPackage.Literals.MODEL);
It throws this exception,
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/uml2/types/TypesPackage
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.init(UMLPackageImpl.java:1907)
at org.eclipse.uml2.uml.UMLPackage.<clinit>(UMLPackage.java:83)
at org.eclipse.uml2.uml.UMLPackage$Literals.<clinit>(UMLPackage.java:28779)
at mp.m2bt.BTGenerator.main(BTGenerator.java:49)
Caused by: java.lang.ClassNotFoundException: org.eclipse.uml2.types.TypesPackage
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
I am not sure if I am missing anything. I think the problem is in UMLPackage.Literals.MODEL. So, Can anybody help me to fix this issue and get the state machines from the model.
You need the jar org.eclipse.uml2.types in your classpath. This is why the type org.eclipse.uml2.types.TypesPackage cannot be found.
I am using the GDATA API for parsing google calendar. The Calendar is embedded in the website:
http://regreformtracker.aba.com/p/dodd-frank-calendar.html
I got the the calendar URL from the iframe src used in the above mentioned website which is :
https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York
I am using the below mentioned snippet:
URL feedURL = new URL("https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York");
CalendarService service = new CalendarService("TestCalendarFeed");
CalendarEventFeed resultFeed = service.getFeed(feedURL , CalendarEventFeed.class);
I get SAXParseException and below is the stack trace for the same:
[Fatal Error] strict.dtd:81:5: The declaration for the entity "ContentType" must end with '>'.
Oct 13, 2014 2:09:22 PM com.google.gdata.util.LogUtils logException
WARNING: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
Message: The declaration for the entity "ContentType" must end with '>'.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at org.xml.sax.helpers.ParserAdapter.parse(ParserAdapter.java:430)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.data.BaseFeed.parseAtom(Unknown Source)
at com.google.gdata.data.BaseFeed.readFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at com.google.gdata.client.GoogleService.getFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at sample.calendar.TestCalendarFeed.printAllEvents(TestCalendarFeed.java:116)
at sample.calendar.TestCalendarFeed.main(TestCalendarFeed.java:472)
The server had a problem handling your request.
com.google.gdata.util.ParseException: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.data.BaseFeed.parseAtom(Unknown Source)
at com.google.gdata.data.BaseFeed.readFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at com.google.gdata.client.GoogleService.getFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at sample.calendar.TestCalendarFeed.printAllEvents(TestCalendarFeed.java:116)
at sample.calendar.TestCalendarFeed.main(TestCalendarFeed.java:472)
Caused by: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at org.xml.sax.helpers.ParserAdapter.parse(ParserAdapter.java:430)
... 9 more
I am not sure what the error is, could you please check and let me know where i am going wrong?
I tried using other calendars , like my private calendar to check if it is the problem with the calendar URL, but even then i am getting the same issue.
I also tried using CalendarFeed class instead of CalendarEventFeed, still i am getting the same issue.
Your feed url does not point to GData content. https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York is an html web page rather than an xml feed. In any case, GData is deprecated and should not be used (will be shut down in November this year). Try taking a look into reading this calendar through API v3 (https://developers.google.com/google-apps/calendar).
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.
I have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<details>
...
<address1>Test&Address</address1>
...
</details>
When I try to unmarshal it using JAXB, it throws the following exception:
Caused by: org.xml.sax.SAXParseException: The reference to entity "Address" must end with the ';' delimiter.
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.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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 com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:194)
But when I changed the & in the XML to ', it works. Looks like the problem is only with ampersand & and I cannot understand why.
The code to unmarshal is:
JAXBContext context = JAXBContext.newInstance("some.package.name", this.getClass().getClassLoader());
Unmarshaller unmarshaller = context.createUnmarshaller();
obj = unmarshaller.unmarshal(new StringReader(xml));
Anyone have some insight?
EDIT: I tried the solution suggested by #abhin4v below (ie, add a space after &), but it doesn't seem to work too. Here's the stacktrace:
Caused by: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
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.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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 com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:194)
I've run into this too. First pass I simply replaced the & to a token string (AMPERSAND_TOKEN), sent it through JAXB, then re-replaced the ampersand. Not ideal, but it was a quick fix.
Second pass I made a lot of significant changes, so I'm not sure what exactly solved the problem. I suspect that providing JAXB access to the html dtds made it much happier, but that's only a guess and could be specific to my project.
HTH
Xerces converts & to & and then tries to resolve &Address which fails because it does not end with ;. Put a space between & and Address and it should work. Putting a space will not work as Xerces will now try to resolve & and throw the second error given in OP. You can wrap the test in a CDATA section and Xerces will not try to resolve the entities.
It turns out that the problem is because of the framework I'm using (Mentawai framework). The said XML comes from the POST body of an HTTP request.
Apparently, the framework converts the character entities in the XML body, therefore, & becomes & and the unmarshaller fails to unmarshal the XML.