Results 1 to 3 of 3

Thread: Simple annotation based web services

  1. #1
    Join Date
    Jun 2008
    Posts
    4

    Default Simple annotation based web services

    Hi there,
    I'm looking for some advice on starting out creating web services with Spring WS.

    Have been reading Spring Web Services - Reference Documentation 1.5.2, as well as the chapter on web services in the Spring Reference Documentation 2.5.4, as well as searching the forums, and I'm sure I'm missing something.

    I would like to define my web services using a purely annotation based approach, without the need for writing any wsdl xml, and without needing to define callback objects, parse xml in my service objects. I'd like to just deal with POJO's.

    I would like a setup whereby I call a local object and it "automagically" calls the same methods on the remote object. I would like to deploy the service using a servlet (WAR) and to deploy both client and service on Java 5 (Websphere).

    I could see that creating the server part was fairly straight forward, in that you define your annotated service endpoint, make it available via the MesageDispatcherServlet and deploy. However it is the client part I found difficult. I want a way of grabbing the a local object (assume to be proxied) and simply call the methods, which invokes the same methods on the remote service, returning appropriate values. Sort of a similar behaviour to some of the older RMI apps I've written.

    I'm finding the forums and doc quite confusing, as it seems this part of spring is rather "fast moving" advice depends a lot on JVM and Spring versions.

    Any advice on this would be greatly appreciated.

    Apologies if I'm asking for too much!

    Current code is below:

    My spring-ws-servlet.xml

    Code:
    <beans>
        <bean id="orderEndpoint" class="com.ben.service.BusinessServiceEndpoint"/>
        
        <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
            <constructor-arg ref="marshaller" />
        </bean>
        <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <list>
                    <value>com.ben.model.BusinessObject</value>
                </list>
            </property>
        </bean>
        <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />
    </beans>
    My endpoint class:

    Code:
    package com.ben.service;
    
    import org.springframework.ws.server.endpoint.annotation.Endpoint;
    import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
    
    import com.ben.model.BusinessObject;
    
    @Endpoint
    public class BusinessServiceEndpoint {
    	
    	@PayloadRoot(localPart="businessObjectRequest", namespace="...")
    	public BusinessObject getBusinessObject(){
    		BusinessObject o = new BusinessObject();
    		o.setBusinessValue("blah");
    		return o;
    	}
    }
    My business model object:

    Code:
    package com.anz.pb.directory.model;
    
    public class BusinessObject {
    	private String businessValue;
    	
    	public String getBusinessValue(){
    		return businessValue;
    	}
    	
    	public void setBusinessValue(String businessValue){
    		this.businessValue = businessValue;
    	}
    }
    Is there a config I can do on the client, which will give me something like:
    Code:
    //Injected bean
    BusinessServiceEndpoint service;
    
    //And fetch the remote object through ws
    BusinessObject obj = service.getBusinessObject();
    Kind regards,
    Ben Warner
    Last edited by bjwarner; Jun 25th, 2008 at 01:19 AM.

  2. #2
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    97

    Default

    To go from a vanilla business object, to a format that Jaxb can understand, you're going to have to use xjc (there's a maven plugin) to generate an xml representation of your business model.

    Refer to http://java.sun.com/webservices/docs...b/samples.html. (The Java to Schema bits are what you're interested in)

    Don't know if this takes you all the way to where you're going, but it's a few steps forward.

    *edit*: PS. Yes, it can all be a little overwhelming at first, but I think once you start taking the sample apps. I started with echo, and moved on to airline. Some bits in airline might be a bit confusing, but when you use that as an example, and try and build your own WS, it becomes quite straightforward.
    Last edited by tunaranch; Jun 25th, 2008 at 03:36 AM.

  3. #3
    Join Date
    Jun 2008
    Posts
    4

    Default

    Thanks very much for your reply tunaranch. Have been looking into the references from your post. Will post my findings shortly.

Posting Permissions

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