rest icon indicating copy to clipboard operation
rest copied to clipboard

Allow Feature to register resources

Open kalgon opened this issue 5 years ago • 2 comments

It would be nice if javax.ws.rs.core.Features could also be used to register resources as well (and not only providers).

Then I could package a complete API unit like this:

public class AdminFeature implements Feature {

	@Override
	public boolean configure(FeatureContext context) {
		context.register(AdminMessageBodyWriter.class);
		context.register(AdminExceptionMapper.class);
		context.register(AdminFilter.class);
		context.register(UsersResource.class);
		context.register(RolesResource.class);
		context.register(JobsResource.class);
		return true;
	}
}

And in my application, I would only have to do:

@ApplicationPath("api")
public class MyApplication extends Application {

	@Override
	public Set<Class<?>> getClasses() {
		return Set.of(
			AdminFeature.class, // registers providers + resources
			SpecificResource.class,
			SpecificFilter.class
		);
	}
}

I know resources don't have a contract to be registered for but if that is a problem, a new method (FeatureContext.registerResource) could be added.

kalgon avatar Mar 10 '20 07:03 kalgon

I currently do not see a need for this. Can you please share a real-world use case?

mkarg avatar Mar 10 '20 21:03 mkarg

I can see some value in the proposal, but I'd like to know more about the problem that this solves. It seems like you could package the classes configured in the AdminFeature into it's own "admin.jar" and then package that JAR file in another WAR file - then use auto-discovery (via @Path and @Provider annotations) for them to be auto-registered.

Thanks for opening the issue.

andymc12 avatar Mar 10 '20 22:03 andymc12