Announcement Announcement Module
Collapse
No announcement yet.
A Strange Problem: unmarshalled nothing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A Strange Problem: unmarshalled nothing

    I am using Spring WS with JAXB2 as marshaller, and met some very strange problems:

    I configured the NewsRequest class as below:
    Code:
    @XmlRootElement(namespace="http://www.andriette.com/ws/news")
    public class NewsRequest implements java.io.Serializable{
    	 
    	@XmlElement
    	public int id;
    	
    	@XmlElement
    	public String descr;
    	
    
    }
    in xsd:
    Code:
    	<xs:element name="newsRequest">
    		<xs:complexType>
    			<xs:sequence>
    				<xs:element name="id" type="xs:integer"></xs:element>
    				<xs:element name="descr" type="xs:string" />
    			</xs:sequence>
    		</xs:complexType>
    	</xs:element>
    in spring-ws-servlet.xml:
    Code:
    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller" >
    	<property name="classesToBeBound">
                <list>
                    <value>com.andriette.model.NewsRequest</value>
                    <value>com.andriette.model.News</value>                
                </list>
        </property>
    	<property name="schema" value="/WEB-INF/xsd/news.xsd"/>
    	
    </bean>
    and the SOAP ENVELOPE:
    Code:
      <?xml version="1.0" encoding="UTF-8" ?> 
    - <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://www.andriette.com/ws/news" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <soapenv:Body>
    - <q0:newsRequest>
      <q0:id>5421</q0:id> 
      <q0:descr>521</q0:descr> 
      </q0:newsRequest>
      </soapenv:Body>
      </soapenv:Envelope>
    BUT just cannot convert the "5421" of q0:id nor "521" of q0:descr to the value in NewsRequest instance. In the instance ,they were 0 and null respectively.

    Here is the log:
    Code:
    DEBUG [http-8080-Processor24] (OpenSessionInViewFilter.java:239) - Using SessionFactory 'sessionFactory' for OpenSession
    InViewFilter
    DEBUG [http-8080-Processor24] (AbstractBeanFactory.java:203) - Returning cached instance of singleton bean 'sessionFacto
    ry'
    DEBUG [http-8080-Processor24] (OpenSessionInViewFilter.java:181) - Opening single Hibernate Session in OpenSessionInView
    Filter
    DEBUG [http-8080-Processor24] (SessionFactoryUtils.java:316) - Opening Hibernate Session
    DEBUG [http-8080-Processor24] (SessionImpl.java:220) - opened session at timestamp: 4844263471583232
    DEBUG [http-8080-Processor24] (SessionImpl.java:1289) - setting flush mode to: NEVER
    DEBUG [http-8080-Processor24] (TransactionSynchronizationManager.java:168) - Bound value [org.springframework.orm.hibern
    ate3.SessionHolder@bbddbf] for key [org.hibernate.impl.SessionFactoryImpl@1dfb0b5] to thread [http-8080-Processor24]
    DEBUG [http-8080-Processor24] (MessageDispatcher.java:150) - MessageDispatcher with name 'spring-ws' received request [<
    soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://www.andriette.com/ws/news" x
    mlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <q0:newsRequest>
    <q0:id>5421</q0:id>
    <q0:descr>521</q0:descr>
    </q0:newsRequest>
    </soapenv:Body>
    </soapenv:Envelope>
    ]
    DEBUG [http-8080-Processor24] (AbstractMapBasedEndpointMapping.java:110) - Looking up endpoint for [{http://www.andriett
    e.com/ws/news}newsRequest]
    DEBUG [http-8080-Processor24] (MessageDispatcher.java:240) - Endpoint mapping [org.springframework.ws.server.endpoint.ma
    pping.PayloadRootQNameEndpointMapping@ce374a] maps request to endpoint [com.andriette.endpoints.getNewsEndpoint@1f77497]
    DEBUG [http-8080-Processor24] (MessageDispatcher.java:262) - Testing endpoint adapter [org.springframework.ws.server.end
    point.adapter.MessageEndpointAdapter@15c314a]
    DEBUG [http-8080-Processor24] (AbstractMarshallingPayloadEndpoint.java:140) - Unmarshalled payload request to [com.andri
    ette.model.NewsRequest@1db637f]
    DEBUG [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (ManagerBase.java:676) - Start expire sessions StandardMa
    nager at 1182681513690 sessioncount 0
    DEBUG [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (ManagerBase.java:684) - End expire sessions StandardMana
    ger processingTime 0 expired sessions: 0
    DEBUG [http-8080-Processor24] (NewsManagerImpl.java:22) - Returning news with id=0
    Can you give me some idea what's the problem??

  • #2
    Solved.

    SOAP Envelope is like this:
    Code:
      <?xml version="1.0" encoding="UTF-8" ?> 
    - <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://www.andriette.com/ws/news" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <soapenv:Body>
    - <q0:newsRequest>
      <q0:id>123</q0:id> 
      <q0:descr>456</q0:descr> 
      </q0:newsRequest>
      </soapenv:Body>
      </soapenv:Envelope>
    therefore, the class annotation must also declare the namespace:
    Code:
    @XmlRootElement(namespace="http://www.andriette.com/ws/news")
    public class NewsRequest{
    	 
    	@XmlElement(namespace="http://www.andriette.com/ws/news")
    	public Integer id;
    	
    	@XmlElement(namespace="http://www.andriette.com/ws/news")
    	public String descr;
    	
    
    }
    Cry.....

    Comment

    Working...
    X