Hello all,
I'm developing a REST-based web service using spring. To this point I've used @MVC, but am now exploring using CXF to manage the controllers. The application contains nearly 100 distinct endpoints, based on the different business objects used by the application. After a year of experience with and maintenance of the application, I've refined the controllers to a very generic form, here's the basic idea:
The manager and authorizer are injected into the obejct in the spring application context xml. If I could somehow inject the strings that go into the @Path annotations, then I could truly run each and every service (endpoint group) off this single class, just creating new instances of the class in the spring context.Code:@Produces("application/json") @Path("/{orgid}/thisParticularService/") public class SomeService { @Context private MessageContext mc; private IServiceObjectManager manager; private IServiceObjectAuthorizer authorizer; @SuppressWarnings("unchecked") @GET public Collection<ServiceObject> getList(@PathParam("orgid") BigDecimal orgid) throws Exception { if (!authorizer.authorizeGeneral(mc.getHttpServletRequest().getSession(), orgid)) { throw new WebApplicationException(401); } return (List<ServiceObject>) manager.getList(orgid); } @GET @Path("/{id}") public ServiceObject getDetail(@PathParam("id") BigDecimal id, @PathParam("orgid") BigDecimal orgid) throws Exception { if (!authorizer.authorizeGeneral(mc.getHttpServletRequest().getSession(), orgid)) { throw new WebApplicationException(401); } return (ServiceObject) manager.getDetail(id); } @PUT @Path("/{id}") @Consumes("application/json") public Response update(@PathParam("id") Long id, ServiceObject c, @PathParam("orgid") BigDecimal orgid) throws Exception{ ..... ..... etc, etc
Eclipse validation tells me that a constant variable can be placed in the annotation, like this:
But this, of course, can't be set by a setter, so I can't inject the value into the bean....or can I? Does anyone have an idea of how I might go about truly genericizing the service?Code:private static final String pathString = "/{id}"; @Path(pathString) ....


Reply With Quote
