Add support for generic metadata from custom annotation on jax-rs interface
Opened this issue · 1 comments
Lets assume user have JAX-RS resource interface as follow:
public interface UserService {
@Path("/")
@GET
User get();
}
He want to have it secured (JWT for example):
And creates for that custom annotation, f.e.:
Using filters mechanism f.e.
@javax.ws.rs.NameBinding
@Retention(RUNTIME)
@Target({TYPE, METHOD})
public @interface JWTTokenNeeded {
}
https://antoniogoncalves.org/2016/10/03/securing-jax-rs-endpoints-with-jwt/
And adds it to resource:
public interface UserService {
@Path("/")
@GET
@JWTTokenNeeded
User get();
}
This custom annotation information should be passed to generated factory, F.e.:
Using MetaParameter:
setMetaParameter("JWTTokenNeeded", "true");
@Request
public class UserService_get extends ServerRequest<Void, TestOnCompleteHandlers.User> {
UserService_get() {
super(new RequestMeta(TestOnCompleteHandlers.UserService.class, "get", Void.class, TestOnCompleteHandlers.User.class), null);
setHttpMethod("GET");
setAccept(new String[]{"application/json"});
setPath("/");
setServiceRoot("");
setContentType(new String[]{"application/json"});
setMetaParameter("JWTTokenNeeded", "true");
setResponseReader(response -> new AbstractObjectReader<TestOnCompleteHandlers.User>("org.dominokit.rest.processor.TestOnCompleteHandlers.User") {
@Override
protected JsonDeserializer<TestOnCompleteHandlers.User> newDeserializer() {
return new TestOnCompleteHandlers_UserBeanJsonDeserializerImpl();
}
}.read(response.getBodyAsString()));
}
}
}
Then in creating requests or interceptors We cloud see that metadata and act accordingly.
Thanks to that, We would be able to pass ass much metadata to UI wihout any hard dependency.
Examples:
Annotation:
@JWT
Result:
setMetaParameter("JWT", "true");
Annotation:
@JWT(value="val")
Result
setMetaParameter("JWT", "val");
Annotation:
@JWT(value1="val1", value2="val2")
Result
setMetaParameter("JWT", "{value1:val1, value2: val2}");