Announcement Announcement Module
Collapse
No announcement yet.
jibx marshalling return empty element Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jibx marshalling return empty element

    I'm new to Spring-WS and trying to use it with jibx I encountered a problem on marshalling the response. I get the marshalling of the received SOAP message, my endpoint invoke a bean who return a result object, but then the result is an empty element of the expected type like this:
    Code:
    ...
        <contatto xsi:schemaLocation="http://luciano.mytest.com/schema/contact 
    	http://localhost:8080/contact/schema/contact.xsd" xmlns:xsi="null" />
    ...
    This is my configuration of Spring-ws beans
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    ...<bean id="payloadMapping" 
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
      <property name="endpointMap">
        <map>
          <entry key=
              "{http://luciano.mytest.com/schema/contact}pkparm" 
              value-ref="getContattoMarshallingEndpoint" />
    ...    </map>
      </property>
    </bean>
    
    <bean id="getContattoMarshallingEndpoint" 
        class="it.almaviva.springws.GetContattoMarshallingEndpoint"
        p:service-ref="contattiService" p:marshaller-ref="contattoMarshaller" 
      p:unmarshaller-ref="pkparmUnMarshaller" />
    
    ....
    
    <bean id="pkparmUnMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
            <property name="targetClass"><value>it.almaviva.model.PkContatto</value></property>
    </bean>
    <bean id="contattoMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
            <property name="targetClass"><value>it.almaviva.model.Contatto</value></property>
    </bean>
    ...
    </beans>
    This is my endpoint failing
    Code:
    public class GetContattoMarshallingEndpoint extends
    		AbstractMarshallingPayloadEndpoint {
    
    	@Override
    	protected Object invokeInternal(Object object) throws Exception {
    				PkContatto pk  =    (PkContatto) object;
    		Contatto cont=service.findByPrimaryKey(pk.getPk());
    		return  cont;
    	}
    	
    	// injected
    	private ContattiService service;
    	public void setService(ContattiService service) {
    		this.service = service;
    	}
    
    
    }
    my schema
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xns="http://luciano.mytest.com/schema/contact"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    	elementFormDefault="qualified"
    	targetNamespace="http://luciano.mytest.com/schema/contact">
    
    
    	<xsd:simpleType name="pktype">
    		<xsd:restriction base="xsd:string">
    			<xsd:minLength value="1" />
    			<xsd:maxLength value="10" />
    			<xsd:pattern value="([0-9])*" />
    		</xsd:restriction>
    	</xsd:simpleType>
    
    	<xsd:simpleType name="nomecittatype">
    		<xsd:restriction base="xsd:string">
    			<xsd:minLength value="2" />
    			<xsd:maxLength value="30" />
    			<xsd:pattern value="([a-z][A-Z])*" />
    		</xsd:restriction>
    	</xsd:simpleType>
    
    	<xsd:element name="pkparm">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="pk" type="xns:pktype" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="nomecittaparm">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="nomecitta" type="xns:nomecittatype" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    
    
    	<xsd:element name="contatti">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element maxOccurs="unbounded" minOccurs="0"
    					ref="xns:contatto" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    
    	<!-- Created from mapping for class it.sipad.model.Contatto -->
    	<xsd:element name="contatto">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="contatto-id" type="xsd:string" />
    				<xsd:element name="nome" type="xsd:string" />
    				<xsd:element name="telefoni">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element maxOccurs="unbounded" minOccurs="0"
    								ref="xns:telefono" />
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    				<xsd:element name="indirizzi">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element maxOccurs="unbounded" minOccurs="0"
    								ref="xns:indirizzo" />
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    				<xsd:element minOccurs="0" name="foto">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element name="foto-id" type="xsd:string" />
    							<xsd:element name="immagine"
    								type="xsd:base64Binary" />
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    			</xsd:sequence>
    			<xsd:attribute name="schemaLocation" type="xsd:string" />
    		</xsd:complexType>
    	</xsd:element>
    	<!-- Created from mapping for class it.sipad.model.Telefono -->
    	<xsd:element name="telefono">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="telefono-id" type="xsd:string" />
    				<xsd:element name="prefisso" type="xsd:string" />
    				<xsd:element name="numero" type="xsd:string" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    	<!-- Created from mapping for class it.sipad.model.Indirizzo -->
    	<xsd:element name="indirizzo">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="indirizzo-id" type="xsd:string" />
    				<xsd:element name="via" type="xsd:string" />
    				<xsd:element name="citta">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element name="citta-id" type="xsd:string" />
    							<xsd:element minOccurs="0" name="nome" type="xsd:string" />
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    </xsd:schema>
    and jibx binding.file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <binding force-classes="true" forwards="false" value-style="attribute"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xns="http://luciano.mytest.com/schema/contact">
    
    	<namespace uri="http://www.w3.org/2001/XMLSchema-instance"
    		prefix="xsi" />
    	<namespace uri="http://luciano.mytest.com/schema/contact"
    		default="elements" />
    <!-- 
    	<namespace uri="http://luciano.mytest.com/contact/wsdl"
    		prefix="wns" />
     -->		
    
    	<mapping name="pkparm" class="it.almaviva.model.PkContatto" >
    	 		<value name="schemaLocation"
    			ns="http://www.w3.org/2001/XMLSchema-instance"
    			constant="http://luciano.mytest.com/schema/contact http://localhost:8080/contact/schema/contact.xsd"
    			usage="optional" />
    		/>
    		<value style="element" name="pk" field="pk" />
    	</mapping>
    
    	<mapping name="nomecittaparm" class="it.almaviva.model.NomeCitta" >
    	 		<value name="schemaLocation"
    			ns="http://www.w3.org/2001/XMLSchema-instance"
    			constant="http://luciano.mytest.com/schema/contact http://localhost:8080/contact/schema/contact.xsd"
    			usage="optional" />
    		/>
    		<value style="element" name="nomecitta" field="nome" />
    	</mapping>
    
    <!-- 
    	<mapping abstract="true" type-name="xns:contatti" class="it.almaviva.model.Contatti" >
    		<collection field="contatti" usage="optional"
    			create-type="java.util.ArrayList" item-type="it.almaviva.model.Contatto" />
    	</mapping>
    	<mapping name="contatto" class="it.almaviva.model.Contatto" >
    		<structure map-as="xns:contatto"/>
    	</mapping>
    
    	<mapping abstract="true" class="it.almaviva.model.Contatto" type-name="xns:contatto">
     -->
     
     	<mapping  name="contatti" class="it.almaviva.model.Contatti" >
     	 		<value name="schemaLocation"
    			ns="http://www.w3.org/2001/XMLSchema-instance"
    			constant="http://luciano.mytest.com/schema/contact http://localhost:8080/contact/schema/contact.xsd"
    			usage="optional" />
    		/>
    		<collection field="contatti" usage="optional"
    			create-type="java.util.ArrayList" item-type="it.almaviva.model.Contatto" />
    	</mapping>
    	
    	<mapping name="contatto" class="it.almaviva.model.Contatto" >
     		<value name="schemaLocation"
    			ns="http://www.w3.org/2001/XMLSchema-instance"
    			constant="http://luciano.mytest.com/schema/contact http://localhost:8080/contact/schema/contact.xsd"
    			usage="optional" />
    		/>
    		<value style="element" name="contatto-id" field="contattoID" />
    		<value style="element" name="nome" field="nome" />
    		<collection name="telefoni" field="telefonis" usage="optional"
    			create-type="java.util.HashSet" item-type="it.almaviva.model.Telefono" />
    		<collection name="indirizzi" field="indirizzis" usage="optional"
    			create-type="java.util.HashSet" item-type="it.almaviva.model.Indirizzo" />
    		<structure field="foto" usage="optional" name="foto">
    			<value style="element" name="foto-id" field="fotoID" />
    			<value style="element" name="immagine" field="immagine" />
    		</structure>
    	</mapping>
    	<mapping class="it.almaviva.model.Telefono" name="telefono">
    		<value style="element" name="telefono-id" field="telefonoID" />
    		<value style="element" name="prefisso" field="prefisso" />
    		<value style="element" name="numero" field="numero" />
    	</mapping>
    	<mapping class="it.almaviva.model.Indirizzo" name="indirizzo">
    		<value style="element" name="indirizzo-id" field="indirizzoID" />
    		<value style="element" name="via" field="via" />
    		<structure field="citta" name="citta">
    			<value style="element" name="citta-id" field="cittaID" />
    			<value style="element" name="nome" field="nome" usage="optional" />
    		</structure>
    	</mapping>
    </binding>
    My jibx binding file should be ok as with it and axis2 I exposed the same web service without any problem
    What am I doing wrong?

    Luciano

  • #2
    Solved using SAAJ 1.1 from Sun RI

    Code:
    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
      <property name="messageFactory">
        <bean class="com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"></bean>
     </property>
    </bean>
    The tip was indicated in the FAQ for JBoss 4.2, but worked also in my JBoss 4.0.5

    I tested also with Axiom and works fine too.

    Code:
    <bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
    <property name="payloadCaching" value="true"/>
    </bean>
    I only can't understand why I didn't get any exception with the default JBoss SAAJ.

    Luciano

    Comment


    • #3
      I experienced similar issues. Actually, I got an error message of "index out of bound" with JBoss4.0.5 and the returned soap body=null. I went to debug and find the marshalling xml file is good but JBoss tranferred the xml to null due to the exception with its SAAJ1.2 implementation. When I replaced it by SAAJ1.3 jars. The error is gone. In terms of missing exception message, it may due to your Log4j configuration.

      Peter

      Comment

      Working...
      X