users@jaxb.java.net

javax.xml.bind.UnmarshalException: unexpected element

From: Peizhao Hu <peizhao_at_itee.uq.edu.au>
Date: Sun, 29 Apr 2007 17:48:23 +1000

Hi,

recently, I changed my Web Service codes from SOAP+Tomcat5.5 to JWS +
Application Server 9.

I have my following code working in the first setting, but resulted into
error in the second one. The only different from coding point of view is
the DataType definition of the "teds" variable. In the first setting, I
have it as Element directly, where I have it as Object and cast to
Element later on. the service terminated after "test1" and reported the
following error message. schema is attached.


============================ Java Code
========================================
    @WebMethod(action="register")
    public String register(@WebParam(name = "contextPath") String
contextPath, @WebParam(name = "teds") Object teds) {
        System.out.println("received object "+contextPath);
              
        StringBuilder replyMsg = new StringBuilder("[Reply Message]");
      
        try{
            JAXBContext jc = JAXBContext.newInstance(contextPath);
            Unmarshaller u = jc.createUnmarshaller();
            System.out.println("test1");
            JAXBElement<?> sensorElt =
(JAXBElement<?>)u.unmarshal((Element)teds);
            System.out.println("test2");
            replyMsg.append(sensorElt.getName());
            VTEDSType vteds =(VTEDSType)sensorElt.getValue();
            System.out.println("test3");
           
        } catch( JAXBException je ) {
            je.printStackTrace();
            replyMsg.append(je.toString());
        } catch(Exception e){
            replyMsg.append(e.toString());
        }
       
        //SensorDescription
        return "Registered Sensor:"+replyMsg.toString();
    }


============================ 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:523)
        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:920)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:366)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:347)
        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:288)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:271)
        at
org.nicta.safe.network.ars.ws.SensorReceptor.register(SensorReceptor.java:54)
        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:597)
        at com.sun.xml.ws.server.PeptTie._invoke(PeptTie.java:61)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.invokeEndpoint(SOAPMessageDispatcher.java:280)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher$SoapInvoker.invoke(SOAPMessageDispatcher.java:588)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.receive(SOAPMessageDispatcher.java:147)
        at com.sun.xml.ws.server.Tie.handle(Tie.java:90)
        at
com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:195)
        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:397)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at
com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
        at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
        at
com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
        at
com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
        at
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
        at
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)



-- 
regards;
Peizhao