Results 1 to 5 of 5

Thread: Simple Marshalling/Unmarshalling

  1. #1
    Join Date
    Apr 2008
    Posts
    9

    Default Simple Marshalling/Unmarshalling

    Hey Spring-WS!

    Have a couple of questions that could not Googlify... Questions are simple:

    When writing a WS client:

    1. Accessing synchronous response:

    Code:
    webServiceTemplate.marshalSendAndReceive( payLoad object )
    1.a - Is this asynchronous? Since there is no response object provided?
    1.b - If not, where should I put a response to? Should I configure my own EndPoint for that?
    1.c - How to make it synchronous (with marshalling)?

    2. When injecting Marshaller/Unmarshaller:

    Code:
    <bean id="wsTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        		<property name="marshaller" ref="castorMarshaller" />
    		<property name="unmarshaller" ref="castorMarshaller" />
    </bean>
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"/>
    2.a How do I include a custom namespace that the endpoint I am sending to expects to see?

    2.b How do I have control over field names:

    MyObject.myProperty

    should marshal to

    <MyObject>
    <myProperty>value</myProperty>
    </MyObject>

    BUT INSTEAD marshalls to (Castor):

    <my-object>
    <my-property>value</my-property>
    </my-object>

    or (e.g. with XStream):

    <m__MyObject>
    <m__myProperty>value<m__myProperty>
    <m__MyObject>


    Thank you very much for your answers guys,
    iLearn

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    1 No, it's synchronous. The parameter payload object is transformed into XML, a SOAP envelope is wrapped around it, and it's sent over the wired. The response payload, if any, is unmarshalled and returned.

    2. Those really depend on the marshaller. In Castor, you would need to write a mapping file, for instance.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Apr 2008
    Posts
    9

    Default

    Arjen,

    Thank you for answering my questions. The first question is completely misunderstanding on my part, since in APIs it says: "Returns the unmarshalled payload of the response message, if any."

    The second question (in my initial post) I still have difficulties with:

    2.a How do I include a custom namespace that the remote endpoint I am sending to expects to see?

    2.b Is creating a custom Castor mapping file the only way to have:

    <MyObject>
    <myProperty>value</myProperty>
    </MyObject>

    instead of

    <my-object>
    <my-property>value</my-property>
    </my-object>
    ?

    Thanks for clarification!
    Last edited by iLearn; May 7th, 2008 at 03:28 PM.

  4. #4
    Join Date
    Jun 2008
    Posts
    6

    Default Needed sourcecode for castor marshel and unmarshel

    I am new to webservices.I need an example in spring webservices using Castor marshelling.Can anyone send me the code to me.

    Thanks in advance

  5. #5
    Join Date
    Apr 2008
    Location
    Philadelphia, US
    Posts
    198

    Default

    iLearn,

    By default Castor will marshal/unmarshal with "-" in between the words, so MyObject will get marshaled into "my-object", since that is a default behavior.

    In order to create a "custom look" for your object and fields, you would need to create a mapping file - which is really not all that difficult. Here is a great example from: http://www.castor.org/xml-mapping.html

    Let's say you have a class OrderItem:

    Code:
    public class OrderItem {
        
        private String id;
        private Integer orderQuantity;
        
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public Integer getOrderQuantity() {
            return orderQuantity;
        }
        public void setOrderQuantity(Integer orderQuantity) {
            this.orderQuantity = orderQuantity;
        }
    }
    normally, if you map it with Castor without any mapping file, you would get:

    Code:
    <?xml version="1.0" ?>        
    <order-item>
       <id>12</id>
       <order-quantity>100</order-quantity>
    </order-item>
    but what if you need to marshal it (map it) to something like this which is way more natural and more readable:

    Code:
    <?xml version="1.0" ?>        
    <item identity="12">
       <quantity>100</quantity>
    </item>
    then you need to create a very simple mapping file:

    Code:
    <class name="mypackage.OrderItem>
               
       <map-to xml="item"/>
    
       <field name="id" type="string">
          <bind-xml name="identity" node="attribute"/>
       </field>
    
       </field name="orderQuantity" type="integer">
          <bind-xml name="quantity" node="element"/>
       </field>
    
    </class>
    It is very simple - you map:

    "OrderItem" to "item"
    "id" to "identity" (and making it an attribute by: node="attribute")
    "orderQuantity" to "quantity"


    from here: http://blog.dotkam.com/2008/06/25/ma...l-with-castor/

    litius
    Last edited by litius; Jul 29th, 2008 at 04:48 PM.
    Humans are stateful and mutable beings that have no problems processing many things concurrently and share state with others + they are usually "coupled"

Posting Permissions

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