Announcement Announcement Module
Collapse
No announcement yet.
Question about injection and annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about injection and annotations

    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:
    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
    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.

    Eclipse validation tells me that a constant variable can be placed in the annotation, like this:
    Code:
    private static final String pathString = "/{id}";
    @Path(pathString)
    ....
    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?
Working...
X