Codehaus XFire

Documentation

Quicklinks

Developers

Sponsors

This page is for brainstorming how REST support should work in XFire (or possibly a new project if xfire ends up being too heavy weight).

Dan's First Take

Creating a Service

public class CustomerService {
  @RestMethod(methods={HttpMethod.GET}) 
  Customer getCustomer(String id);

  @RestMethod(methods={HttpMethod.DELETE}) 
  void deleteCustomer(String id);

  @RestMethod(methods={HttpMethod.POST}) 
  @WebResult(name="customerId")
  String addCustomer(Customer customer); 

  @RestMethod(method={HttpMethod.PUT})
  void updateCustomer(Customer customer);
}
public enum HttpMethod {
    DELETE,
    GET,
    PUT,
    POST
}

Mapping data to method parameters

The information to invoke our service could come from a number of places:

  • URI Path Info
    • @Path(2) - would select the first query parameter - i.e. "123" in "/customer/123"
    • @QueryParameter("customerId") - would select the query parameter with the name "customerId".
    • @RegexPath("someregexexpression") - would select some stuff from the uri
  • HTTP Headers
    • @HttpHeader("customerId") - would select the HTTP header with the name "customerId"
  • XML in a POST/PUT method
    • This can be done with JAXB, XMLBeans, etc.

Mapping the Operations to URIs

This could be done in the interface a couple different ways. At the class level:

@RestService(uri="/customer/")
public class CustomerService {
  ...
}

At the method level

public class CustomerService {
  @RestMethod(methods={HttpMethod.GET}, uri="/customer") 
  Customer getCustomer(String id);
...
}

At the service registration level:

CustomerService customerService = ...;
ServiceRegistry registry = ...;
registry.register("/internal-customers", customerService);
registry.register("/external-customers", anotherCustomerService);

Questions

  • What is the best way to map operations to URIs?
  • Is there a good syntax to map URI fragments to method parameters
  • What about MIME?
  • Should this framework allow non XML responses? i.e. could it return a JPEG? - the bigger question is can XFire support that....