Announcement Announcement Module
Collapse
No announcement yet.
Error invoking SpringWS: cvc-elt.1: Cannot find the declaration of element Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error invoking SpringWS: cvc-elt.1: Cannot find the declaration of element

    Hi,

    I'm trying to implement a simple WS, have followed instructions form the book and also from the springsource.
    While invoking the WS as webServiceTemplate.marshalSendAndReceive following error is seen:
    [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'CustomerDetailsRequest'.]


    Snippet from the stacktrace:
    Code:
    org.springframework.oxm.jaxb.JaxbMarshallingFailureException: JAXB marshalling exception: null; nested exception is javax.xml.bind.MarshalException
     - with linked exception:
    [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'CustomerDetailsRequest'.]
    	at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:72)
    	at org.springframework.oxm.jaxb.AbstractJaxbMarshaller.convertJaxbException(AbstractJaxbMarshaller.java:143)
    	at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:383)
    	at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:81)
    	at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:360)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:535)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:351)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:341)
    	at com.h3g.midus.services.web.poc.client.CustomerDetails.getDetails(CustomerDetails.java:15)
    	at com.h3g.midus.domain.ServiceRequest.complete(ServiceRequest.java:328)
    	at com.h3g.midus.domain.ServiceRequest$$FastClassByCGLIB$$6eeead3d.invoke(<generated>)
    	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    I have seen few more posts with similar error, have tried all the suggested solutions, but none have worked, hence thought to seek help from the forum.
    I think somehow the the parser cant get hold of XSD in declared location, hence throws the exception.

    The relevant code detail snippets are:
    From xyz-ws-servlet.xml

    1. Endpoint Mapping
    Code:
    <bean id="endpointMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    <property name="interceptors">
    <list>
    <ref bean="loggingInterceptor"/>
    </list>
    </property>
    <property name="endpointMap">
    <map>
    <entry key="{http://xyz.abc.com/poc/schemas}CustomerDetailsRequest" value-ref="customerDetailsEndpoint"/>
    </map>
    </property>
    </bean>
    2. Endpoint bean
    Code:
    <bean id="customerDetailsEndpoint" class="com.abc.xyz.services.web.poc.CustomerDetailsMarshallingEndpoint">
    <property name="marshaller" ref="marshaller"/>
    <property name="unmarshaller" ref="marshaller"/>
    <property name="customerDetailsBrowser" ref="customerDetailsBrowser"></property>	
    </bean>
    3. JaxbMarshaller bean definition
    Code:
    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
    <list>
    <value>com.abc.xyz.services.web.poc.CustomerDetailsRequest</value>
    <value>com.abc.xyz.services.web.poc.CustomerDetailsResponse</value>
    </list>
    </property>
            
    <property name="schemas" value="classpath:xsd/CustomerDetails.xsd"/></bean>
    4. And finally the XSD
    Code:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xyz.abc.com/poc/schemas"  xmlns="http://xyz.abc.com/poc/schemas"   attributeFormDefault="qualified" elementFormDefault="qualified">
    <xs:element name="CustomerDetailsRequest">
    
    ... Few more nodes ....
    
    </xs:element>
    <xs:element name="CustomerDetailsResponse">
    
    ... Few more nodes ....
    
    </xs:element>
    </xs:schema>
    I have already tried all of the solutions posted on this subject, but none have worked.

    Would be a great help if anyone can suggest what may be wrong!

    Thanks,
    Last edited by chiraj; Jun 19th, 2009, 06:53 AM.

  • #2
    I was able to fix this problem by defining two seperate Jaxb2Marshallers. One for marshalling te response, one for unmarshalling the request.

    In my case, putting both schema's into one JaxbMarshaller led to the same org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ns:xyz'.

    I guess it depends on the complexity of your schema's. In my case the response schema included the request schema (not my idea btw), which probably puzzled the schema validation logic.

    Succes!

    Comment

    Working...
    X