Results 1 to 4 of 4

Thread: Jaxb2

  1. #1
    Join Date
    Oct 2007
    Posts
    22

    Default Jaxb2

    Hi, all.

    I'm new to JAXB, so I'm sorry if this is obvious...

    Using Spring-WS 1.0.3, JDK 5, Spring 2.5.0, JAXB 2.1.6, I'm getting the following error when trying to hit my web service:

    Code:
    01/09 11:36:05 T:1698 WARNING: MessageDispatcher.processEndpointException: Endpoint invocation resulted in exception - responding with SOAP Fault
    org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://com/infopia/webservices/types/2", local:"Product"). Expected elements are (none); nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://com/infopia/webservices/types/2", local:"Product"). Expected elements are (none)
    	at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:75)
    	at org.springframework.oxm.jaxb.AbstractJaxbMarshaller.convertJaxbException(AbstractJaxbMarshaller.java:143)
    	at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:399)
    	at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)
    	at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.unmarshalRequest(MarshallingMethodEndpointAdapter.java:143)
    	at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.invokeInternal(MarshallingMethodEndpointAdapter.java:134)
    	at org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:58)
    	at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:215)
    	at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:162)
    	at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:87)
    	at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
    	at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:197)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    	at com.infopia.webservices.auditing.AuditingFilter.doFilter(AuditingFilter.java:84)
    	at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
    	at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    	at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    	at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    	at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    	at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    	at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
    	at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
    	at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
    	at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://com/infopia/webservices/types/2", local:"Product"). Expected elements are (none)
    	at javax.xml.bind.UnmarshalException.<init>(UnmarshalException.java:67)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:603)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1009)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:446)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:427)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
    	at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
    	at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:123)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:314)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:297)
    	at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:107)
    	at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:395)
    	... 28 more
    My implementation class's method looks like:
    Code:
      @PayloadRoot(localPart = "Product", namespace = "http://com/infopia/webservices/types/2")
      public JAXBElement<CallStatus> createSku(JAXBElement<Product> requestElement) throws IOException {
        Product product = requestElement.getValue();
        return new JAXBElement<CallStatus>(new QName("http://com/infopia/webservices/types/2", "CallStatus"), CallStatus.class, new CallStatus());
    The SOAP sent in is:
    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP-ENV:Header/>
       <SOAP-ENV:Body>
          <Product xmlns="http://com/infopia/webservices/types/2" xmlns:ns2="http://com.infopia.webservices/types/2"/>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    The Spring-ws servlet's configuration file is:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
        <bean class="com.infopia.webservices.veneer.v2.ServiceImplementation"/>
        
        <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
    
        <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="contextPath" value="com.infopia.webservices.veneer.v2.types"/>
        </bean>
        <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
            <constructor-arg ref="marshaller"/>
        </bean>
        <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
        <bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
           <property name="messageFactory" ref="messageFactory"/>
        </bean>
    
    </beans>
    The wsdl and schema are attached rather than inline, as I've hit the character limit in the post.

    The interesting thing is that this appears to be a JAXB problem, but the way I called into the service is using Spring-WS via a class that extends WebServiceGatewaySupport, like:
    Code:
        Product p = new Product();
        CallStatus status = (CallStatus) getWebServiceTemplate().marshalSendAndReceive(
          new JAXBElement<Product>(new QName("http://com/infopia/webservices/types/2", "Product"), Product.class, p));
    And it apparently didn't have any problem with the JAXB marshalling using the same JAXB classes that the server side is using (the Product class above) (the configuration of its org.springframework.oxm.jaxb.Jaxb2Marshaller in its spring file is identical [copied & pasted] as the one in the server's servlet configuration file).

    Anyone have any thoughts or anything obvious stand out?

    Thanks,
    Greg
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2007
    Posts
    22

    Default

    I've also tried setting the schema property on the org.springframework.oxm.jaxb.Jaxb2Marshaller bean in the configuration XML file, which leads to a different error:

    Code:
    01/09 16:10:54 T:328 WARNING: MessageDispatcher.processEndpointException: Endpoint invocation resulted in exception - responding with SOAP Fault
    org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: null; nested exception is javax.xml.bind.UnmarshalException
     - with linked exception:
    [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Product'.]
    	at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:75)
    	at org.springframework.oxm.jaxb.AbstractJaxbMarshaller.convertJaxbException(AbstractJaxbMarshaller.java:143)
    	at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:399)
    	at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)
    	at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.unmarshalRequest(MarshallingMethodEndpointAdapter.java:143)
    	at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.invokeInternal(MarshallingMethodEndpointAdapter.java:134)
    	at org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:58)
    	at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:215)
    	at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:162)
    	at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:87)
    	at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
    	at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:197)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    	at com.infopia.webservices.auditing.AuditingFilter.doFilter(AuditingFilter.java:84)
    	at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
    	at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    	at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    	at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    	at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    	at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    	at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
    	at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
    	at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
    	at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.xml.bind.UnmarshalException
     - with linked exception:
    [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Product'.]
    	at javax.xml.bind.UnmarshalException.<init>(UnmarshalException.java:56)
    	at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:506)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:324)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:297)
    	at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:107)
    	at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:395)
    	... 28 more
    Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Product'.
    	at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109)
    	at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:104)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
    	at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:335)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:89)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
    	at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
    	at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:123)
    	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:314)
    	... 31 more
    I believe this is coming b/c it's doing validating of the XML against the schema. I don't really want validation turned on, but maybe this gives more info to someone?

    Thanks in advance,
    Greg

  3. #3
    Join Date
    Oct 2007
    Posts
    22

    Default

    I apologize for not figuring this part out sooner, but part of the problem was that I should've been using the namespace http://com.infopia.webservices/types/2 rather than http://com/infopia/webservices/types/2 in both the service implementation and the creation of the JAXBElement in calling it.

    I.e. service implementation:

    Code:
      @PayloadRoot(localPart = "Product", namespace = "http://com.infopia.webservices/types/2")
      public JAXBElement<CallStatus> createSku(JAXBElement<Product> requestElement) throws IOException {
        Product product = requestElement.getValue();
        CallStatus status = new CallStatus();
        status.setCallId(312);
        status.setMessage("Whatever.");
        return new JAXBElement<CallStatus>(new QName("http://com.infopia.webservices/types/2", "CallStatus"), CallStatus.class, status);
      }
    and caller:

    Code:
        Product p = new Product();
        CallStatus getFlightsResponseDocument = (CallStatus) getWebServiceTemplate().marshalSendAndReceive(
          new JAXBElement<Product>(new QName("http://com.infopia.webservices/types/2", "Product"), Product.class, p));
    with resulting SOAP:

    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP-ENV:Header/>
       <SOAP-ENV:Body>
          <ns2:Product xmlns:ns2="http://com.infopia.webservices/types/2"/>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    However, I've done that, and I still get the same stack trace, except the message now is:

    Code:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ns2:Product'.
    I have a feeling it's another namespace issue, but it's not clear to me what that would be. Any help would be appreciated - sorry for not figuring out the above part beforehand.

    Thanks,
    Greg

  4. #4
    Join Date
    Oct 2007
    Posts
    22

    Default

    Well, to be helpful for those who might search & find this thread, it turns out the problem was my own ignorance of XML schema. The top-level objects for both the request and the response needed to be elements, not complexTypes. Also, to get it to work, for those interested, the service implementation needed to take Product and return JAXBElement<CallStatus> as opposed to taking JAXBElement<Product>, which I what I was originally doing due to an example I saw online (not this site).

    FYI,
    Greg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •