Results 1 to 4 of 4

Thread: JiBX Marshaller

  1. #1
    Join Date
    Jul 2009
    Posts
    8

    Default JiBX Marshaller

    Does any one know how to configure a Jibx marshaller in a spring-ws?
    if we have a request coming and we want to map that request into an object,do we need to create two classes? one for the object, the other one for marshaller? and modify the spring-ws-servlet.xml?

    Many thanks,
    Qiulu

  2. #2
    Join Date
    Jan 2005
    Location
    Wellington, New Zealand
    Posts
    17

    Default

    Hi Qiulu,
    Did you sort this? I'd be interested in your implementation. I'm still finishing mine.

    Cheers
    Glenn

  3. #3
    Join Date
    Dec 2005
    Posts
    930

    Default

    I have been using JiBX with Spring WS for a couple of years now. Here is a simple example (I typed this in TextPad, so there may be a few typos):

    Spring config:
    Code:
    <bean id="fooEndpoint" class="com.foo.FooEndpoint">
    	<constructor-arg ref="fooResponseMarshaller" />
    	<constructor-arg ref="fooRequestUnmarshaller" />
    </bean>
    <bean id="fooResponseMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
    	<property name="bindingName" value="JiBXbindingFoo" /
    	<property name="targetClass" value="com.foo.FooResponse" />
    </bean>
    <bean id="fooRequestUnmarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
    	<property name="bindingName" value="JiBXbindingFoo" /
    	property name="targetClass" value="com.foo.FooRequest" />
    </bean>
    FooEndpoint extends org.springframework.ws.server.endpoint.AbstractMar shallingPayloadEndpoint

    Code:
    package com.foo;
    
    import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;
    
    public class FooEndpoint extends AbstractMarshallingPayloadEndpoint {
    
    	@Override
    	protected Object invokeInternal(Object requestObject) throws Exception {
    		FooRequest fooRequest = (FooRequest) requestObject;
    		FooResponse fooResponse = new FooResponse();
    		fooResponse.setResponse(fooRequest.getRequest());
    		return fooResponse;
    	}

    Code:
    public class FooRequest {
    	private String request;
    	
    	public String getRequest() {
    		return request;
    	}
    	
    	public void setRequest(String request) {
    		return request;
    	}
    }
    Code:
    public class FooResponse {
    	private String response;
    	
    	public String getResponse() {
    		return response;
    	}
    	
    	public void setResponse(String response) {
    		return response;
    	}
    }
    JiBX binding file: (jibx-binding.xml, for example)

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <binding name="JiBXbindingFoo">
    	<mapping name="FooRequest" class="com.foo.FooRequest" ordered="true">
    		<property name="request" field="request" />
    	</mapping>
    	<mapping name="FooResponse" class="com.foo.FooResponse" ordered="true">
    		<property name="response" field="response" />
    	</mapping>
    </binding>
    Note, if you use Eclipse and test with an embedded Tomcat server, you will need to add a Builder to your workspace so that every time you do a clean, the JiBX binding compiler will run automatically. If you use Maven, then this is easy to do. If interested I can post this as well

    Hope this helps
    Alan
    Last edited by Alan Stewart; Aug 31st, 2009 at 11:00 PM.

  4. #4
    Join Date
    Oct 2009
    Posts
    1

    Default

    Hi Alan,

    How do you specify the marshaller and unmarshaller if you have multiple target classes?

    Is it possible to specify the contextPath as we do with JAXB2?

    Thanks,
    Sree

Posting Permissions

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