1

I have a service layer that I would like to convert into a webservice. However I hate using annotations because they severely limit code reusability in my common base classes. Some webservices use a subset of the objects, and I don't want things exposed for one service to be exposed for another.

I had the same issue with hibernate, however the hbm xml mappings allow me to share the same domain objects and have different mappings for different services, which works great. Is there any kind of rest webservice framework for java that will allow me to describe my api and scheme objects with xml, and still gain the benefits of converting these objects to json/xml etc?

ant-depalma
  • 2,006
  • 4
  • 26
  • 34

3 Answers3

0

You could describe your web services in WADL, which is XML based, then generate your code using CXF's wadl2java tool. Note that WADL is not widely adopted as of yet, so you have to decide how important it is to you, to do contract-first REST services.

Perception
  • 79,279
  • 19
  • 185
  • 195
0

Spring Web Services is another annotation-free framework based on XML for Web Services publishing. You should give it a try

Carlos Gavidia-Calderon
  • 7,145
  • 9
  • 34
  • 59
0

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

EclipseLink JAXB (MOXy) has an extension that allows you to represent the metadata as an XML file. You can leverage this metadata in a JAX-RS environment using a ContextResolver:

package blog.bindingfile.jaxrs;

import java.io.*;
import java.util.*;

import javax.ws.rs.Produces;
import javax.ws.rs.ext.*;
import javax.xml.bind.*;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

import blog.bindingfile.Customer;

@Provider
@Produces({"application/xml", "application/json"})
public class CustomerContextResolver implements ContextResolver<JAXBContext> {

    private JAXBContext jc;

    public CustomerContextResolver() {
        Map<String, Object> props = new HashMap<String, Object>(1);
        props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "blog/bindingfile/binding.xml");
        jc = JAXBContext.newInstance(new Class[] {Customer.class} , props);
    }

    public JAXBContext getContext(Class<?> clazz) {
        if(Customer.class == clazz) {
            return jc;
        }
        return null;
    }

}

For More Information

Related Stack Overflow Questions

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Hmm so forgive my ignorance but would this be a good fit if I would prefer not to generate additional client objects, but instead use a subset of my domain objects as specified in the xml? This way I can have one domain object but ws clients don't see all of the fields? – ant-depalma Mar 12 '12 at 21:32
  • @user842800 - Yes, that is a common use case where MOXy's external mapping document can be leveraged. – bdoughan Mar 12 '12 at 21:40