Hi,
I am trying to parse an xml element to the Unmarshaller. however, I got
exception saying unexpected element.
The variable is typed as Object received from a web service client. and
I was trying to cast it to xml element and pass it to the Unmarshaller.
JAXBContext jc = JAXBContext.newInstance(contextPath);
Unmarshaller u = jc.createUnmarshaller();
System.out.println("test1");
VTEDSType vteds = (VTEDSType)u.unmarshal((Element)teds); //
Error
I am using JAXB 2.13, but I also try with JAXB 2.0, both gave me same error.
I also pasted the log from my application server console, I have some
codes to verify my object contextPath and print out the xml node as shown.
//============================ Output of Received Object
==================================
received object context path org.nicta.safe.network.ars.sensor.teds
<teds xmlns:ns2=
http://ws.ars.network.safe.nicta.org/>
<BasicTEDS>
<Identification name=Manufacturer>
<value>
NICTA
</value>
</Identification>
<Identification name=ModelNumber>
<value>
NICTA-Camera-03037
</value>
</Identification>
<Identification name=VersionLetter>
<value>
A
</value>
</Identification>
<Identification name=VersionNumber>
<value>
001
</value>
</Identification>
<Identification name=SerialNumber>
<value>
nicta-423479-736483736322-Sensor
</value>
</Identification>
</BasicTEDS>
<StandardTemplateTEDS/>
<CustomisedTEDS>
<Classification name=MeasuredProperty>
<value>
Logical:Computer:Video
</value>
</Classification>
<Classification name=IntendedApplication>
<value>
Recognition:Object
</value>
</Classification>
<SpecificProperty name=Location>
<value>
NICTA - QRL Lv19
</value>
</SpecificProperty>
<SpecificProperty name=Owner>
<value>
NICTA QRL
</value>
</SpecificProperty>
<SpecificProperty name=Owner>
<value>
QR
</value>
</SpecificProperty>
<SpecificProperty name=IdentificationName>
<value>
Smart Camera
</value>
</SpecificProperty>
<SpecificProperty name=CalibrationDate>
<value>
22/02/2007
</value>
</SpecificProperty>
</CustomisedTEDS>
</teds>
test1
//================================ Error ===============================
javax.xml.bind.UnmarshalException: unexpected element (uri:"",
local:"teds"). Expected elements are <{}VTEDS>
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:556)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:199)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:194)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:71)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:957)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:399)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:380)
at
com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:35)
at
com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:101)
at
com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:224)
at
com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:107)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:289)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:272)
at
org.nicta.safe.network.ars.ws.SensorsReceptor.register(SensorsReceptor.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:197)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:132)
at
com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:241)
at
com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:75)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:70)
at
com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:133)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:79)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:70)
at
com.sun.xml.ws.rm.jaxws.runtime.server.RMServerPipe.process(RMServerPipe.java:271)
at
com.sun.xml.ws.mex.server.MetadataServerPipe.process(MetadataServerPipe.java:121)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:79)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:70)
at
com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:191)
at
com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:113)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:79)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
at
com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:208)
at
com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:374)
at
com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:175)
at
com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)
at
com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:398)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:255)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:564)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:81)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:207)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:564)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:558)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1067)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:564)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:558)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1067)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:249)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:618)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:549)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:790)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:326)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:248)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:199)
at
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at
com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:93)
--
regards;
Peizhao